-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
322 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,40 @@ | ||
pub fn euclidean_3d_elementwise(x1: f64, y1: f64, z1: f64, x2: f64, y2: f64, z2: f64) -> f64 { | ||
(((x2 - x1).powi(2)) + ((y2 - y1).powi(2)) + ((z2 - z1).powi(2))).sqrt() | ||
(((x2 - x1).powi(2)) + ((y2 - y1).powi(2)) + ((z2 - z1).powi(2))).sqrt() | ||
} | ||
|
||
|
||
pub fn euclidean_2d_elementwise(x1: f64, y1: f64, x2: f64, y2: f64) -> f64 { | ||
(((x2 - x1).powi(2)) + ((y2 - y1).powi(2))).sqrt() | ||
(((x2 - x1).powi(2)) + ((y2 - y1).powi(2))).sqrt() | ||
} | ||
|
||
|
||
pub fn cosine_similarity_2d_elementwise(x1: f64, y1: f64, x2: f64, y2: f64) -> f64 { | ||
let dot_product = (x1*x2) + (y1*y2); | ||
let dot_product = (x1 * x2) + (y1 * y2); | ||
let magnitude1 = (x1.powi(2) + y1.powi(2)).powf(0.5); | ||
let magnitude2 = (x2.powi(2) + y2.powi(2)).powf(0.5); | ||
|
||
let res = if magnitude1 == 0.0 || magnitude2 == 0.0 { | ||
0.0 | ||
} else { | ||
dot_product / (magnitude1*magnitude2) | ||
dot_product / (magnitude1 * magnitude2) | ||
}; | ||
res | ||
} | ||
|
||
pub fn cosine_similarity_3d_elementwise(x1: f64, y1: f64, z1: f64, x2: f64, y2: f64, z2: f64) -> f64 { | ||
let dot_product = (x1*x2) + (y1*y2) + (z1*z2); | ||
pub fn cosine_similarity_3d_elementwise( | ||
x1: f64, | ||
y1: f64, | ||
z1: f64, | ||
x2: f64, | ||
y2: f64, | ||
z2: f64, | ||
) -> f64 { | ||
let dot_product = (x1 * x2) + (y1 * y2) + (z1 * z2); | ||
let magnitude1 = (x1.powi(2) + y1.powi(2) + z1.powi(2)).powf(0.5); | ||
let magnitude2 = (x2.powi(2) + y2.powi(2) + z2.powi(2)).powf(0.5); | ||
|
||
let res = if magnitude1 == 0.0 || magnitude2 == 0.0 { | ||
0.0 | ||
} else { | ||
dot_product / (magnitude1*magnitude2) | ||
dot_product / (magnitude1 * magnitude2) | ||
}; | ||
res | ||
} | ||
} |
Oops, something went wrong.