Skip to content

Commit cfb2c6a

Browse files
committed
set min similarity for constant zeros
1 parent b6e32fb commit cfb2c6a

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

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)