Skip to content

Commit

Permalink
use platform-independent count_ones()
Browse files Browse the repository at this point in the history
  • Loading branch information
Kviatkovskii, Mikhail (Ext) committed Jul 5, 2024
1 parent 8ef289b commit a49f06f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/ringo/math/similarity/tanimoto.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::arch::x86_64::_popcnt64;
use bit_vec::BitVec;

pub fn tanimoto_vec(a: &BitVec, b: &BitVec) -> f32 {
Expand All @@ -20,12 +19,12 @@ pub fn tanimoto_vec(a: &BitVec, b: &BitVec) -> f32 {
}

pub unsafe fn tanimoto_array(a: &[u64; 4], b: &[u64; 4]) -> f32 {
let mut dividend: i32 = 0;
let mut divisor: i32 = 0;
let mut dividend: u32 = 0;
let mut divisor: u32 = 0;

for i in 0..4 {
dividend += _popcnt64((a[i] & b[i]) as i64);
divisor += _popcnt64((a[i] | b[i]) as i64);
dividend += ((a[i] & b[i]) as i64).count_ones();
divisor += ((a[i] | b[i]) as i64).count_ones();
}
return dividend as f32 / divisor as f32;
}
Expand Down

0 comments on commit a49f06f

Please sign in to comment.