usearch 2.21.1 → 2.21.3
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/README.md +1 -1
- package/include/usearch/index.hpp +22 -1
- package/package.json +1 -1
- package/prebuilds/darwin-arm64+x64/usearch.node +0 -0
- package/prebuilds/linux-arm64/usearch.node +0 -0
- package/prebuilds/linux-x64/usearch.node +0 -0
- package/simsimd/CONTRIBUTING.md +16 -9
- package/simsimd/Cargo.toml +7 -11
- package/simsimd/MANIFEST.in +1 -0
- package/simsimd/README.md +21 -20
- package/simsimd/build.rs +4 -3
- package/simsimd/c/lib.c +1 -1
- package/simsimd/include/simsimd/binary.h +11 -10
- package/simsimd/include/simsimd/dot.h +4 -4
- package/simsimd/include/simsimd/geospatial.h +1 -1
- package/simsimd/include/simsimd/mesh.h +1 -1
- package/simsimd/include/simsimd/probability.h +14 -14
- package/simsimd/include/simsimd/simsimd.h +86 -6
- package/simsimd/include/simsimd/sparse.h +60 -105
- package/simsimd/include/simsimd/types.h +4 -3
- package/simsimd/javascript/fallback.ts +10 -14
- package/simsimd/javascript/lib.c +1 -1
- package/simsimd/javascript/simsimd.ts +4 -4
- package/simsimd/package.json +1 -1
- package/simsimd/rust/lib.rs +288 -130
- package/simsimd/scripts/bench.cxx +38 -7
- package/simsimd/scripts/bench.rs +876 -0
- package/simsimd/scripts/test.py +1 -1
- package/simsimd/Cargo.lock +0 -713
- package/simsimd/scripts/bench_cosine.rs +0 -41
- package/simsimd/scripts/bench_native.rs +0 -272
- package/simsimd/scripts/bench_sqeuclidean.rs +0 -41
|
@@ -44,11 +44,12 @@ constexpr std::size_t default_seconds = 10;
|
|
|
44
44
|
constexpr std::size_t default_threads = 1;
|
|
45
45
|
constexpr simsimd_distance_t signaling_distance = std::numeric_limits<simsimd_distance_t>::signaling_NaN();
|
|
46
46
|
|
|
47
|
-
/// Matches OpenAI embedding size
|
|
48
47
|
/// For sub-byte data types
|
|
49
|
-
|
|
48
|
+
/// Can be overridden at runtime via `SIMSIMD_BENCH_DENSE_DIMENSIONS` environment variable
|
|
49
|
+
std::size_t dense_dimensions = 1536;
|
|
50
50
|
/// Has quadratic impact on the number of operations
|
|
51
|
-
|
|
51
|
+
/// Can be overridden at runtime via `SIMSIMD_BENCH_CURVED_DIMENSIONS` environment variable
|
|
52
|
+
std::size_t curved_dimensions = 8;
|
|
52
53
|
|
|
53
54
|
namespace bm = benchmark;
|
|
54
55
|
|
|
@@ -680,7 +681,10 @@ void vdot_f64c_blas(simsimd_f64c_t const *a, simsimd_f64c_t const *b, simsimd_si
|
|
|
680
681
|
|
|
681
682
|
void bilinear_f32_blas(simsimd_f32_t const *a, simsimd_f32_t const *b, simsimd_f32_t const *c, simsimd_size_t n,
|
|
682
683
|
simsimd_distance_t *result) {
|
|
683
|
-
|
|
684
|
+
// Thread-local buffer to avoid allocation in hot path
|
|
685
|
+
static thread_local std::vector<simsimd_f32_t> intermediate;
|
|
686
|
+
if (intermediate.size() < n) intermediate.resize(n);
|
|
687
|
+
|
|
684
688
|
simsimd_f32_t alpha = 1.0f, beta = 0.0f;
|
|
685
689
|
cblas_sgemv(CblasRowMajor, CblasNoTrans, (int)n, (int)n, alpha, c, (int)n, b, 1, beta, intermediate.data(), 1);
|
|
686
690
|
*result = cblas_sdot((int)n, a, 1, intermediate.data(), 1);
|
|
@@ -688,7 +692,10 @@ void bilinear_f32_blas(simsimd_f32_t const *a, simsimd_f32_t const *b, simsimd_f
|
|
|
688
692
|
|
|
689
693
|
void bilinear_f64_blas(simsimd_f64_t const *a, simsimd_f64_t const *b, simsimd_f64_t const *c, simsimd_size_t n,
|
|
690
694
|
simsimd_distance_t *result) {
|
|
691
|
-
|
|
695
|
+
// Thread-local buffer to avoid allocation in hot path
|
|
696
|
+
static thread_local std::vector<simsimd_f64_t> intermediate;
|
|
697
|
+
if (intermediate.size() < n) intermediate.resize(n);
|
|
698
|
+
|
|
692
699
|
simsimd_f64_t alpha = 1.0, beta = 0.0;
|
|
693
700
|
cblas_dgemv(CblasRowMajor, CblasNoTrans, (int)n, (int)n, alpha, c, n, b, 1, beta, intermediate.data(), 1);
|
|
694
701
|
*result = cblas_ddot((int)n, a, 1, intermediate.data(), 1);
|
|
@@ -696,7 +703,10 @@ void bilinear_f64_blas(simsimd_f64_t const *a, simsimd_f64_t const *b, simsimd_f
|
|
|
696
703
|
|
|
697
704
|
void bilinear_f32c_blas(simsimd_f32c_t const *a, simsimd_f32c_t const *b, simsimd_f32c_t const *c, simsimd_size_t n,
|
|
698
705
|
simsimd_distance_t *results) {
|
|
699
|
-
|
|
706
|
+
// Thread-local buffer to avoid allocation in hot path
|
|
707
|
+
static thread_local std::vector<simsimd_f32c_t> intermediate;
|
|
708
|
+
if (intermediate.size() < n) intermediate.resize(n);
|
|
709
|
+
|
|
700
710
|
simsimd_f32c_t alpha = {1.0f, 0.0f}, beta = {0.0f, 0.0f};
|
|
701
711
|
cblas_cgemv(CblasRowMajor, CblasNoTrans, (int)n, (int)n, &alpha, c, n, b, 1, &beta, intermediate.data(), 1);
|
|
702
712
|
simsimd_f32_t f32_result[2] = {0, 0};
|
|
@@ -707,7 +717,10 @@ void bilinear_f32c_blas(simsimd_f32c_t const *a, simsimd_f32c_t const *b, simsim
|
|
|
707
717
|
|
|
708
718
|
void bilinear_f64c_blas(simsimd_f64c_t const *a, simsimd_f64c_t const *b, simsimd_f64c_t const *c, simsimd_size_t n,
|
|
709
719
|
simsimd_distance_t *results) {
|
|
710
|
-
|
|
720
|
+
// Thread-local buffer to avoid allocation in hot path
|
|
721
|
+
static thread_local std::vector<simsimd_f64c_t> intermediate;
|
|
722
|
+
if (intermediate.size() < n) intermediate.resize(n);
|
|
723
|
+
|
|
711
724
|
simsimd_f64c_t alpha = {1.0, 0.0}, beta = {0.0, 0.0};
|
|
712
725
|
cblas_zgemv(CblasRowMajor, CblasNoTrans, (int)n, (int)n, &alpha, c, n, b, 1, &beta, intermediate.data(), 1);
|
|
713
726
|
cblas_zdotu_sub((int)n, (simsimd_f64_t const *)a, 1, (simsimd_f64_t const *)intermediate.data(), 1, results);
|
|
@@ -755,6 +768,24 @@ int main(int argc, char **argv) {
|
|
|
755
768
|
std::printf("- x86 Sierra Forest support enabled: %s\n", flags[(runtime_caps & simsimd_cap_sierra_k) != 0]);
|
|
756
769
|
std::printf("\n");
|
|
757
770
|
|
|
771
|
+
// Override dimensions from environment variables if provided
|
|
772
|
+
if (char const *env_dense = std::getenv("SIMSIMD_BENCH_DENSE_DIMENSIONS")) {
|
|
773
|
+
std::size_t parsed_dense = std::atoi(env_dense);
|
|
774
|
+
if (parsed_dense > 0) {
|
|
775
|
+
dense_dimensions = parsed_dense;
|
|
776
|
+
std::printf("Overriding `dense_dimensions` to %zu from SIMSIMD_BENCH_DENSE_DIMENSIONS\n", dense_dimensions);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
if (char const *env_curved = std::getenv("SIMSIMD_BENCH_CURVED_DIMENSIONS")) {
|
|
780
|
+
std::size_t parsed_curved = std::atoi(env_curved);
|
|
781
|
+
if (parsed_curved > 0) {
|
|
782
|
+
curved_dimensions = parsed_curved;
|
|
783
|
+
std::printf("Overriding `curved_dimensions` to %zu from SIMSIMD_BENCH_CURVED_DIMENSIONS\n",
|
|
784
|
+
curved_dimensions);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
std::printf("\n");
|
|
788
|
+
|
|
758
789
|
// Run the benchmarks
|
|
759
790
|
bm::Initialize(&argc, argv);
|
|
760
791
|
if (bm::ReportUnrecognizedArguments(argc, argv)) return 1;
|