usearch 2.9.2 → 2.10.1

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.
Files changed (172) hide show
  1. package/README.md +39 -38
  2. package/javascript/{types → dist/cjs}/usearch.d.ts +90 -115
  3. package/javascript/dist/cjs/usearch.js +531 -0
  4. package/javascript/dist/esm/usearch.d.ts +212 -0
  5. package/javascript/{usearch.js → dist/esm/usearch.js} +199 -153
  6. package/package.json +25 -23
  7. package/prebuilds/darwin-arm64+x64/usearch.node +0 -0
  8. package/prebuilds/linux-arm64/usearch.node +0 -0
  9. package/prebuilds/linux-x64/usearch.node +0 -0
  10. package/prebuilds/win32-ia32/usearch.node +0 -0
  11. package/prebuilds/win32-x64/usearch.node +0 -0
  12. package/.clang-format +0 -10
  13. package/.clang-tidy +0 -60
  14. package/.cmake-format.py +0 -19
  15. package/.dockerignore +0 -93
  16. package/.gitattributes +0 -9
  17. package/.github/ISSUE_TEMPLATE/bug_report.yml +0 -90
  18. package/.github/ISSUE_TEMPLATE/config.yml +0 -5
  19. package/.github/ISSUE_TEMPLATE/feature_request.yml +0 -64
  20. package/.github/workflows/Dockerfile.libs +0 -36
  21. package/.github/workflows/prerelease.yml +0 -331
  22. package/.github/workflows/release.yml +0 -722
  23. package/.github/workflows/update_version.sh +0 -15
  24. package/.gitmodules +0 -9
  25. package/.releaserc +0 -90
  26. package/CITATION.cff +0 -11
  27. package/CMakeLists.txt +0 -324
  28. package/CODE_OF_CONDUCT.md +0 -128
  29. package/CONTRIBUTING.md +0 -361
  30. package/Cargo.toml +0 -19
  31. package/Dockerfile +0 -16
  32. package/VERSION +0 -1
  33. package/assets/unum.png +0 -0
  34. package/assets/usearch-approaches-transparent.png +0 -0
  35. package/assets/usearch-approaches-white.png +0 -0
  36. package/assets/usearch-neighbor-types.png +0 -0
  37. package/binding.gyp +0 -87
  38. package/build.gradle +0 -204
  39. package/build.rs +0 -18
  40. package/c/CMakeLists.txt +0 -25
  41. package/c/README.md +0 -34
  42. package/c/lib.cpp +0 -358
  43. package/c/test.c +0 -382
  44. package/c/usearch.h +0 -311
  45. package/cmake/clipp.cmake +0 -7
  46. package/cmake/config.cmake.in +0 -15
  47. package/cmake/emscripten.cmake +0 -8
  48. package/cmake/jemalloc.cmake +0 -62
  49. package/cmake/pkg-config.pc.in +0 -4
  50. package/cmake/usearchConfigVersion.cmake.in +0 -20
  51. package/conanfile.py +0 -26
  52. package/cpp/CMakeLists.txt +0 -14
  53. package/cpp/README.md +0 -161
  54. package/cpp/bench.cpp +0 -618
  55. package/cpp/test.cpp +0 -323
  56. package/fp16/CMakeLists.txt +0 -176
  57. package/fp16/LICENSE +0 -11
  58. package/fp16/README.md +0 -20
  59. package/fp16/bench/alt-element.cc +0 -89
  60. package/fp16/bench/from-alt-array.cc +0 -175
  61. package/fp16/bench/from-ieee-array.cc +0 -399
  62. package/fp16/bench/ieee-element.cc +0 -272
  63. package/fp16/bench/to-alt-array.cc +0 -91
  64. package/fp16/bench/to-ieee-array.cc +0 -303
  65. package/fp16/cmake/DownloadGoogleBenchmark.cmake +0 -15
  66. package/fp16/cmake/DownloadGoogleTest.cmake +0 -15
  67. package/fp16/cmake/DownloadPSimd.cmake +0 -15
  68. package/fp16/configure.py +0 -65
  69. package/fp16/confu.yaml +0 -8
  70. package/fp16/include/fp16/__init__.py +0 -0
  71. package/fp16/include/fp16/avx.py +0 -50
  72. package/fp16/include/fp16/avx2.py +0 -53
  73. package/fp16/include/fp16/bitcasts.h +0 -92
  74. package/fp16/include/fp16/fp16.h +0 -451
  75. package/fp16/include/fp16/psimd.h +0 -131
  76. package/fp16/include/fp16.h +0 -11
  77. package/fp16/jni/Android.mk +0 -6
  78. package/fp16/jni/Application.mk +0 -4
  79. package/fp16/test/alt-from-fp32-value.cc +0 -498
  80. package/fp16/test/alt-to-fp32-bits.cc +0 -263
  81. package/fp16/test/alt-to-fp32-psimd.cc +0 -145
  82. package/fp16/test/alt-to-fp32-value.cc +0 -348
  83. package/fp16/test/alt-to-fp32x2-psimd.cc +0 -245
  84. package/fp16/test/bitcasts.cc +0 -56
  85. package/fp16/test/ieee-from-fp32-value.cc +0 -523
  86. package/fp16/test/ieee-to-fp32-bits.cc +0 -333
  87. package/fp16/test/ieee-to-fp32-psimd.cc +0 -312
  88. package/fp16/test/ieee-to-fp32-value.cc +0 -420
  89. package/fp16/test/ieee-to-fp32x2-psimd.cc +0 -541
  90. package/fp16/test/peachpy/alt-xmm-to-fp32-xmm-avx.cc +0 -96
  91. package/fp16/test/peachpy/alt-xmm-to-fp32-ymm-avx2.cc +0 -96
  92. package/fp16/test/peachpy/stubs.py +0 -38
  93. package/fp16/test/tables.cc +0 -530
  94. package/fp16/test/tables.h +0 -13
  95. package/fp16/third-party/THHalf.h +0 -92
  96. package/fp16/third-party/eigen-half.h +0 -170
  97. package/fp16/third-party/float16-compressor.h +0 -80
  98. package/fp16/third-party/half.hpp +0 -2916
  99. package/fp16/third-party/npy-halffloat.h +0 -328
  100. package/include/usearch/index.hpp +0 -3836
  101. package/include/usearch/index_dense.hpp +0 -2004
  102. package/include/usearch/index_plugins.hpp +0 -2213
  103. package/javascript/lib.cpp +0 -341
  104. package/javascript/types/usearch.d.ts.map +0 -1
  105. package/javascript/usearch.test.js +0 -74
  106. package/package-ci.json +0 -10
  107. package/pyproject.toml +0 -51
  108. package/setup.py +0 -201
  109. package/simsimd/.releaserc +0 -86
  110. package/simsimd/CONTRIBUTING.md +0 -88
  111. package/simsimd/Cargo.lock +0 -709
  112. package/simsimd/Cargo.toml +0 -44
  113. package/simsimd/LICENSE +0 -201
  114. package/simsimd/README.md +0 -317
  115. package/simsimd/binding.gyp +0 -36
  116. package/simsimd/build.rs +0 -20
  117. package/simsimd/include/simsimd/binary.h +0 -245
  118. package/simsimd/include/simsimd/complex.h +0 -174
  119. package/simsimd/include/simsimd/probability.h +0 -548
  120. package/simsimd/include/simsimd/simsimd.h +0 -465
  121. package/simsimd/include/simsimd/spatial.h +0 -1267
  122. package/simsimd/include/simsimd/types.h +0 -208
  123. package/simsimd/javascript/bench.js +0 -127
  124. package/simsimd/javascript/fallback.ts +0 -193
  125. package/simsimd/javascript/lib.c +0 -102
  126. package/simsimd/javascript/node-gyp-build.d.ts +0 -1
  127. package/simsimd/javascript/simsimd.ts +0 -124
  128. package/simsimd/javascript/test.mjs +0 -153
  129. package/simsimd/javascript/tsconfig-base.json +0 -25
  130. package/simsimd/javascript/tsconfig-cjs.json +0 -8
  131. package/simsimd/javascript/tsconfig-esm.json +0 -8
  132. package/simsimd/package-lock.json +0 -1688
  133. package/simsimd/package.json +0 -61
  134. package/simsimd/rust/benches/cosine.rs +0 -27
  135. package/simsimd/rust/benches/native.rs +0 -30
  136. package/simsimd/rust/benches/sqeuclidean.rs +0 -27
  137. package/simsimd/rust/lib.c +0 -45
  138. package/simsimd/rust/lib.rs +0 -550
  139. package/sqlite/README.md +0 -178
  140. package/sqlite/lib.cpp +0 -325
  141. package/stringzilla/CONTRIBUTING.md +0 -446
  142. package/stringzilla/Cargo.lock +0 -25
  143. package/stringzilla/Cargo.toml +0 -26
  144. package/stringzilla/LICENSE +0 -201
  145. package/stringzilla/README.md +0 -1422
  146. package/stringzilla/VERSION +0 -1
  147. package/stringzilla/assets/cover-strinzilla.jpeg +0 -0
  148. package/stringzilla/assets/meme-stringzilla-v2.jpeg +0 -0
  149. package/stringzilla/assets/meme-stringzilla-v3.jpeg +0 -0
  150. package/stringzilla/binding.gyp +0 -16
  151. package/stringzilla/build.rs +0 -87
  152. package/stringzilla/c/lib.c +0 -337
  153. package/stringzilla/cli/README.md +0 -65
  154. package/stringzilla/cli/__init__.py +0 -0
  155. package/stringzilla/cli/split.py +0 -105
  156. package/stringzilla/cli/wc.py +0 -117
  157. package/stringzilla/include/stringzilla/experimental.h +0 -845
  158. package/stringzilla/include/stringzilla/module.modulemap +0 -9
  159. package/stringzilla/include/stringzilla/stringzilla.h +0 -5370
  160. package/stringzilla/include/stringzilla/stringzilla.hpp +0 -3838
  161. package/stringzilla/javascript/lib.c +0 -125
  162. package/stringzilla/javascript/stringzilla.js +0 -22
  163. package/stringzilla/package-ci.json +0 -10
  164. package/stringzilla/package.json +0 -32
  165. package/stringzilla/rust/lib.rs +0 -873
  166. package/stringzilla/swift/StringProtocol+StringZilla.swift +0 -280
  167. package/stringzilla/swift/Test.swift +0 -60
  168. package/tsconfig.json +0 -21
  169. package/wasmer.toml +0 -12
  170. package/winlibinstaller.bat +0 -42
  171. /package/{simsimd/javascript/dist-package-cjs.json → javascript/dist/cjs/package.json} +0 -0
  172. /package/{simsimd/javascript/dist-package-esm.json → javascript/dist/esm/package.json} +0 -0
@@ -1,44 +0,0 @@
1
- [package]
2
- name = "simsimd"
3
- description = "Fastest SIMD-Accelerated Vector Similarity Functions for x86 and Arm"
4
- version = "3.9.0"
5
- edition = "2021"
6
- license = "Apache-2.0"
7
- authors = [
8
- "Ash Vardanian <1983160+ashvardanian@users.noreply.github.com>",
9
- "Pedro Planel <pplanel@gmail.com>",
10
- ]
11
- repository = "https://github.com/ashvardanian/SimSIMD"
12
- documentation = "https://docs.rs/simsimd"
13
- homepage = "https://ashvardanian.com/posts/simsimd-faster-scipy"
14
- keywords = ["simd", "search", "linear-algebra", "vector"]
15
- categories = [
16
- "mathematics",
17
- "hardware-support",
18
- "no-std",
19
- "wasm",
20
- "external-ffi-bindings",
21
- ]
22
-
23
- [lib]
24
- name = "simsimd"
25
- path = "rust/lib.rs"
26
-
27
- [build-dependencies]
28
- cc = "1.0.83"
29
-
30
-
31
- [[bench]]
32
- name = "cosine"
33
- harness = false
34
- path = "rust/benches/cosine.rs"
35
-
36
- [[bench]]
37
- name = "sqeuclidean"
38
- harness = false
39
- path = "rust/benches/sqeuclidean.rs"
40
-
41
- [dev-dependencies]
42
- criterion = { version = "0.5.1" }
43
- rand = { version = "0.8.5" }
44
- half = { version = "2.4.0" }
package/simsimd/LICENSE DELETED
@@ -1,201 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
package/simsimd/README.md DELETED
@@ -1,317 +0,0 @@
1
- # SimSIMD 📏
2
-
3
- <div>
4
- <a href="https://pepy.tech/project/simsimd">
5
- <img alt="PyPI" src="https://static.pepy.tech/personalized-badge/simsimd?period=total&units=abbreviation&left_color=black&right_color=blue&left_text=SimSIMD%20Python%20installs">
6
- </a>
7
- <a href="https://www.npmjs.com/package/simsimd">
8
- <img alt="npm" src="https://img.shields.io/npm/dy/simsimd?label=npm%20dowloads">
9
- </a>
10
- <a href="https://crates.io/crates/simsimd">
11
- <img alt="rust" src="https://img.shields.io/crates/d/simsimd?logo=rust" />
12
- </a>
13
- <img alt="GitHub code size in bytes" src="https://img.shields.io/github/languages/code-size/ashvardanian/simsimd">
14
- <a href="https://github.com/ashvardanian/SimSIMD/actions/workflows/release.yml">
15
- <img alt="GitHub Actions Ubuntu" src="https://img.shields.io/github/actions/workflow/status/ashvardanian/SimSIMD/release.yml?branch=main&label=Ubuntu&logo=github&color=blue">
16
- </a>
17
- <a href="https://github.com/ashvardanian/SimSIMD/actions/workflows/release.yml">
18
- <img alt="GitHub Actions Windows" src="https://img.shields.io/github/actions/workflow/status/ashvardanian/SimSIMD/release.yml?branch=main&label=Windows&logo=windows&color=blue">
19
- </a>
20
- <a href="https://github.com/ashvardanian/SimSIMD/actions/workflows/release.yml">
21
- <img alt="GitHub Actions MacOS" src="https://img.shields.io/github/actions/workflow/status/ashvardanian/SimSIMD/release.yml?branch=main&label=MacOS&logo=apple&color=blue">
22
- </a>
23
- <a href="https://github.com/ashvardanian/SimSIMD/actions/workflows/release.yml">
24
- <img alt="GitHub Actions CentOS Linux" src="https://img.shields.io/github/actions/workflow/status/ashvardanian/SimSIMD/release.yml?branch=main&label=CentOS&logo=centos&color=blue">
25
- </a>
26
-
27
- </div>
28
-
29
-
30
- ## Hardware-Accelerated Similarity Metrics and Distance Functions
31
-
32
- - Zero-dependency [header-only C 99](#using-simsimd-in-c) library.
33
- - Handles `f64` double-, `f32` single-, and `f16` half-precision, `i8` integral, and binary vectors.
34
- - Targets ARM NEON, SVE, x86 AVX2, AVX-512 (VNNI, FP16) hardware backends.
35
- - Bindings for [Python](#using-simsimd-in-python), [Rust](#using-simsimd-in-rust) and [JavaScript](#using-simsimd-in-javascript).
36
- - __Up to 200x faster__ than [`scipy.spatial.distance`][scipy] and [`numpy.inner`][numpy].
37
- - [Supports more Python versions][compatibility] than SciPy and NumPy.
38
- - Zero-copy compatible with NumPy, PyTorch, TensorFlow, and other tensors.
39
- - Used in [USearch](https://github.com/unum-cloud/usearch) and several DBMS products.
40
-
41
- __Implemented distance functions__ include:
42
-
43
- - Euclidean (L2), Inner Distance, and Cosine (Angular) spatial distances.
44
- - Hamming (~ Manhattan) and Jaccard (~ Tanimoto) binary distances.
45
- - Kullback-Leibler and Jensen–Shannon divergences for probability distributions.
46
-
47
- [scipy]: https://docs.scipy.org/doc/scipy/reference/spatial.distance.html#module-scipy.spatial.distance
48
- [numpy]: https://numpy.org/doc/stable/reference/generated/numpy.inner.html
49
- [compatibility]: https://pypi.org/project/simsimd/#files
50
-
51
- __Technical Insights__ and related articles:
52
-
53
- - [Uses Horner's method for polynomial approximations, beating GCC 12 by 119x](https://ashvardanian.com/posts/gcc-12-vs-avx512fp16/).
54
- - [Uses Arm SVE and x86 AVX-512's masked loads to eliminate tail `for`-loops](https://ashvardanian.com/posts/simsimd-faster-scipy/#tails-of-the-past-the-significance-of-masked-loads).
55
- - [Uses AVX-512 FP16 for half-precision operations, that few compilers vectorize](https://ashvardanian.com/posts/simsimd-faster-scipy/#the-challenge-of-f16).
56
- - [Substitutes LibC's `sqrt` calls with bithacks using Jan Kadlec's constant](https://ashvardanian.com/posts/simsimd-faster-scipy/#bonus-section-bypassing-sqrt-and-libc-dependencies).
57
- - [For Python avoids slow PyBind11, SWIG, and even `PyArg_ParseTuple` for speed](https://ashvardanian.com/posts/pybind11-cpython-tutorial/).
58
- - [For JavaScript uses typed arrays and NAPI for zero-copy calls](https://ashvardanian.com/posts/javascript-ai-vector-search/).
59
-
60
- ## Benchmarks
61
-
62
- ### Apple M2 Pro
63
-
64
- Given 1000 embeddings from OpenAI Ada API with 1536 dimensions, running on the Apple M2 Pro Arm CPU with NEON support, here's how SimSIMD performs against conventional methods:
65
-
66
- | Kind | `f32` improvement | `f16` improvement | `i8` improvement | Conventional method | SimSIMD |
67
- | :------------- | ----------------: | ----------------: | ---------------: | :------------------------------------- | :-------------- |
68
- | Cosine | __32 x__ | __79 x__ | __133 x__ | `scipy.spatial.distance.cosine` | `cosine` |
69
- | Euclidean ² | __5 x__ | __26 x__ | __17 x__ | `scipy.spatial.distance.sqeuclidean` | `sqeuclidean` |
70
- | Inner Distance | __2 x__ | __9 x__ | __18 x__ | `numpy.inner` | `inner` |
71
- | Jensen Shannon | __31 x__ | __53 x__ | | `scipy.spatial.distance.jensenshannon` | `jensenshannon` |
72
-
73
- ### Intel Sapphire Rapids
74
-
75
- On the Intel Sapphire Rapids platform, SimSIMD was benchmarked against auto-vectorized code using GCC 12. GCC handles single-precision `float` but might not be the best choice for `int8` and `_Float16` arrays, which has been part of the C language since 2011.
76
-
77
- | Kind | GCC 12 `f32` | GCC 12 `f16` | SimSIMD `f16` | `f16` improvement |
78
- | :------------- | -----------: | -----------: | ------------: | ----------------: |
79
- | Cosine | 3.28 M/s | _336.29 k/s_ | _6.88 M/s_ | __20 x__ |
80
- | Euclidean ² | 4.62 M/s | _147.25 k/s_ | _5.32 M/s_ | __36 x__ |
81
- | Inner Distance | 3.81 M/s | _192.02 k/s_ | _5.99 M/s_ | __31 x__ |
82
- | Jensen Shannon | 1.18 M/s | _18.13 k/s_ | _2.14 M/s_ | __118 x__ |
83
-
84
- __Broader Benchmarking Results__:
85
-
86
- - [Apple M2 Pro](https://ashvardanian.com/posts/simsimd-faster-scipy/#appendix-1-performance-on-apple-m2-pro).
87
- - [4th Gen Intel Xeon Platinum](https://ashvardanian.com/posts/simsimd-faster-scipy/#appendix-2-performance-on-4th-gen-intel-xeon-platinum-8480).
88
- - [AWS Graviton 3](https://ashvardanian.com/posts/simsimd-faster-scipy/#appendix-3-performance-on-aws-graviton-3).
89
-
90
- ## Using SimSIMD in Python
91
-
92
- The package is intended to replace the usage of `numpy.inner`, `numpy.dot`, and `scipy.spatial.distance`.
93
- Aside from drastic performance improvements, SimSIMD significantly improves accuracy in mixed precision setups.
94
- NumPy and SciPy, processing `i8` or `f16` vectors, will use the same types for accumulators, while SimSIMD can combine `i8` enumeration, `i16` multiplication, and `i32` accumulation to entirely avoid overflows.
95
- The same applies to processing `f16` values with `f32` precision.
96
-
97
- ### Installation
98
-
99
- ```sh
100
- pip install simsimd
101
- ```
102
-
103
- ### Distance Between 2 Vectors
104
-
105
- ```py
106
- import simsimd
107
- import numpy as np
108
-
109
- vec1 = np.random.randn(1536).astype(np.float32)
110
- vec2 = np.random.randn(1536).astype(np.float32)
111
- dist = simsimd.cosine(vec1, vec2)
112
- ```
113
-
114
- Supported functions include `cosine`, `inner`, `sqeuclidean`, `hamming`, and `jaccard`.
115
- Unlike SciPy, SimSIMD allows explicitly stating the precision of the input vectors, which is especially useful for mixed-precision setups.
116
-
117
- ```py
118
- dist = simsimd.cosine(vec1, vec2, "i8")
119
- dist = simsimd.cosine(vec1, vec2, "f16")
120
- dist = simsimd.cosine(vec1, vec2, "f32")
121
- dist = simsimd.cosine(vec1, vec2, "f64")
122
- ```
123
-
124
- ### Distance Between 2 Batches
125
-
126
- ```py
127
- batch1 = np.random.randn(100, 1536).astype(np.float32)
128
- batch2 = np.random.randn(100, 1536).astype(np.float32)
129
- dist = simsimd.cosine(batch1, batch2)
130
- ```
131
-
132
- If either batch has more than one vector, the other batch must have one or the same number of vectors.
133
- If it contains just one, the value is broadcasted.
134
-
135
- ### All Pairwise Distances
136
-
137
- For calculating distances between all possible pairs of rows across two matrices (akin to [`scipy.spatial.distance.cdist`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cdist.html)):
138
-
139
- ```py
140
- matrix1 = np.random.randn(1000, 1536).astype(np.float32)
141
- matrix2 = np.random.randn(10, 1536).astype(np.float32)
142
- distances = simsimd.cdist(matrix1, matrix2, metric="cosine")
143
- ```
144
-
145
- ### Multithreading
146
-
147
- By default, computations use a single CPU core. To optimize and utilize all CPU cores on Linux systems, add the `threads=0` argument. Alternatively, specify a custom number of threads:
148
-
149
- ```py
150
- distances = simsimd.cdist(matrix1, matrix2, metric="cosine", threads=0)
151
- ```
152
-
153
- ### Hardware Backend Capabilities
154
-
155
- To view a list of hardware backends that SimSIMD supports:
156
-
157
- ```py
158
- print(simsimd.get_capabilities())
159
- ```
160
-
161
- ### Using Python API with USearch
162
-
163
- Want to use it in Python with [USearch](https://github.com/unum-cloud/usearch)?
164
- You can wrap the raw C function pointers SimSIMD backends into a `CompiledMetric` and pass it to USearch, similar to how it handles Numba's JIT-compiled code.
165
-
166
- ```py
167
- from usearch.index import Index, CompiledMetric, MetricKind, MetricSignature
168
- from simsimd import pointer_to_sqeuclidean, pointer_to_cosine, pointer_to_inner
169
-
170
- metric = CompiledMetric(
171
- pointer=pointer_to_cosine("f16"),
172
- kind=MetricKind.Cos,
173
- signature=MetricSignature.ArrayArraySize,
174
- )
175
-
176
- index = Index(256, metric=metric)
177
- ```
178
-
179
- ## Using SimSIMD in Rust
180
-
181
- To install, add the following to your `Cargo.toml`:
182
-
183
- ```toml
184
- [dependencies]
185
- simsimd = "..."
186
- ```
187
-
188
- Before using the SimSIMD library, ensure you have imported the necessary traits and types into your Rust source file.
189
- The library provides several traits for different distance/similarity kinds - `SpatialSimilarity`, `BinarySimilarity`, and `ProbabilitySimilarity`.
190
-
191
- ```rust
192
- use simsimd::SpatialSimilarity;
193
-
194
- fn main() {
195
- let vector_a: Vec<f32> = vec![1.0, 2.0, 3.0];
196
- let vector_b: Vec<f32> = vec![4.0, 5.0, 6.0];
197
-
198
- // Compute the cosine similarity between vector_a and vector_b
199
- let cosine_similarity = f32::cosine(&vector_a, &vector_b)
200
- .expect("Vectors must be of the same length");
201
-
202
- println!("Cosine Similarity: {}", cosine_similarity);
203
-
204
- // Compute the squared Euclidean distance between vector_a and vector_b
205
- let sq_euclidean_distance = f32::sqeuclidean(&vector_a, &vector_b)
206
- .expect("Vectors must be of the same length");
207
-
208
- println!("Squared Euclidean Distance: {}", sq_euclidean_distance);
209
- }
210
- ```
211
-
212
- Similarly, one can compute bit-level distance functions between slices of unsigned integers:
213
-
214
- ```rust
215
- use simsimd::BinarySimilarity;
216
-
217
- fn main() {
218
- let vector_a = &[0b11110000, 0b00001111, 0b10101010];
219
- let vector_b = &[0b11110000, 0b00001111, 0b01010101];
220
-
221
- // Compute the Hamming distance between vector_a and vector_b
222
- let hamming_distance = u8::hamming(&vector_a, &vector_b)
223
- .expect("Vectors must be of the same length");
224
-
225
- println!("Hamming Distance: {}", hamming_distance);
226
-
227
- // Compute the Jaccard distance between vector_a and vector_b
228
- let jaccard_distance = u8::jaccard(&vector_a, &vector_b)
229
- .expect("Vectors must be of the same length");
230
-
231
- println!("Jaccard Distance: {}", jaccard_distance);
232
- }
233
- ```
234
-
235
- Rust has no native support for half-precision floating-point numbers, but SimSIMD provides a `f16` type for this purpose.
236
- It doesn't have any functionality and is a `transparent` wrapper around `u16`, so it can be used with `half`, or any other half-precision library.
237
-
238
- ```rust
239
- use simsimd::SpatialSimilarity;
240
- use simsimd::f16 as SimF16;
241
- use half::f16 as HalfF16;
242
-
243
- fn main() {
244
- let vector_a: Vec<HalfF16> = ...
245
- let vector_b: Vec<HalfF16> = ...
246
-
247
- let buffer_a: &[SimF16] = unsafe { std::slice::from_raw_parts(a_half.as_ptr() as *const SimF16, a_half.len()) };
248
- let buffer_b: &[SimF16] = unsafe { std::slice::from_raw_parts(b_half.as_ptr() as *const SimF16, b_half.len()) };
249
-
250
- // Compute the cosine similarity between vector_a and vector_b
251
- let cosine_similarity = SimF16::cosine(&vector_a, &vector_b)
252
- .expect("Vectors must be of the same length");
253
-
254
- println!("Cosine Similarity: {}", cosine_similarity);
255
- }
256
- ```
257
-
258
- ## Using SimSIMD in JavaScript
259
-
260
- To install, choose one of the following options depending on your environment:
261
-
262
- - `npm install --save simsimd`
263
- - `yarn add simsimd`
264
- - `pnpm add simsimd`
265
- - `bun install simsimd`
266
-
267
- The package is distributed with prebuilt binaries for Node.js v10 and above for Linux (x86_64, arm64), macOS (x86_64, arm64), and Windows (i386,x86_64).
268
-
269
- If your platform is not supported, you can build the package from source via `npm run build`. This will automatically happen unless you install the package with `--ignore-scripts` flag or use Bun.
270
-
271
- After you install it, you will be able to call the SimSIMD functions on various `TypedArray` variants:
272
-
273
- ```js
274
- const { sqeuclidean, cosine, inner, hamming, jaccard } = require('simsimd');
275
-
276
- const vectorA = new Float32Array([1.0, 2.0, 3.0]);
277
- const vectorB = new Float32Array([4.0, 5.0, 6.0]);
278
-
279
- const distance = sqeuclidean(vectorA, vectorB);
280
- console.log('Squared Euclidean Distance:', distance);
281
- ```
282
-
283
- ## Using SimSIMD in C
284
-
285
- For integration within a CMake-based project, add the following segment to your `CMakeLists.txt`:
286
-
287
- ```cmake
288
- FetchContent_Declare(
289
- simsimd
290
- GIT_REPOSITORY https://github.com/ashvardanian/simsimd.git
291
- GIT_SHALLOW TRUE
292
- )
293
- FetchContent_MakeAvailable(simsimd)
294
- ```
295
-
296
- If you're aiming to utilize the `_Float16` functionality with SimSIMD, ensure your development environment is compatible with C 11.
297
- For other functionalities of SimSIMD, C 99 compatibility will suffice.
298
- A minimal usage example would be:
299
-
300
- ```c
301
- #include <simsimd/simsimd.h>
302
-
303
- int main() {
304
- simsimd_f32_t vector_a[1536];
305
- simsimd_f32_t vector_b[1536];
306
- simsimd_f32_t distance = simsimd_avx512_f32_cos(vector_a, vector_b, 1536);
307
- return 0;
308
- }
309
- ```
310
-
311
- All of the functions names follow the same pattern: `simsimd_{backend}_{type}_{metric}`.
312
-
313
- - The backend can be `avx512`, `avx2`, `neon`, or `sve`.
314
- - The type can be `f64`, `f32`, `f16`, `i8`, or `b8`.
315
- - The metric can be `cos`, `ip`, `l2sq`, `hamming`, `jaccard`, `kl`, or `js`.
316
-
317
- In case you want to avoid hard-coding the backend, you can use the `simsimd_metric_punned_t` to pun the function pointer, and `simsimd_capabilities` function to get the available backends at runtime.
@@ -1,36 +0,0 @@
1
- {
2
- "variables": {
3
- "openssl_fips": ""
4
- },
5
- "targets": [
6
- {
7
- "target_name": "simsimd",
8
- "sources": ["javascript/lib.c"],
9
- "include_dirs": ["include"],
10
- "defines": ["SIMSIMD_NATIVE_F16=0"],
11
- "cflags": [
12
- "-std=c11",
13
- "-ffast-math",
14
- "-Wno-unknown-pragmas",
15
- "-Wno-maybe-uninitialized",
16
- "-Wno-cast-function-type",
17
- "-Wno-switch",
18
- ],
19
- "conditions": [
20
- ["OS=='mac'", {
21
- "xcode_settings": {
22
- "MACOSX_DEPLOYMENT_TARGET": "11.0",
23
- "OTHER_CFLAGS": [
24
- "-arch arm64",
25
- "-arch x86_64"
26
- ],
27
- "OTHER_LDFLAGS": [
28
- "-arch arm64",
29
- "-arch x86_64"
30
- ]
31
- }
32
- }]
33
- ]
34
- }
35
- ]
36
- }
package/simsimd/build.rs DELETED
@@ -1,20 +0,0 @@
1
- fn main() {
2
- cc::Build::new()
3
- .file("rust/lib.c")
4
- .include("include")
5
- .flag("-O3")
6
- .flag("-DSIMSIMD_NATIVE_F16=0")
7
- .flag("-std=c99") // Enforce C99 standard
8
- .flag("-pedantic") // Ensure strict compliance with the C standard
9
- .warnings(false)
10
- .compile("simsimd");
11
-
12
- println!("cargo:rerun-if-changed=rust/lib.c");
13
- println!("cargo:rerun-if-changed=rust/lib.rs");
14
- println!("cargo:rerun-if-changed=include/simsimd/simsimd.h");
15
-
16
- println!("cargo:rerun-if-changed=include/simsimd/binary.h");
17
- println!("cargo:rerun-if-changed=include/simsimd/probability.h");
18
- println!("cargo:rerun-if-changed=include/simsimd/spatial.h");
19
- println!("cargo:rerun-if-changed=include/simsimd/types.h");
20
- }