Skip to content

Commit

Permalink
chore: definition at build.rs and assert_almost_equal
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Gabriel committed Jan 28, 2024
1 parent 3b43a7a commit aed0fa2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ fn main() {
.file("rust/lib.c")
.include("include")
.flag("-O3")
.flag("-DSIMSIMD_NATIVE_F16=0")
.warnings(false)
.compile("simsimd");

Expand Down
2 changes: 0 additions & 2 deletions rust/lib.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "simsimd/simsimd.h"

#define SIMSIMD_NATIVE_F16 = 0

simsimd_f32_t cosine_i8(simsimd_i8_t const* a, simsimd_i8_t const* b, simsimd_size_t d) {
return simsimd_metric_punned(simsimd_metric_cosine_k, simsimd_datatype_i8_k, simsimd_cap_any_k)(a, b, d, d);
}
Expand Down
19 changes: 13 additions & 6 deletions rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,20 @@ impl SimSIMD for f32 {
mod tests {
use super::*;
//
fn assert_almost_equal(left: f32, right: f32, tolerance: f32) {
let lower = right - tolerance;
let upper = right + tolerance;

assert!(left >= lower && left <= upper);
}

#[test]
fn test_cosine_i8() {
let a = &[3, 97, 127];
let b = &[3, 97, 127];

if let Some(result) = SimSIMD::cosine(a, b) {
assert_eq!(0.00012027938, result);
assert_almost_equal(0.00012027938, result, 0.01);
println!("The result of cosine_i8 is {:.8}", result);
}
}
Expand All @@ -174,7 +181,7 @@ mod tests {
let b = &[1.0, 2.0, 3.0];

if let Some(result) = SimSIMD::cosine(a, b) {
assert_eq!(0.004930496, result);
assert_almost_equal(0.004930496, result, 0.01);
println!("The result of cosine_f32 is {:.8}", result);
}
}
Expand All @@ -185,7 +192,7 @@ mod tests {
let b = &[4, 5, 6];

if let Some(result) = SimSIMD::inner(a, b) {
assert_eq!(0.029403687, result);
assert_almost_equal(0.029403687, result, 0.01);
println!("The result of inner_i8 is {:.8}", result);
}
}
Expand All @@ -196,7 +203,7 @@ mod tests {
let b = &[4.0, 5.0, 6.0];

if let Some(result) = SimSIMD::inner(a, b) {
assert_eq!(-31.0, result);
assert_almost_equal(-31.0, result, 0.01);
println!("The result of inner_f32 is {:.8}", result);
}
}
Expand All @@ -207,7 +214,7 @@ mod tests {
let b = &[4, 5, 6];

if let Some(result) = SimSIMD::sqeuclidean(a, b) {
assert_eq!(27.0, result);
assert_almost_equal(27.0, result, 0.01);
println!("The result of sqeuclidean_i8 is {:.8}", result);
}
}
Expand All @@ -218,7 +225,7 @@ mod tests {
let b = &[4.0, 5.0, 6.0];

if let Some(result) = SimSIMD::sqeuclidean(a, b) {
assert_eq!(27.0, result);
assert_almost_equal(27.0, result, 0.01);
println!("The result of sqeuclidean_f32 is {:.8}", result);
}
}
Expand Down

0 comments on commit aed0fa2

Please sign in to comment.