55 * @date July 1, 2023
66 *
77 * Contains:
8- * - Hamming distance
9- * - Jaccard distance (Tanimoto coefficient)
8+ * - Bit-level Hamming distance
9+ * - Bit-level Jaccard distance (Tanimoto coefficient)
10+ * - TODO: Hamming distance for integer vectors - `u16`, `u32`
1011 *
1112 * For hardware architectures:
1213 * - Arm: NEON, SVE
@@ -55,23 +56,23 @@ extern "C" {
5556
5657// clang-format off
5758
58- /* Serial backends for bitsets. */
59+ /* Serial backends for bitsets and integers . */
5960SIMSIMD_PUBLIC void simsimd_hamming_b8_serial (simsimd_b8_t const * a , simsimd_b8_t const * b , simsimd_size_t n_words , simsimd_distance_t * distance );
6061SIMSIMD_PUBLIC void simsimd_jaccard_b8_serial (simsimd_b8_t const * a , simsimd_b8_t const * b , simsimd_size_t n_words , simsimd_distance_t * distance );
6162
62- /* Arm NEON backend for bitsets. */
63+ /* Arm NEON backend for bitsets and integers . */
6364SIMSIMD_PUBLIC void simsimd_hamming_b8_neon (simsimd_b8_t const * a , simsimd_b8_t const * b , simsimd_size_t n_words , simsimd_distance_t * distance );
6465SIMSIMD_PUBLIC void simsimd_jaccard_b8_neon (simsimd_b8_t const * a , simsimd_b8_t const * b , simsimd_size_t n_words , simsimd_distance_t * distance );
6566
66- /* Arm SVE backend for bitsets. */
67+ /* Arm SVE backend for bitsets and integers . */
6768SIMSIMD_PUBLIC void simsimd_hamming_b8_sve (simsimd_b8_t const * a , simsimd_b8_t const * b , simsimd_size_t n_words , simsimd_distance_t * distance );
6869SIMSIMD_PUBLIC void simsimd_jaccard_b8_sve (simsimd_b8_t const * a , simsimd_b8_t const * b , simsimd_size_t n_words , simsimd_distance_t * distance );
6970
70- /* x86 AVX2 backend for bitsets for Intel Haswell CPUs and newer, needs only POPCNT extensions. */
71+ /* x86 AVX2 backend for bitsets and integers for Intel Haswell CPUs and newer, needs only POPCNT extensions. */
7172SIMSIMD_PUBLIC void simsimd_hamming_b8_haswell (simsimd_b8_t const * a , simsimd_b8_t const * b , simsimd_size_t n_words , simsimd_distance_t * distance );
7273SIMSIMD_PUBLIC void simsimd_jaccard_b8_haswell (simsimd_b8_t const * a , simsimd_b8_t const * b , simsimd_size_t n_words , simsimd_distance_t * distance );
7374
74- /* x86 AVX512 backend for bitsets for Intel Ice Lake CPUs and newer, using VPOPCNTDQ extensions. */
75+ /* x86 AVX512 backend for bitsets and integers for Intel Ice Lake CPUs and newer, using VPOPCNTDQ extensions. */
7576SIMSIMD_PUBLIC void simsimd_hamming_b8_ice (simsimd_b8_t const * a , simsimd_b8_t const * b , simsimd_size_t n_words , simsimd_distance_t * distance );
7677SIMSIMD_PUBLIC void simsimd_jaccard_b8_ice (simsimd_b8_t const * a , simsimd_b8_t const * b , simsimd_size_t n_words , simsimd_distance_t * distance );
7778// clang-format on
@@ -91,14 +92,14 @@ SIMSIMD_PUBLIC unsigned char simsimd_popcount_b8(simsimd_b8_t x) {
9192
9293SIMSIMD_PUBLIC void simsimd_hamming_b8_serial (simsimd_b8_t const * a , simsimd_b8_t const * b , simsimd_size_t n_words ,
9394 simsimd_distance_t * result ) {
94- simsimd_i32_t differences = 0 ;
95+ simsimd_u32_t differences = 0 ;
9596 for (simsimd_size_t i = 0 ; i != n_words ; ++ i ) differences += simsimd_popcount_b8 (a [i ] ^ b [i ]);
9697 * result = differences ;
9798}
9899
99100SIMSIMD_PUBLIC void simsimd_jaccard_b8_serial (simsimd_b8_t const * a , simsimd_b8_t const * b , simsimd_size_t n_words ,
100101 simsimd_distance_t * result ) {
101- simsimd_i32_t intersection = 0 , union_ = 0 ;
102+ simsimd_u32_t intersection = 0 , union_ = 0 ;
102103 for (simsimd_size_t i = 0 ; i != n_words ; ++ i )
103104 intersection += simsimd_popcount_b8 (a [i ] & b [i ]), union_ += simsimd_popcount_b8 (a [i ] | b [i ]);
104105 * result = (union_ != 0 ) ? 1 - (simsimd_f64_t )intersection / (simsimd_f64_t )union_ : 1 ;
0 commit comments