Skip to content

Commit e633afa

Browse files
authored
set min similarity for constant zeros (#331)
* set min similarity for constant zeros * bump version
1 parent b6e32fb commit e633afa

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "smartcore"
33
description = "Machine Learning in Rust."
44
homepage = "https://smartcorelib.org"
5-
version = "0.4.3"
5+
version = "0.4.4"
66
authors = ["smartcore Developers"]
77
edition = "2021"
88
license = "Apache-2.0"

src/metrics/distance/cosine.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<T: Number> Cosine<T> {
9292
let magnitude_y = Self::magnitude(y);
9393

9494
if magnitude_x == 0.0 || magnitude_y == 0.0 {
95-
panic!("Cannot compute cosine distance for zero-magnitude vectors.");
95+
return f64::MIN;
9696
}
9797

9898
dot_product / (magnitude_x * magnitude_y)
@@ -188,12 +188,12 @@ mod tests {
188188
wasm_bindgen_test::wasm_bindgen_test
189189
)]
190190
#[test]
191-
#[should_panic(expected = "Cannot compute cosine distance for zero-magnitude vectors.")]
192191
fn cosine_distance_zero_vector() {
193192
let a = vec![0, 0, 0];
194193
let b = vec![1, 2, 3];
195194

196-
let _dist: f64 = Cosine::new().distance(&a, &b);
195+
let dist: f64 = Cosine::new().distance(&a, &b);
196+
assert!(dist > 1e300)
197197
}
198198

199199
#[cfg_attr(

0 commit comments

Comments
 (0)