usearch 0.18.3 → 0.18.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "usearch"
3
- version = "0.18.3"
3
+ version = "0.18.4"
4
4
  authors = ["Ashot Vardanian <1983160+ashvardanian@users.noreply.github.com>"]
5
5
  description = "Smaller & Faster Single-File Vector Search Engine from Unum"
6
6
  edition = "2021"
package/conanfile.py CHANGED
@@ -4,7 +4,7 @@ from conans import ConanFile
4
4
  class USearchConan(ConanFile):
5
5
 
6
6
  name = 'USearch'
7
- version = '0.18.3'
7
+ version = '0.18.4'
8
8
  license = 'Apache 2.0'
9
9
  url = 'https://github.com/unum-cloud/usearch'
10
10
  description = 'Smaller & Faster Single-File Vector Search Engine from Unum'
@@ -269,7 +269,7 @@ template <typename scalar_at = float, typename result_at = scalar_at> struct cos
269
269
  ab += result_t(a[i]) * result_t(b[i]), //
270
270
  a2 += square<result_t>(a[i]), //
271
271
  b2 += square<result_t>(b[i]);
272
- return ab ? (1 - ab / (std::sqrt(a2) * std::sqrt(b2))) : 0;
272
+ return (ab != 0) ? (1 - ab / (std::sqrt(a2) * std::sqrt(b2))) : 0;
273
273
  }
274
274
  };
275
275
 
@@ -36,7 +36,7 @@ struct cos_f8_t {
36
36
  a2 += square(ai);
37
37
  b2 += square(bi);
38
38
  }
39
- return 1.f - ab / (std::sqrt(a2) * std::sqrt(b2));
39
+ return (ab != 0) ? (1.f - ab / (std::sqrt(a2) * std::sqrt(b2))) : 0;
40
40
  }
41
41
  };
42
42
 
@@ -505,30 +505,27 @@ class index_punned_dense_gt {
505
505
  static metric_and_meta_t ip_metric_f32_(std::size_t dimensions) {
506
506
  (void)dimensions;
507
507
  #if USEARCH_USE_SIMSIMD
508
- #if defined(USEARCH_DEFINED_X86)
509
- if (dimensions % 4 == 0)
508
+ if (hardware_supports(isa_t::avx2_k) && dimensions % 4 == 0)
510
509
  return {
511
510
  pun_metric_<simsimd_f32_t>([=](simsimd_f32_t const* a, simsimd_f32_t const* b) {
512
511
  return 1.f - simsimd_dot_f32x4avx2(a, b, dimensions);
513
512
  }),
514
513
  isa_t::avx2_k,
515
514
  };
516
- #elif defined(USEARCH_DEFINED_ARM)
517
- if (supports_arm_sve())
515
+ if (hardware_supports(isa_t::sve_k))
518
516
  return {
519
517
  pun_metric_<simsimd_f32_t>([=](simsimd_f32_t const* a, simsimd_f32_t const* b) {
520
518
  return 1.f - simsimd_dot_f32sve(a, b, dimensions);
521
519
  }),
522
520
  isa_t::sve_k,
523
521
  };
524
- if (dimensions % 4 == 0)
522
+ if (hardware_supports(isa_t::neon_k) && dimensions % 4 == 0)
525
523
  return {
526
524
  pun_metric_<simsimd_f32_t>([=](simsimd_f32_t const* a, simsimd_f32_t const* b) {
527
525
  return 1.f - simsimd_dot_f32x4neon(a, b, dimensions);
528
526
  }),
529
527
  isa_t::neon_k,
530
528
  };
531
- #endif
532
529
  #endif
533
530
  return pun_metric_<f32_t>(ip_gt<f32_t>{});
534
531
  }
@@ -536,23 +533,20 @@ class index_punned_dense_gt {
536
533
  static metric_and_meta_t cos_metric_f16_(std::size_t dimensions) {
537
534
  (void)dimensions;
538
535
  #if USEARCH_USE_SIMSIMD
539
- #if defined(USEARCH_DEFINED_X86)
540
- if (dimensions % 16 == 0)
536
+ if (hardware_supports(isa_t::avx512_k) && dimensions % 16 == 0)
541
537
  return {
542
538
  pun_metric_<simsimd_f16_t>([=](simsimd_f16_t const* a, simsimd_f16_t const* b) {
543
539
  return 1.f - simsimd_cos_f16x16avx512(a, b, dimensions);
544
540
  }),
545
541
  isa_t::avx512_k,
546
542
  };
547
- #elif defined(USEARCH_DEFINED_ARM)
548
- if (dimensions % 4 == 0)
543
+ if (hardware_supports(isa_t::neon_k) && dimensions % 4 == 0)
549
544
  return {
550
545
  pun_metric_<simsimd_f16_t>([=](simsimd_f16_t const* a, simsimd_f16_t const* b) {
551
546
  return 1.f - simsimd_cos_f16x4neon(a, b, dimensions);
552
547
  }),
553
548
  isa_t::neon_k,
554
549
  };
555
- #endif
556
550
  #endif
557
551
  return pun_metric_<f16_t>(cos_gt<f16_t, f32_t>{});
558
552
  }
@@ -560,14 +554,12 @@ class index_punned_dense_gt {
560
554
  static metric_and_meta_t cos_metric_f8_(std::size_t dimensions) {
561
555
  (void)dimensions;
562
556
  #if USEARCH_USE_SIMSIMD
563
- #if defined(USEARCH_DEFINED_ARM)
564
- if (dimensions % 16 == 0)
557
+ if (hardware_supports(isa_t::neon_k) && dimensions % 16 == 0)
565
558
  return {
566
559
  pun_metric_<int8_t>(
567
560
  [=](int8_t const* a, int8_t const* b) { return 1.f - simsimd_cos_i8x16neon(a, b, dimensions); }),
568
561
  isa_t::neon_k,
569
562
  };
570
- #endif
571
563
  #endif
572
564
  return pun_metric_<f8_bits_t>(cos_f8_t{dimensions});
573
565
  }
@@ -76,13 +76,23 @@ inline char const* isa_name(isa_t isa) noexcept {
76
76
  }
77
77
  }
78
78
 
79
- inline bool supports_arm_sve() noexcept {
80
- #if defined(USEARCH_DEFINED_ARM)
81
- #if defined(USEARCH_DEFINED_LINUX)
79
+ inline bool hardware_supports(isa_t isa) noexcept {
80
+ #if defined(USEARCH_DEFINED_ARM) && defined(USEARCH_DEFINED_LINUX)
82
81
  unsigned long capabilities = getauxval(AT_HWCAP);
83
- if (capabilities & HWCAP_SVE)
84
- return true;
82
+ switch (isa) {
83
+ case isa_t::neon_k: return capabilities & HWCAP_NEON;
84
+ case isa_t::sve_k: return capabilities & HWCAP_SVE;
85
+ default: return false;
86
+ }
85
87
  #endif
88
+
89
+ #if defined(USEARCH_DEFINED_X86) && defined(USEARCH_DEFINED_GCC)
90
+ __builtin_cpu_init();
91
+ switch (isa) {
92
+ case isa_t::avx2_k: return __builtin_cpu_supports("avx2");
93
+ case isa_t::avx512_k: return __builtin_cpu_supports("avx512f");
94
+ default: return false;
95
+ }
86
96
  #endif
87
97
  return false;
88
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "usearch",
3
- "version": "0.18.3",
3
+ "version": "0.18.4",
4
4
  "description": "Smaller & Faster Single-File Vector Search Engine from Unum",
5
5
  "author": "Ashot Vardanian",
6
6
  "license": "Apache 2.0",
package/python/lib.cpp CHANGED
@@ -13,6 +13,7 @@
13
13
  * @copyright Copyright (c) 2023
14
14
  */
15
15
  #define PY_SSIZE_T_CLEAN
16
+ #define NOMINMAX // Some of our dependencies call `std::max(x, y)`, which crashes Windows builds
16
17
  #include <thread>
17
18
 
18
19
  #include <pybind11/numpy.h>
package/setup.py CHANGED
@@ -9,7 +9,7 @@ compile_args = ['-std=c++11', '-O3']
9
9
  link_args = []
10
10
  macros_args = [
11
11
  ('USEARCH_USE_NATIVE_F16', '0'),
12
- ('USEARCH_USE_SIMSIMD', '1'),
12
+ ('USEARCH_USE_SIMSIMD', '0'),
13
13
  ]
14
14
 
15
15
  if sys.platform == 'linux':