We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b6e32fb commit cfb2c6aCopy full SHA for cfb2c6a
1 file changed
src/metrics/distance/cosine.rs
@@ -92,7 +92,7 @@ impl<T: Number> Cosine<T> {
92
let magnitude_y = Self::magnitude(y);
93
94
if magnitude_x == 0.0 || magnitude_y == 0.0 {
95
- panic!("Cannot compute cosine distance for zero-magnitude vectors.");
+ return f64::MIN;
96
}
97
98
dot_product / (magnitude_x * magnitude_y)
@@ -188,12 +188,12 @@ mod tests {
188
wasm_bindgen_test::wasm_bindgen_test
189
)]
190
#[test]
191
- #[should_panic(expected = "Cannot compute cosine distance for zero-magnitude vectors.")]
192
fn cosine_distance_zero_vector() {
193
let a = vec![0, 0, 0];
194
let b = vec![1, 2, 3];
195
196
- let _dist: f64 = Cosine::new().distance(&a, &b);
+ let dist: f64 = Cosine::new().distance(&a, &b);
+ assert!(dist > 1e300)
197
198
199
#[cfg_attr(
0 commit comments