Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "smartcore"
description = "Machine Learning in Rust."
homepage = "https://smartcorelib.org"
version = "0.4.3"
version = "0.4.4"
authors = ["smartcore Developers"]
edition = "2021"
license = "Apache-2.0"
Expand Down
6 changes: 3 additions & 3 deletions src/metrics/distance/cosine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<T: Number> Cosine<T> {
let magnitude_y = Self::magnitude(y);

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

dot_product / (magnitude_x * magnitude_y)
Expand Down Expand Up @@ -188,12 +188,12 @@ mod tests {
wasm_bindgen_test::wasm_bindgen_test
)]
#[test]
#[should_panic(expected = "Cannot compute cosine distance for zero-magnitude vectors.")]
fn cosine_distance_zero_vector() {
let a = vec![0, 0, 0];
let b = vec![1, 2, 3];

let _dist: f64 = Cosine::new().distance(&a, &b);
let dist: f64 = Cosine::new().distance(&a, &b);
assert!(dist > 1e300)
}

#[cfg_attr(
Expand Down
Loading