-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from ava57r/main-utils
add module utils
- Loading branch information
Showing
2 changed files
with
24 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// L2-renormalize a set of vector. Nothing done if the vector is 0-normed | ||
pub fn fvec_renorm_l2(d: usize, nx: usize, fvec: &mut [f32]) { | ||
unsafe { faiss_sys::faiss_fvec_renorm_L2(d, nx, fvec.as_mut_ptr()) } | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use super::*; | ||
|
||
const D: u32 = 8; | ||
|
||
#[test] | ||
fn check_fvec_renorm_l2_01() { | ||
let mut some_data = vec![ | ||
7.5_f32, -7.5, 7.5, -7.5, 7.5, 7.5, 7.5, 7.5, -1., 1., 1., 1., 1., 1., 1., -1., 0., 0., | ||
0., 1., 1., 0., 0., -1., 100., 100., 100., 100., -100., 100., 100., 100., 120., 100., | ||
100., 105., -100., 100., 100., 105., | ||
]; | ||
|
||
fvec_renorm_l2(D as usize, 5, &mut some_data); | ||
} | ||
} |