usearch 2.21.3 → 2.25.0

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 (602) hide show
  1. package/README.md +24 -24
  2. package/binding.gyp +15 -37
  3. package/c/CMakeLists.txt +4 -5
  4. package/c/README.md +7 -7
  5. package/c/lib.cpp +32 -14
  6. package/c/test.c +83 -1
  7. package/c/usearch.h +24 -3
  8. package/cpp/CMakeLists.txt +4 -0
  9. package/cpp/README.md +5 -5
  10. package/cpp/bench.cpp +97 -116
  11. package/cpp/test.cpp +117 -20
  12. package/include/usearch/index.hpp +235 -52
  13. package/include/usearch/index_dense.hpp +105 -40
  14. package/include/usearch/index_plugins.hpp +1387 -204
  15. package/javascript/dist/cjs/usearch.d.ts +8 -3
  16. package/javascript/dist/cjs/usearch.js +12 -4
  17. package/javascript/dist/esm/usearch.d.ts +8 -3
  18. package/javascript/dist/esm/usearch.js +12 -4
  19. package/javascript/lib.cpp +17 -0
  20. package/javascript/usearch.ts +14 -6
  21. package/numkong/.clang-tidy +30 -0
  22. package/{simsimd → numkong}/.cmake-format.py +18 -0
  23. package/numkong/.editorconfig +12 -0
  24. package/numkong/.git-blame-ignore-revs +123 -0
  25. package/numkong/.mailmap +15 -0
  26. package/numkong/.spi.yml +11 -0
  27. package/numkong/.swift-format +14 -0
  28. package/numkong/CITATION.cff +81 -0
  29. package/numkong/CONTRIBUTING.md +500 -0
  30. package/numkong/Cargo.toml +54 -0
  31. package/numkong/MANIFEST.in +8 -0
  32. package/numkong/Package.swift +84 -0
  33. package/numkong/README.md +569 -0
  34. package/numkong/bench/README.md +217 -0
  35. package/numkong/bench/bench-browser.html +323 -0
  36. package/numkong/bench/bench.cpp +344 -0
  37. package/numkong/bench/bench.hpp +816 -0
  38. package/numkong/bench/bench.js +148 -0
  39. package/numkong/bench/bench.mjs +616 -0
  40. package/numkong/bench/bench_attention.cpp +113 -0
  41. package/numkong/bench/bench_cast.cpp +264 -0
  42. package/numkong/bench/bench_cross_amx.cpp +62 -0
  43. package/numkong/bench/bench_cross_arm.cpp +245 -0
  44. package/numkong/bench/bench_cross_blas.cpp +309 -0
  45. package/numkong/bench/bench_cross_loongarch.cpp +106 -0
  46. package/numkong/bench/bench_cross_power.cpp +84 -0
  47. package/numkong/bench/bench_cross_rvv.cpp +121 -0
  48. package/numkong/bench/bench_cross_serial.cpp +151 -0
  49. package/numkong/bench/bench_cross_sme.cpp +163 -0
  50. package/numkong/bench/bench_cross_wasm.cpp +142 -0
  51. package/numkong/bench/bench_cross_x86.cpp +455 -0
  52. package/numkong/bench/bench_curved.cpp +210 -0
  53. package/numkong/bench/bench_dot.cpp +315 -0
  54. package/numkong/bench/bench_each.cpp +503 -0
  55. package/numkong/bench/bench_geospatial.cpp +112 -0
  56. package/numkong/bench/bench_maxsim.cpp +154 -0
  57. package/numkong/bench/bench_mesh.cpp +148 -0
  58. package/numkong/bench/bench_probability.cpp +60 -0
  59. package/numkong/bench/bench_reduce.cpp +371 -0
  60. package/numkong/bench/bench_set.cpp +73 -0
  61. package/numkong/bench/bench_sparse.cpp +198 -0
  62. package/numkong/bench/bench_spatial.cpp +347 -0
  63. package/numkong/bench/bench_trigonometry.cpp +137 -0
  64. package/numkong/bench/swift/Bench.swift +506 -0
  65. package/numkong/binding.gyp +169 -0
  66. package/numkong/build.rs +484 -0
  67. package/numkong/c/dispatch.h +512 -0
  68. package/numkong/c/dispatch_bf16.c +447 -0
  69. package/numkong/c/dispatch_bf16c.c +52 -0
  70. package/numkong/c/dispatch_e2m3.c +296 -0
  71. package/numkong/c/dispatch_e3m2.c +284 -0
  72. package/numkong/c/dispatch_e4m3.c +318 -0
  73. package/numkong/c/dispatch_e5m2.c +316 -0
  74. package/numkong/c/dispatch_f16.c +452 -0
  75. package/numkong/c/dispatch_f16c.c +58 -0
  76. package/numkong/c/dispatch_f32.c +434 -0
  77. package/numkong/c/dispatch_f32c.c +99 -0
  78. package/numkong/c/dispatch_f64.c +348 -0
  79. package/numkong/c/dispatch_f64c.c +98 -0
  80. package/numkong/c/dispatch_i16.c +96 -0
  81. package/numkong/c/dispatch_i32.c +89 -0
  82. package/numkong/c/dispatch_i4.c +153 -0
  83. package/numkong/c/dispatch_i64.c +86 -0
  84. package/numkong/c/dispatch_i8.c +348 -0
  85. package/numkong/c/dispatch_other.c +348 -0
  86. package/numkong/c/dispatch_u1.c +193 -0
  87. package/numkong/c/dispatch_u16.c +124 -0
  88. package/numkong/c/dispatch_u32.c +118 -0
  89. package/numkong/c/dispatch_u4.c +153 -0
  90. package/numkong/c/dispatch_u64.c +102 -0
  91. package/numkong/c/dispatch_u8.c +364 -0
  92. package/numkong/c/numkong.c +940 -0
  93. package/numkong/cmake/nk_arm_isa_probes.cmake +61 -0
  94. package/numkong/cmake/nk_isa_probe.cmake +90 -0
  95. package/numkong/cmake/nk_loongarch_isa_probes.cmake +15 -0
  96. package/numkong/cmake/nk_math_lib.cmake +46 -0
  97. package/numkong/cmake/nk_power_isa_probes.cmake +15 -0
  98. package/numkong/cmake/nk_riscv_isa_probes.cmake +19 -0
  99. package/numkong/cmake/nk_x86_isa_probes.cmake +35 -0
  100. package/numkong/cmake/toolchain-aarch64-gnu.cmake +86 -0
  101. package/numkong/cmake/toolchain-android-arm64.cmake +25 -0
  102. package/numkong/cmake/toolchain-android-armv7.cmake +25 -0
  103. package/numkong/cmake/toolchain-loongarch64-gnu.cmake +68 -0
  104. package/numkong/cmake/toolchain-ppc64le-gnu.cmake +74 -0
  105. package/numkong/cmake/toolchain-riscv64-gnu.cmake +107 -0
  106. package/numkong/cmake/toolchain-riscv64-llvm.cmake +114 -0
  107. package/numkong/cmake/toolchain-wasi.cmake +77 -0
  108. package/numkong/cmake/toolchain-wasm.cmake +70 -0
  109. package/numkong/cmake/toolchain-wasm64.cmake +62 -0
  110. package/numkong/cmake/toolchain-x86_64-llvm.cmake +47 -0
  111. package/numkong/include/README.md +643 -0
  112. package/numkong/include/module.modulemap +129 -0
  113. package/numkong/include/numkong/attention/sapphireamx.h +1363 -0
  114. package/numkong/include/numkong/attention/sme.h +2075 -0
  115. package/numkong/include/numkong/attention.h +49 -0
  116. package/numkong/include/numkong/capabilities.h +930 -0
  117. package/numkong/include/numkong/cast/README.md +262 -0
  118. package/numkong/include/numkong/cast/diamond.h +64 -0
  119. package/numkong/include/numkong/cast/haswell.h +823 -0
  120. package/numkong/include/numkong/cast/icelake.h +475 -0
  121. package/numkong/include/numkong/cast/loongsonasx.h +252 -0
  122. package/numkong/include/numkong/cast/neon.h +1174 -0
  123. package/numkong/include/numkong/cast/powervsx.h +449 -0
  124. package/numkong/include/numkong/cast/rvv.h +970 -0
  125. package/numkong/include/numkong/cast/sapphire.h +262 -0
  126. package/numkong/include/numkong/cast/serial.h +2336 -0
  127. package/numkong/include/numkong/cast/skylake.h +915 -0
  128. package/numkong/include/numkong/cast/v128relaxed.h +537 -0
  129. package/numkong/include/numkong/cast.h +254 -0
  130. package/numkong/include/numkong/cast.hpp +44 -0
  131. package/numkong/include/numkong/curved/README.md +223 -0
  132. package/numkong/include/numkong/curved/genoa.h +182 -0
  133. package/numkong/include/numkong/curved/haswell.h +276 -0
  134. package/numkong/include/numkong/curved/neon.h +329 -0
  135. package/numkong/include/numkong/curved/neonbfdot.h +211 -0
  136. package/numkong/include/numkong/curved/rvv.h +305 -0
  137. package/numkong/include/numkong/curved/serial.h +207 -0
  138. package/numkong/include/numkong/curved/skylake.h +457 -0
  139. package/numkong/include/numkong/curved/smef64.h +530 -0
  140. package/numkong/include/numkong/curved.h +513 -0
  141. package/numkong/include/numkong/curved.hpp +144 -0
  142. package/numkong/include/numkong/dot/README.md +442 -0
  143. package/numkong/include/numkong/dot/alder.h +563 -0
  144. package/numkong/include/numkong/dot/diamond.h +158 -0
  145. package/numkong/include/numkong/dot/genoa.h +289 -0
  146. package/numkong/include/numkong/dot/haswell.h +1723 -0
  147. package/numkong/include/numkong/dot/icelake.h +997 -0
  148. package/numkong/include/numkong/dot/loongsonasx.h +671 -0
  149. package/numkong/include/numkong/dot/neon.h +869 -0
  150. package/numkong/include/numkong/dot/neonbfdot.h +243 -0
  151. package/numkong/include/numkong/dot/neonfhm.h +358 -0
  152. package/numkong/include/numkong/dot/neonfp8.h +323 -0
  153. package/numkong/include/numkong/dot/neonsdot.h +622 -0
  154. package/numkong/include/numkong/dot/powervsx.h +752 -0
  155. package/numkong/include/numkong/dot/rvv.h +722 -0
  156. package/numkong/include/numkong/dot/rvvbb.h +72 -0
  157. package/numkong/include/numkong/dot/rvvbf16.h +123 -0
  158. package/numkong/include/numkong/dot/rvvhalf.h +129 -0
  159. package/numkong/include/numkong/dot/sapphire.h +141 -0
  160. package/numkong/include/numkong/dot/serial.h +874 -0
  161. package/numkong/include/numkong/dot/sierra.h +405 -0
  162. package/numkong/include/numkong/dot/skylake.h +1116 -0
  163. package/numkong/include/numkong/dot/sve.h +420 -0
  164. package/numkong/include/numkong/dot/svebfdot.h +75 -0
  165. package/numkong/include/numkong/dot/svehalf.h +168 -0
  166. package/numkong/include/numkong/dot/svesdot.h +90 -0
  167. package/numkong/include/numkong/dot/v128relaxed.h +1293 -0
  168. package/numkong/include/numkong/dot.h +1136 -0
  169. package/numkong/include/numkong/dot.hpp +94 -0
  170. package/numkong/include/numkong/dots/README.md +496 -0
  171. package/numkong/include/numkong/dots/alder.h +117 -0
  172. package/numkong/include/numkong/dots/diamond.h +86 -0
  173. package/numkong/include/numkong/dots/genoa.h +100 -0
  174. package/numkong/include/numkong/dots/graniteamx.h +733 -0
  175. package/numkong/include/numkong/dots/haswell.h +310 -0
  176. package/numkong/include/numkong/dots/icelake.h +180 -0
  177. package/numkong/include/numkong/dots/loongsonasx.h +176 -0
  178. package/numkong/include/numkong/dots/neon.h +123 -0
  179. package/numkong/include/numkong/dots/neonbfdot.h +59 -0
  180. package/numkong/include/numkong/dots/neonfhm.h +96 -0
  181. package/numkong/include/numkong/dots/neonfp8.h +99 -0
  182. package/numkong/include/numkong/dots/neonsdot.h +144 -0
  183. package/numkong/include/numkong/dots/powervsx.h +194 -0
  184. package/numkong/include/numkong/dots/rvv.h +2593 -0
  185. package/numkong/include/numkong/dots/sapphireamx.h +4017 -0
  186. package/numkong/include/numkong/dots/serial.h +2867 -0
  187. package/numkong/include/numkong/dots/sierra.h +100 -0
  188. package/numkong/include/numkong/dots/skylake.h +207 -0
  189. package/numkong/include/numkong/dots/sme.h +5041 -0
  190. package/numkong/include/numkong/dots/smebi32.h +477 -0
  191. package/numkong/include/numkong/dots/smef64.h +1328 -0
  192. package/numkong/include/numkong/dots/smehalf.h +47 -0
  193. package/numkong/include/numkong/dots/v128relaxed.h +317 -0
  194. package/numkong/include/numkong/dots.h +3110 -0
  195. package/numkong/include/numkong/dots.hpp +641 -0
  196. package/numkong/include/numkong/each/README.md +465 -0
  197. package/numkong/include/numkong/each/haswell.h +1658 -0
  198. package/numkong/include/numkong/each/icelake.h +272 -0
  199. package/numkong/include/numkong/each/neon.h +1138 -0
  200. package/numkong/include/numkong/each/neonbfdot.h +211 -0
  201. package/numkong/include/numkong/each/neonhalf.h +318 -0
  202. package/numkong/include/numkong/each/rvv.h +1121 -0
  203. package/numkong/include/numkong/each/sapphire.h +343 -0
  204. package/numkong/include/numkong/each/serial.h +282 -0
  205. package/numkong/include/numkong/each/skylake.h +1562 -0
  206. package/numkong/include/numkong/each/v128relaxed.h +562 -0
  207. package/numkong/include/numkong/each.h +2232 -0
  208. package/numkong/include/numkong/each.hpp +434 -0
  209. package/numkong/include/numkong/geospatial/README.md +147 -0
  210. package/numkong/include/numkong/geospatial/haswell.h +633 -0
  211. package/numkong/include/numkong/geospatial/neon.h +615 -0
  212. package/numkong/include/numkong/geospatial/rvv.h +701 -0
  213. package/numkong/include/numkong/geospatial/serial.h +309 -0
  214. package/numkong/include/numkong/geospatial/skylake.h +613 -0
  215. package/numkong/include/numkong/geospatial/v128relaxed.h +652 -0
  216. package/numkong/include/numkong/geospatial.h +453 -0
  217. package/numkong/include/numkong/geospatial.hpp +235 -0
  218. package/numkong/include/numkong/matrix.hpp +336 -0
  219. package/numkong/include/numkong/maxsim/README.md +187 -0
  220. package/numkong/include/numkong/maxsim/alder.h +511 -0
  221. package/numkong/include/numkong/maxsim/genoa.h +115 -0
  222. package/numkong/include/numkong/maxsim/haswell.h +553 -0
  223. package/numkong/include/numkong/maxsim/icelake.h +480 -0
  224. package/numkong/include/numkong/maxsim/neonsdot.h +394 -0
  225. package/numkong/include/numkong/maxsim/sapphireamx.h +877 -0
  226. package/numkong/include/numkong/maxsim/serial.h +490 -0
  227. package/numkong/include/numkong/maxsim/sme.h +993 -0
  228. package/numkong/include/numkong/maxsim/v128relaxed.h +280 -0
  229. package/numkong/include/numkong/maxsim.h +571 -0
  230. package/numkong/include/numkong/maxsim.hpp +133 -0
  231. package/numkong/include/numkong/mesh/README.md +219 -0
  232. package/numkong/include/numkong/mesh/haswell.h +2013 -0
  233. package/numkong/include/numkong/mesh/neon.h +1821 -0
  234. package/numkong/include/numkong/mesh/neonbfdot.h +771 -0
  235. package/numkong/include/numkong/mesh/rvv.h +936 -0
  236. package/numkong/include/numkong/mesh/serial.h +721 -0
  237. package/numkong/include/numkong/mesh/skylake.h +2344 -0
  238. package/numkong/include/numkong/mesh/v128relaxed.h +1081 -0
  239. package/numkong/include/numkong/mesh.h +666 -0
  240. package/numkong/include/numkong/mesh.hpp +701 -0
  241. package/numkong/include/numkong/numkong.h +78 -0
  242. package/numkong/include/numkong/numkong.hpp +58 -0
  243. package/numkong/include/numkong/probability/README.md +177 -0
  244. package/numkong/include/numkong/probability/haswell.h +267 -0
  245. package/numkong/include/numkong/probability/neon.h +255 -0
  246. package/numkong/include/numkong/probability/rvv.h +414 -0
  247. package/numkong/include/numkong/probability/serial.h +181 -0
  248. package/numkong/include/numkong/probability/skylake.h +324 -0
  249. package/numkong/include/numkong/probability.h +380 -0
  250. package/numkong/include/numkong/probability.hpp +120 -0
  251. package/numkong/include/numkong/random.h +50 -0
  252. package/numkong/include/numkong/random.hpp +285 -0
  253. package/numkong/include/numkong/reduce/README.md +552 -0
  254. package/numkong/include/numkong/reduce/alder.h +636 -0
  255. package/numkong/include/numkong/reduce/genoa.h +201 -0
  256. package/numkong/include/numkong/reduce/haswell.h +3785 -0
  257. package/numkong/include/numkong/reduce/icelake.h +549 -0
  258. package/numkong/include/numkong/reduce/neon.h +3980 -0
  259. package/numkong/include/numkong/reduce/neonbfdot.h +142 -0
  260. package/numkong/include/numkong/reduce/neonfhm.h +293 -0
  261. package/numkong/include/numkong/reduce/neonsdot.h +357 -0
  262. package/numkong/include/numkong/reduce/rvv.h +3533 -0
  263. package/numkong/include/numkong/reduce/serial.h +753 -0
  264. package/numkong/include/numkong/reduce/sierra.h +338 -0
  265. package/numkong/include/numkong/reduce/skylake.h +3794 -0
  266. package/numkong/include/numkong/reduce/sve.h +52 -0
  267. package/numkong/include/numkong/reduce/v128relaxed.h +2302 -0
  268. package/numkong/include/numkong/reduce.h +1582 -0
  269. package/numkong/include/numkong/reduce.hpp +778 -0
  270. package/numkong/include/numkong/scalar/README.md +89 -0
  271. package/numkong/include/numkong/scalar/haswell.h +122 -0
  272. package/numkong/include/numkong/scalar/loongsonasx.h +74 -0
  273. package/numkong/include/numkong/scalar/neon.h +122 -0
  274. package/numkong/include/numkong/scalar/neonhalf.h +70 -0
  275. package/numkong/include/numkong/scalar/powervsx.h +96 -0
  276. package/numkong/include/numkong/scalar/rvv.h +211 -0
  277. package/numkong/include/numkong/scalar/sapphire.h +74 -0
  278. package/numkong/include/numkong/scalar/serial.h +332 -0
  279. package/numkong/include/numkong/scalar/v128relaxed.h +56 -0
  280. package/numkong/include/numkong/scalar.h +696 -0
  281. package/numkong/include/numkong/set/README.md +179 -0
  282. package/numkong/include/numkong/set/haswell.h +334 -0
  283. package/numkong/include/numkong/set/icelake.h +485 -0
  284. package/numkong/include/numkong/set/loongsonasx.h +181 -0
  285. package/numkong/include/numkong/set/neon.h +363 -0
  286. package/numkong/include/numkong/set/powervsx.h +326 -0
  287. package/numkong/include/numkong/set/rvv.h +226 -0
  288. package/numkong/include/numkong/set/rvvbb.h +117 -0
  289. package/numkong/include/numkong/set/serial.h +174 -0
  290. package/numkong/include/numkong/set/sve.h +187 -0
  291. package/numkong/include/numkong/set/v128relaxed.h +240 -0
  292. package/numkong/include/numkong/set.h +471 -0
  293. package/numkong/include/numkong/set.hpp +114 -0
  294. package/numkong/include/numkong/sets/README.md +149 -0
  295. package/numkong/include/numkong/sets/haswell.h +63 -0
  296. package/numkong/include/numkong/sets/icelake.h +66 -0
  297. package/numkong/include/numkong/sets/loongsonasx.h +52 -0
  298. package/numkong/include/numkong/sets/neon.h +61 -0
  299. package/numkong/include/numkong/sets/powervsx.h +65 -0
  300. package/numkong/include/numkong/sets/serial.h +43 -0
  301. package/numkong/include/numkong/sets/smebi32.h +1135 -0
  302. package/numkong/include/numkong/sets/v128relaxed.h +58 -0
  303. package/numkong/include/numkong/sets.h +382 -0
  304. package/numkong/include/numkong/sparse/README.md +156 -0
  305. package/numkong/include/numkong/sparse/icelake.h +463 -0
  306. package/numkong/include/numkong/sparse/neon.h +288 -0
  307. package/numkong/include/numkong/sparse/serial.h +117 -0
  308. package/numkong/include/numkong/sparse/sve2.h +504 -0
  309. package/numkong/include/numkong/sparse/turin.h +322 -0
  310. package/numkong/include/numkong/sparse.h +363 -0
  311. package/numkong/include/numkong/sparse.hpp +113 -0
  312. package/numkong/include/numkong/spatial/README.md +439 -0
  313. package/numkong/include/numkong/spatial/alder.h +604 -0
  314. package/numkong/include/numkong/spatial/diamond.h +240 -0
  315. package/numkong/include/numkong/spatial/genoa.h +222 -0
  316. package/numkong/include/numkong/spatial/haswell.h +979 -0
  317. package/numkong/include/numkong/spatial/icelake.h +1067 -0
  318. package/numkong/include/numkong/spatial/loongsonasx.h +483 -0
  319. package/numkong/include/numkong/spatial/neon.h +846 -0
  320. package/numkong/include/numkong/spatial/neonbfdot.h +164 -0
  321. package/numkong/include/numkong/spatial/neonfp8.h +258 -0
  322. package/numkong/include/numkong/spatial/neonsdot.h +429 -0
  323. package/numkong/include/numkong/spatial/powervsx.h +738 -0
  324. package/numkong/include/numkong/spatial/rvv.h +991 -0
  325. package/numkong/include/numkong/spatial/rvvbf16.h +128 -0
  326. package/numkong/include/numkong/spatial/rvvhalf.h +120 -0
  327. package/numkong/include/numkong/spatial/serial.h +347 -0
  328. package/numkong/include/numkong/spatial/sierra.h +516 -0
  329. package/numkong/include/numkong/spatial/skylake.h +605 -0
  330. package/numkong/include/numkong/spatial/sve.h +246 -0
  331. package/numkong/include/numkong/spatial/svebfdot.h +125 -0
  332. package/numkong/include/numkong/spatial/svehalf.h +136 -0
  333. package/numkong/include/numkong/spatial/svesdot.h +143 -0
  334. package/numkong/include/numkong/spatial/v128relaxed.h +969 -0
  335. package/numkong/include/numkong/spatial.h +1681 -0
  336. package/numkong/include/numkong/spatial.hpp +183 -0
  337. package/numkong/include/numkong/spatials/README.md +580 -0
  338. package/numkong/include/numkong/spatials/alder.h +94 -0
  339. package/numkong/include/numkong/spatials/diamond.h +82 -0
  340. package/numkong/include/numkong/spatials/genoa.h +94 -0
  341. package/numkong/include/numkong/spatials/graniteamx.h +173 -0
  342. package/numkong/include/numkong/spatials/haswell.h +219 -0
  343. package/numkong/include/numkong/spatials/icelake.h +113 -0
  344. package/numkong/include/numkong/spatials/loongsonasx.h +153 -0
  345. package/numkong/include/numkong/spatials/neon.h +109 -0
  346. package/numkong/include/numkong/spatials/neonbfdot.h +60 -0
  347. package/numkong/include/numkong/spatials/neonfhm.h +92 -0
  348. package/numkong/include/numkong/spatials/neonfp8.h +111 -0
  349. package/numkong/include/numkong/spatials/neonsdot.h +143 -0
  350. package/numkong/include/numkong/spatials/powervsx.h +153 -0
  351. package/numkong/include/numkong/spatials/rvv.h +1976 -0
  352. package/numkong/include/numkong/spatials/sapphireamx.h +1149 -0
  353. package/numkong/include/numkong/spatials/serial.h +248 -0
  354. package/numkong/include/numkong/spatials/sierra.h +96 -0
  355. package/numkong/include/numkong/spatials/skylake.h +184 -0
  356. package/numkong/include/numkong/spatials/sme.h +1927 -0
  357. package/numkong/include/numkong/spatials/smef64.h +483 -0
  358. package/numkong/include/numkong/spatials/v128relaxed.h +240 -0
  359. package/numkong/include/numkong/spatials.h +3374 -0
  360. package/numkong/include/numkong/spatials.hpp +509 -0
  361. package/numkong/include/numkong/tensor.hpp +1981 -0
  362. package/numkong/include/numkong/trigonometry/README.md +184 -0
  363. package/numkong/include/numkong/trigonometry/haswell.h +653 -0
  364. package/numkong/include/numkong/trigonometry/neon.h +638 -0
  365. package/numkong/include/numkong/trigonometry/rvv.h +700 -0
  366. package/numkong/include/numkong/trigonometry/serial.h +703 -0
  367. package/numkong/include/numkong/trigonometry/skylake.h +725 -0
  368. package/numkong/include/numkong/trigonometry/v128relaxed.h +667 -0
  369. package/numkong/include/numkong/trigonometry.h +467 -0
  370. package/numkong/include/numkong/trigonometry.hpp +166 -0
  371. package/numkong/include/numkong/types.h +1695 -0
  372. package/numkong/include/numkong/types.hpp +6027 -0
  373. package/numkong/include/numkong/vector.hpp +766 -0
  374. package/numkong/javascript/@numkong-darwin-arm64/package.json +26 -0
  375. package/numkong/javascript/@numkong-darwin-x64/package.json +26 -0
  376. package/numkong/javascript/@numkong-linux-arm64/package.json +25 -0
  377. package/numkong/javascript/@numkong-linux-x64/package.json +25 -0
  378. package/numkong/javascript/@numkong-win32-arm64/package.json +25 -0
  379. package/numkong/javascript/@numkong-win32-x64/package.json +25 -0
  380. package/numkong/javascript/README.md +254 -0
  381. package/numkong/javascript/node-gyp-build.d.ts +4 -0
  382. package/numkong/javascript/numkong-browser.ts +40 -0
  383. package/numkong/javascript/numkong-wasm.ts +750 -0
  384. package/numkong/javascript/numkong.c +712 -0
  385. package/numkong/javascript/numkong.ts +613 -0
  386. package/{simsimd → numkong}/javascript/tsconfig-base.json +6 -3
  387. package/numkong/javascript/tsconfig-cjs.json +13 -0
  388. package/{simsimd → numkong}/javascript/tsconfig-esm.json +1 -1
  389. package/numkong/javascript/types.ts +784 -0
  390. package/numkong/numkong.gypi +104 -0
  391. package/numkong/package.json +108 -0
  392. package/numkong/probes/arm_neon.c +8 -0
  393. package/numkong/probes/arm_neon_bfdot.c +9 -0
  394. package/numkong/probes/arm_neon_fhm.c +9 -0
  395. package/numkong/probes/arm_neon_half.c +8 -0
  396. package/numkong/probes/arm_neon_sdot.c +9 -0
  397. package/numkong/probes/arm_neonfp8.c +9 -0
  398. package/numkong/probes/arm_sme.c +16 -0
  399. package/numkong/probes/arm_sme2.c +16 -0
  400. package/numkong/probes/arm_sme2p1.c +16 -0
  401. package/numkong/probes/arm_sme_bf16.c +16 -0
  402. package/numkong/probes/arm_sme_bi32.c +16 -0
  403. package/numkong/probes/arm_sme_f64.c +16 -0
  404. package/numkong/probes/arm_sme_fa64.c +14 -0
  405. package/numkong/probes/arm_sme_half.c +16 -0
  406. package/numkong/probes/arm_sme_lut2.c +15 -0
  407. package/numkong/probes/arm_sve.c +18 -0
  408. package/numkong/probes/arm_sve2.c +20 -0
  409. package/numkong/probes/arm_sve2p1.c +18 -0
  410. package/numkong/probes/arm_sve_bfdot.c +20 -0
  411. package/numkong/probes/arm_sve_half.c +18 -0
  412. package/numkong/probes/arm_sve_sdot.c +21 -0
  413. package/numkong/probes/loongarch_lasx.c +12 -0
  414. package/numkong/probes/power_vsx.c +12 -0
  415. package/numkong/probes/probe.js +127 -0
  416. package/numkong/probes/riscv_rvv.c +14 -0
  417. package/numkong/probes/riscv_rvv_bb.c +15 -0
  418. package/numkong/probes/riscv_rvv_bf16.c +17 -0
  419. package/numkong/probes/riscv_rvv_half.c +14 -0
  420. package/numkong/probes/wasm_v128relaxed.c +11 -0
  421. package/numkong/probes/x86_alder.c +17 -0
  422. package/numkong/probes/x86_diamond.c +17 -0
  423. package/numkong/probes/x86_genoa.c +17 -0
  424. package/numkong/probes/x86_graniteamx.c +19 -0
  425. package/numkong/probes/x86_haswell.c +11 -0
  426. package/numkong/probes/x86_icelake.c +17 -0
  427. package/numkong/probes/x86_sapphire.c +16 -0
  428. package/numkong/probes/x86_sapphireamx.c +18 -0
  429. package/numkong/probes/x86_sierra.c +17 -0
  430. package/numkong/probes/x86_skylake.c +15 -0
  431. package/numkong/probes/x86_turin.c +17 -0
  432. package/numkong/rust/README.md +698 -0
  433. package/numkong/rust/capabilities.rs +96 -0
  434. package/numkong/rust/cast.rs +314 -0
  435. package/numkong/rust/curved.rs +391 -0
  436. package/numkong/rust/each.rs +2721 -0
  437. package/numkong/rust/geospatial.rs +343 -0
  438. package/numkong/rust/matrix.rs +5424 -0
  439. package/numkong/rust/maxsim.rs +540 -0
  440. package/numkong/rust/mesh.rs +837 -0
  441. package/numkong/rust/numkong.rs +409 -0
  442. package/numkong/rust/probability.rs +272 -0
  443. package/numkong/rust/reduce.rs +1249 -0
  444. package/numkong/rust/set.rs +194 -0
  445. package/numkong/rust/sparse.rs +513 -0
  446. package/numkong/rust/spatial.rs +1815 -0
  447. package/numkong/rust/tensor.rs +7565 -0
  448. package/numkong/rust/types.rs +3666 -0
  449. package/numkong/rust/vector.rs +1899 -0
  450. package/numkong/rustfmt.toml +2 -0
  451. package/numkong/swift/Matrix.swift +1388 -0
  452. package/numkong/swift/MaxSim.swift +151 -0
  453. package/numkong/swift/NumKong.swift +283 -0
  454. package/numkong/swift/Numerics.swift +329 -0
  455. package/numkong/swift/README.md +433 -0
  456. package/numkong/swift/Scalar.swift +741 -0
  457. package/numkong/swift/Tensor.swift +209 -0
  458. package/numkong/test/README.md +315 -0
  459. package/numkong/test/playwright.config.ts +16 -0
  460. package/numkong/test/swift/Test.swift +534 -0
  461. package/numkong/test/test-browser-bundle-runner.mjs +36 -0
  462. package/numkong/test/test-browser-bundle.html +188 -0
  463. package/numkong/test/test-browser-runner.mjs +43 -0
  464. package/numkong/test/test-browser.html +305 -0
  465. package/numkong/test/test-dtypes.mjs +453 -0
  466. package/numkong/test/test-wasm.mjs +267 -0
  467. package/numkong/test/test.cpp +442 -0
  468. package/numkong/test/test.hpp +580 -0
  469. package/numkong/test/test.mjs +363 -0
  470. package/numkong/test/test_base.py +1041 -0
  471. package/numkong/test/test_cast.cpp +242 -0
  472. package/numkong/test/test_cross.hpp +551 -0
  473. package/numkong/test/test_cross.py +467 -0
  474. package/numkong/test/test_cross_amx.cpp +50 -0
  475. package/numkong/test/test_cross_arm.cpp +225 -0
  476. package/numkong/test/test_cross_blas.cpp +354 -0
  477. package/numkong/test/test_cross_loongarch.cpp +90 -0
  478. package/numkong/test/test_cross_power.cpp +73 -0
  479. package/numkong/test/test_cross_rvv.cpp +109 -0
  480. package/numkong/test/test_cross_serial.cpp +181 -0
  481. package/numkong/test/test_cross_sme.cpp +148 -0
  482. package/numkong/test/test_cross_wasm.cpp +141 -0
  483. package/numkong/test/test_cross_x86.cpp +442 -0
  484. package/numkong/test/test_curved.cpp +182 -0
  485. package/numkong/test/test_curved.py +207 -0
  486. package/numkong/test/test_dot.cpp +353 -0
  487. package/numkong/test/test_dot.py +296 -0
  488. package/numkong/test/test_each.cpp +437 -0
  489. package/numkong/test/test_each.py +756 -0
  490. package/numkong/test/test_geospatial.cpp +155 -0
  491. package/numkong/test/test_geospatial.py +241 -0
  492. package/numkong/test/test_maxsim.cpp +138 -0
  493. package/numkong/test/test_maxsim.py +209 -0
  494. package/numkong/test/test_mesh.cpp +203 -0
  495. package/numkong/test/test_mesh.py +394 -0
  496. package/numkong/test/test_probability.cpp +136 -0
  497. package/numkong/test/test_probability.py +166 -0
  498. package/numkong/test/test_reduce.cpp +563 -0
  499. package/numkong/test/test_reduce.py +781 -0
  500. package/numkong/test/test_set.cpp +151 -0
  501. package/numkong/test/test_set.py +120 -0
  502. package/numkong/test/test_similarities.py +579 -0
  503. package/numkong/test/test_sparse.cpp +121 -0
  504. package/numkong/test/test_sparse.py +118 -0
  505. package/numkong/test/test_spatial.cpp +518 -0
  506. package/numkong/test/test_spatial.py +269 -0
  507. package/numkong/test/test_tensor.cpp +884 -0
  508. package/numkong/test/test_tensor.py +1417 -0
  509. package/numkong/test/test_trigonometry.cpp +156 -0
  510. package/numkong/test/test_trigonometry.py +180 -0
  511. package/package.json +7 -8
  512. package/prebuilds/darwin-arm64+x64/usearch.node +0 -0
  513. package/prebuilds/linux-arm64/usearch.node +0 -0
  514. package/prebuilds/linux-x64/usearch.node +0 -0
  515. package/fp16/CMakeLists.txt +0 -176
  516. package/fp16/LICENSE +0 -11
  517. package/fp16/README.md +0 -20
  518. package/fp16/bench/alt-element.cc +0 -89
  519. package/fp16/bench/from-alt-array.cc +0 -175
  520. package/fp16/bench/from-ieee-array.cc +0 -399
  521. package/fp16/bench/ieee-element.cc +0 -272
  522. package/fp16/bench/to-alt-array.cc +0 -91
  523. package/fp16/bench/to-ieee-array.cc +0 -303
  524. package/fp16/cmake/DownloadGoogleBenchmark.cmake +0 -15
  525. package/fp16/cmake/DownloadGoogleTest.cmake +0 -15
  526. package/fp16/cmake/DownloadPSimd.cmake +0 -15
  527. package/fp16/configure.py +0 -65
  528. package/fp16/confu.yaml +0 -8
  529. package/fp16/include/fp16/__init__.py +0 -0
  530. package/fp16/include/fp16/avx.py +0 -50
  531. package/fp16/include/fp16/avx2.py +0 -53
  532. package/fp16/include/fp16/bitcasts.h +0 -92
  533. package/fp16/include/fp16/fp16.h +0 -451
  534. package/fp16/include/fp16/psimd.h +0 -131
  535. package/fp16/include/fp16.h +0 -11
  536. package/fp16/jni/Android.mk +0 -6
  537. package/fp16/jni/Application.mk +0 -4
  538. package/fp16/test/alt-from-fp32-value.cc +0 -498
  539. package/fp16/test/alt-to-fp32-bits.cc +0 -263
  540. package/fp16/test/alt-to-fp32-psimd.cc +0 -145
  541. package/fp16/test/alt-to-fp32-value.cc +0 -348
  542. package/fp16/test/alt-to-fp32x2-psimd.cc +0 -245
  543. package/fp16/test/bitcasts.cc +0 -56
  544. package/fp16/test/ieee-from-fp32-value.cc +0 -523
  545. package/fp16/test/ieee-to-fp32-bits.cc +0 -333
  546. package/fp16/test/ieee-to-fp32-psimd.cc +0 -312
  547. package/fp16/test/ieee-to-fp32-value.cc +0 -420
  548. package/fp16/test/ieee-to-fp32x2-psimd.cc +0 -541
  549. package/fp16/test/peachpy/alt-xmm-to-fp32-xmm-avx.cc +0 -96
  550. package/fp16/test/peachpy/alt-xmm-to-fp32-ymm-avx2.cc +0 -96
  551. package/fp16/test/peachpy/stubs.py +0 -38
  552. package/fp16/test/tables.cc +0 -530
  553. package/fp16/test/tables.h +0 -13
  554. package/fp16/third-party/THHalf.h +0 -92
  555. package/fp16/third-party/eigen-half.h +0 -170
  556. package/fp16/third-party/float16-compressor.h +0 -80
  557. package/fp16/third-party/half.hpp +0 -2916
  558. package/fp16/third-party/npy-halffloat.h +0 -328
  559. package/simsimd/.git-blame-ignore-revs +0 -2
  560. package/simsimd/CONTRIBUTING.md +0 -321
  561. package/simsimd/Cargo.toml +0 -49
  562. package/simsimd/MANIFEST.in +0 -4
  563. package/simsimd/Package.swift +0 -28
  564. package/simsimd/README.md +0 -1493
  565. package/simsimd/binding.gyp +0 -35
  566. package/simsimd/build.rs +0 -70
  567. package/simsimd/c/lib.c +0 -374
  568. package/simsimd/include/module.modulemap +0 -4
  569. package/simsimd/include/simsimd/binary.h +0 -486
  570. package/simsimd/include/simsimd/curved.h +0 -1541
  571. package/simsimd/include/simsimd/dot.h +0 -1853
  572. package/simsimd/include/simsimd/elementwise.h +0 -2465
  573. package/simsimd/include/simsimd/geospatial.h +0 -43
  574. package/simsimd/include/simsimd/mesh.h +0 -69
  575. package/simsimd/include/simsimd/probability.h +0 -606
  576. package/simsimd/include/simsimd/simsimd.h +0 -2567
  577. package/simsimd/include/simsimd/sparse.h +0 -1384
  578. package/simsimd/include/simsimd/spatial.h +0 -2335
  579. package/simsimd/include/simsimd/types.h +0 -666
  580. package/simsimd/javascript/fallback.ts +0 -233
  581. package/simsimd/javascript/lib.c +0 -125
  582. package/simsimd/javascript/node-gyp-build.d.ts +0 -1
  583. package/simsimd/javascript/simsimd.ts +0 -179
  584. package/simsimd/javascript/tsconfig-cjs.json +0 -8
  585. package/simsimd/package-lock.json +0 -1761
  586. package/simsimd/package.json +0 -61
  587. package/simsimd/rust/lib.rs +0 -1821
  588. package/simsimd/scripts/bench.cxx +0 -1170
  589. package/simsimd/scripts/bench.ipynb +0 -187
  590. package/simsimd/scripts/bench.js +0 -127
  591. package/simsimd/scripts/bench.rs +0 -876
  592. package/simsimd/scripts/bench_vectors.py +0 -734
  593. package/simsimd/scripts/bench_vectors_live.py +0 -213
  594. package/simsimd/scripts/test.c +0 -187
  595. package/simsimd/scripts/test.mjs +0 -220
  596. package/simsimd/scripts/test.py +0 -1505
  597. package/simsimd/swift/SimSIMD.swift +0 -149
  598. package/simsimd/swift/Test.swift +0 -128
  599. /package/{simsimd → numkong}/CODE_OF_CONDUCT.md +0 -0
  600. /package/{simsimd → numkong}/LICENSE +0 -0
  601. /package/{simsimd → numkong}/javascript/dist-package-cjs.json +0 -0
  602. /package/{simsimd → numkong}/javascript/dist-package-esm.json +0 -0
@@ -0,0 +1,613 @@
1
+ /**
2
+ * @fileoverview NumKong - Portable mixed-precision BLAS-like vector math library
3
+ *
4
+ * NumKong provides SIMD-accelerated distance metrics and vector operations for
5
+ * x86, ARM, RISC-V, and WASM platforms. The library automatically detects and uses
6
+ * the best available SIMD instruction set at runtime.
7
+ *
8
+ * @module numkong
9
+ * @author Ash Vardanian
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { dot, euclidean, Float16Array } from 'numkong';
14
+ *
15
+ * // Auto-detected types
16
+ * const a = new Float32Array([1, 2, 3]);
17
+ * const b = new Float32Array([4, 5, 6]);
18
+ * dot(a, b); // 32
19
+ * euclidean(a, b); // 5.196...
20
+ *
21
+ * // Custom types with explicit dtype
22
+ * const c = new Float16Array([1, 2, 3]);
23
+ * const d = new Float16Array([4, 5, 6]);
24
+ * dot(c, d, DType.F16); // 32
25
+ * ```
26
+ */
27
+
28
+ import build from "node-gyp-build";
29
+ import { createRequire } from "node:module";
30
+ import * as path from "node:path";
31
+ import { existsSync } from "node:fs";
32
+ import { getFileName, getRoot } from "bindings";
33
+ import { setConversionFunctions, Float16Array, BFloat16Array, E4M3Array, E5M2Array, BinaryArray, TensorBase, VectorBase, VectorView, Vector, MatrixBase, Matrix, PackedMatrix, DType, dtypeToString, outputDtype, KernelFamily } from "./types.js";
34
+
35
+ function loadNativeAddon(): any {
36
+ // Duplicate-libomp guard. We ship our own `libomp.dylib` next to
37
+ // `numkong.node` in each `@numkong/darwin-*` package, but another OpenMP
38
+ // runtime (e.g. one loaded by another native addon) may already be
39
+ // resident. `KMP_DUPLICATE_LIB_OK=TRUE` tells LLVM libomp / Intel
40
+ // libiomp5 to coexist; it must be in `process.env` before the `require()`
41
+ // below triggers the addon's `dlopen`, since libomp's constructor reads
42
+ // the env during dependency resolution and is too late to influence
43
+ // afterwards. Left unguarded because the variable is harmless on
44
+ // platforms / runtimes (GCC libgomp) that don't recognize it, and a user
45
+ // who set it to something else is respected by `??=`. See
46
+ // `python/numkong/__init__.py` for the Python analog.
47
+ process.env.KMP_DUPLICATE_LIB_OK ??= "TRUE";
48
+
49
+ // Tier 1: platform-specific optional dependency (@numkong/<os>-<arch>)
50
+ try {
51
+ const req = createRequire(path.join(getDirName(), "noop.js"));
52
+ return req(`@numkong/${process.platform}-${process.arch}`);
53
+ } catch { }
54
+
55
+ // Tier 2: node-gyp-build fallback (local dev, unsupported platform, build-from-source)
56
+ try {
57
+ return build(getBuildDir(getDirName()));
58
+ } catch { }
59
+
60
+ return null;
61
+ }
62
+
63
+ let compiled: any = loadNativeAddon();
64
+
65
+ if (compiled) {
66
+ setConversionFunctions({
67
+ castF16ToF32: compiled.castF16ToF32,
68
+ castF32ToF16: compiled.castF32ToF16,
69
+ castBF16ToF32: compiled.castBF16ToF32,
70
+ castF32ToBF16: compiled.castF32ToBF16,
71
+ castE4M3ToF32: compiled.castE4M3ToF32,
72
+ castF32ToE4M3: compiled.castF32ToE4M3,
73
+ castE5M2ToF32: compiled.castE5M2ToF32,
74
+ castF32ToE5M2: compiled.castF32ToE5M2,
75
+ cast: compiled.cast,
76
+ });
77
+ } else {
78
+ throw new Error(
79
+ "NumKong native addon not found. Install with `npm install numkong` (which fetches " +
80
+ "the prebuilt binary), or build from source with `npm run install`. " +
81
+ "For WASM, import from 'numkong/wasm' instead."
82
+ );
83
+ }
84
+
85
+ /**
86
+ * CPU capability bit masks in chronological order (by first commercial silicon).
87
+ * Use these with getCapabilities() to check for specific SIMD support.
88
+ */
89
+ export const Capability = {
90
+ SERIAL: 1n << 0n, // Always: Fallback
91
+ NEON: 1n << 1n, // 2013: ARM NEON
92
+ HASWELL: 1n << 2n, // 2013: Intel AVX2
93
+ SKYLAKE: 1n << 3n, // 2017: Intel AVX-512
94
+ NEONHALF: 1n << 4n, // 2017: ARM NEON FP16
95
+ NEONSDOT: 1n << 5n, // 2017: ARM NEON i8 dot
96
+ NEONFHM: 1n << 6n, // 2018: ARM NEON FP16 FML
97
+ ICELAKE: 1n << 7n, // 2019: Intel AVX-512 VNNI
98
+ GENOA: 1n << 8n, // 2020: Intel/AMD AVX-512 BF16
99
+ NEONBFDOT: 1n << 9n, // 2020: ARM NEON BF16
100
+ SVE: 1n << 10n, // 2020: ARM SVE
101
+ SVEHALF: 1n << 11n, // 2020: ARM SVE FP16
102
+ SVESDOT: 1n << 12n, // 2020: ARM SVE i8 dot
103
+ ALDER: 1n << 13n, // 2021: Intel AVX2+VNNI
104
+ SVEBFDOT: 1n << 14n, // 2021: ARM SVE BF16
105
+ SVE2: 1n << 15n, // 2022: ARM SVE2
106
+ V128RELAXED: 1n << 16n, // 2022: WASM Relaxed SIMD
107
+ SAPPHIRE: 1n << 17n, // 2023: Intel AVX-512 FP16
108
+ SAPPHIREAMX: 1n << 18n, // 2023: Intel Sapphire AMX
109
+ RVV: 1n << 19n, // 2023: RISC-V Vector
110
+ RVVHALF: 1n << 20n, // 2023: RISC-V Zvfh
111
+ RVVBF16: 1n << 21n, // 2023: RISC-V Zvfbfwma
112
+ GRANITEAMX: 1n << 22n, // 2024: Intel Granite AMX FP16
113
+ TURIN: 1n << 23n, // 2024: AMD Turin AVX-512 CD
114
+ SME: 1n << 24n, // 2024: ARM SME
115
+ SME2: 1n << 25n, // 2024: ARM SME2
116
+ SMEF64: 1n << 26n, // 2024: ARM SME F64
117
+ SMEFA64: 1n << 27n, // 2024: ARM SME FA64
118
+ SVE2P1: 1n << 28n, // 2025+: ARM SVE2.1
119
+ SME2P1: 1n << 29n, // 2025+: ARM SME2.1
120
+ SMEHALF: 1n << 30n, // 2025+: ARM SME F16F16
121
+ SMEBF16: 1n << 31n, // 2025+: ARM SME B16B16
122
+ SMELUT2: 1n << 32n, // 2025+: ARM SME LUTv2
123
+ RVVBB: 1n << 33n, // 2025+: RISC-V Zvbb
124
+ SIERRA: 1n << 34n, // 2024: Intel AVXVNNIINT8
125
+ SMEBI32: 1n << 35n, // 2025+: ARM SME BI32I32
126
+ LOONGSONASX: 1n << 36n, // LoongArch LASX 256-bit SIMD
127
+ POWERVSX: 1n << 37n, // Power VSX 128-bit SIMD
128
+ DIAMOND: 1n << 38n, // 2025+: Intel AVX10.2
129
+ NEONFP8: 1n << 39n, // ARM NEON FP8
130
+ } as const;
131
+
132
+ export { Float16Array, BFloat16Array, E4M3Array, E5M2Array, BinaryArray, TensorBase, VectorBase, VectorView, Vector, MatrixBase, Matrix, PackedMatrix, outputDtype };
133
+
134
+ /** Convert a single FP16 value (as uint16 bits) to FP32 */
135
+ export const castF16ToF32 = compiled.castF16ToF32;
136
+ /** Convert a single FP32 value to FP16 (returns uint16 bits) */
137
+ export const castF32ToF16 = compiled.castF32ToF16;
138
+ /** Convert a single BF16 value (as uint16 bits) to FP32 */
139
+ export const castBF16ToF32 = compiled.castBF16ToF32;
140
+ /** Convert a single FP32 value to BF16 (returns uint16 bits) */
141
+ export const castF32ToBF16 = compiled.castF32ToBF16;
142
+ /** Convert a single E4M3 value (as uint8 bits) to FP32 */
143
+ export const castE4M3ToF32 = compiled.castE4M3ToF32;
144
+ /** Convert a single FP32 value to E4M3 (returns uint8 bits) */
145
+ export const castF32ToE4M3 = compiled.castF32ToE4M3;
146
+ /** Convert a single E5M2 value (as uint8 bits) to FP32 */
147
+ export const castE5M2ToF32 = compiled.castE5M2ToF32;
148
+ /** Convert a single FP32 value to E5M2 (returns uint8 bits) */
149
+ export const castF32ToE5M2 = compiled.castF32ToE5M2;
150
+ /** Bulk conversion between different numeric types (modifies destination array in-place) */
151
+ export const cast = compiled.cast;
152
+
153
+ export { DType };
154
+
155
+ /**
156
+ * Numeric arrays supported by distance metrics with auto-detected dtype.
157
+ *
158
+ * These standard TypedArrays are auto-detected by the N-API binding.
159
+ */
160
+ export type NumericArray = Float64Array | Float32Array | Int8Array | Uint8Array;
161
+
162
+ /**
163
+ * Extended array types supported by distance metrics with explicit dtype parameter.
164
+ *
165
+ * Includes Uint16Array (backing type for Float16Array and BFloat16Array) in addition
166
+ * to the auto-detected types. Pass a dtype string as the third argument to distance
167
+ * functions when using custom types.
168
+ */
169
+ export type DistanceArray = Float64Array | Float32Array | Int8Array | Uint8Array | Uint16Array;
170
+
171
+ /**
172
+ * Union type for all array types (including custom types for conversions)
173
+ */
174
+ export type NumKongArray =
175
+ | Float64Array
176
+ | Float32Array
177
+ | Float16Array
178
+ | BFloat16Array
179
+ | E4M3Array
180
+ | E5M2Array
181
+ | Int8Array
182
+ | Uint8Array
183
+ | BinaryArray;
184
+
185
+ /**
186
+ * Extract a TypedArray from a TensorBase for the N-API backend.
187
+ *
188
+ * The native backend doesn't benefit from zero-copy TensorBase (Node.js TypedArrays
189
+ * already share process memory), but accepting TensorBase keeps the API uniform.
190
+ */
191
+ function unwrapTensor(input: TensorBase): { arr: DistanceArray; dtype: DType } {
192
+ switch (input.dtype) {
193
+ case DType.F64: return { arr: new Float64Array(input.buffer, input.byteOffset, input.length), dtype: input.dtype };
194
+ case DType.F32: return { arr: new Float32Array(input.buffer, input.byteOffset, input.length), dtype: input.dtype };
195
+ case DType.F16: case DType.BF16: return { arr: new Uint16Array(input.buffer, input.byteOffset, input.length), dtype: input.dtype };
196
+ case DType.I8: return { arr: new Int8Array(input.buffer, input.byteOffset, input.length), dtype: input.dtype };
197
+ case DType.U8: case DType.U1: return { arr: new Uint8Array(input.buffer, input.byteOffset, input.length), dtype: input.dtype };
198
+ default: return { arr: new Uint8Array(input.buffer, input.byteOffset, input.length), dtype: input.dtype };
199
+ }
200
+ }
201
+
202
+ /**
203
+ * Returns the runtime-detected SIMD capabilities as a bitmask.
204
+ *
205
+ * The bitmask includes flags for various SIMD instruction sets like AVX2, AVX-512,
206
+ * ARM NEON, ARM SVE, ARM SME, RISC-V Vector, and WASM SIMD extensions.
207
+ * Use with Capability constants to check for specific instruction sets.
208
+ *
209
+ * @returns {bigint} Bitmask of capability flags (use with Capability constants)
210
+ *
211
+ * @example
212
+ * ```ts
213
+ * import { getCapabilities, Capability } from 'numkong';
214
+ *
215
+ * const caps = getCapabilities();
216
+ * console.log(`Capabilities: 0x${caps.toString(16)}`);
217
+ *
218
+ * // Check for specific SIMD support
219
+ * if (caps & Capability.HASWELL) {
220
+ * console.log('AVX2 available');
221
+ * }
222
+ * ```
223
+ */
224
+ export const getCapabilities = (): bigint => {
225
+ return compiled.getCapabilities();
226
+ };
227
+
228
+ /**
229
+ * Checks if a specific SIMD capability is available at runtime.
230
+ *
231
+ * This is a convenience wrapper around getCapabilities() that tests for a single capability.
232
+ *
233
+ * @param {bigint} cap - Capability flag to check (from Capability constants)
234
+ * @returns {boolean} True if the capability is available, false otherwise
235
+ *
236
+ * @example
237
+ * ```ts
238
+ * import { hasCapability, Capability } from 'numkong';
239
+ *
240
+ * if (hasCapability(Capability.HASWELL)) {
241
+ * console.log('Intel AVX2 (Haswell) available');
242
+ * }
243
+ * if (hasCapability(Capability.NEON)) {
244
+ * console.log('ARM NEON available');
245
+ * }
246
+ * if (hasCapability(Capability.V128RELAXED)) {
247
+ * console.log('WASM Relaxed SIMD available');
248
+ * }
249
+ * ```
250
+ */
251
+ export const hasCapability = (cap: bigint): boolean => {
252
+ return (getCapabilities() & cap) !== 0n;
253
+ };
254
+
255
+ /**
256
+ * Computes the squared Euclidean distance between two vectors.
257
+ * @param a - The first vector.
258
+ * @param b - The second vector (must match the type of a).
259
+ * @param dtype - Optional dtype string for custom types (e.g. 'f16', 'bf16', 'e4m3').
260
+ * @returns {number} The squared Euclidean distance between vectors a and b.
261
+ */
262
+ export function sqeuclidean(a: NumericArray, b: NumericArray): number;
263
+ export function sqeuclidean(a: DistanceArray, b: DistanceArray, dtype: DType): number;
264
+ export function sqeuclidean(a: TensorBase, b: TensorBase): number;
265
+ export function sqeuclidean(a: DistanceArray | TensorBase, b: DistanceArray | TensorBase, dtype?: DType): number {
266
+ if (a instanceof TensorBase) { const u = unwrapTensor(a), v = unwrapTensor(b as TensorBase); return compiled.sqeuclidean(u.arr, v.arr, dtypeToString(u.dtype)); }
267
+ return dtype !== undefined ? compiled.sqeuclidean(a, b, dtypeToString(dtype)) : compiled.sqeuclidean(a, b);
268
+ }
269
+
270
+ /**
271
+ * Computes the Euclidean distance between two vectors.
272
+ * @param a - The first vector.
273
+ * @param b - The second vector (must match the type of a).
274
+ * @param dtype - Optional dtype string for custom types (e.g. 'f16', 'bf16', 'e4m3').
275
+ * @returns {number} The Euclidean distance between vectors a and b.
276
+ */
277
+ export function euclidean(a: NumericArray, b: NumericArray): number;
278
+ export function euclidean(a: DistanceArray, b: DistanceArray, dtype: DType): number;
279
+ export function euclidean(a: TensorBase, b: TensorBase): number;
280
+ export function euclidean(a: DistanceArray | TensorBase, b: DistanceArray | TensorBase, dtype?: DType): number {
281
+ if (a instanceof TensorBase) { const u = unwrapTensor(a), v = unwrapTensor(b as TensorBase); return compiled.euclidean(u.arr, v.arr, dtypeToString(u.dtype)); }
282
+ return dtype !== undefined ? compiled.euclidean(a, b, dtypeToString(dtype)) : compiled.euclidean(a, b);
283
+ }
284
+
285
+ /**
286
+ * Computes the angular distance between two vectors.
287
+ * @param a - The first vector.
288
+ * @param b - The second vector (must match the type of a).
289
+ * @param dtype - Optional dtype string for custom types (e.g. 'f16', 'bf16', 'e4m3').
290
+ * @returns {number} The angular distance between vectors a and b.
291
+ */
292
+ export function angular(a: NumericArray, b: NumericArray): number;
293
+ export function angular(a: DistanceArray, b: DistanceArray, dtype: DType): number;
294
+ export function angular(a: TensorBase, b: TensorBase): number;
295
+ export function angular(a: DistanceArray | TensorBase, b: DistanceArray | TensorBase, dtype?: DType): number {
296
+ if (a instanceof TensorBase) { const u = unwrapTensor(a), v = unwrapTensor(b as TensorBase); return compiled.angular(u.arr, v.arr, dtypeToString(u.dtype)); }
297
+ return dtype !== undefined ? compiled.angular(a, b, dtypeToString(dtype)) : compiled.angular(a, b);
298
+ }
299
+
300
+ /**
301
+ * Computes the inner product of two vectors (same as dot product).
302
+ * @param a - The first vector.
303
+ * @param b - The second vector (must match the type of a).
304
+ * @param dtype - Optional dtype string for custom types (e.g. 'f16', 'bf16', 'e4m3').
305
+ * @returns {number} The inner product of vectors a and b.
306
+ */
307
+ export function inner(a: NumericArray, b: NumericArray): number;
308
+ export function inner(a: DistanceArray, b: DistanceArray, dtype: DType): number;
309
+ export function inner(a: TensorBase, b: TensorBase): number;
310
+ export function inner(a: DistanceArray | TensorBase, b: DistanceArray | TensorBase, dtype?: DType): number {
311
+ if (a instanceof TensorBase) { const u = unwrapTensor(a), v = unwrapTensor(b as TensorBase); return compiled.inner(u.arr, v.arr, dtypeToString(u.dtype)); }
312
+ return dtype !== undefined ? compiled.inner(a, b, dtypeToString(dtype)) : compiled.inner(a, b);
313
+ }
314
+
315
+ /**
316
+ * Computes the dot product of two vectors (same as inner product).
317
+ * @param a - The first vector.
318
+ * @param b - The second vector (must match the type of a).
319
+ * @param dtype - Optional dtype string for custom types (e.g. 'f16', 'bf16', 'e4m3').
320
+ * @returns {number} The dot product of vectors a and b.
321
+ */
322
+ export function dot(a: NumericArray, b: NumericArray): number;
323
+ export function dot(a: DistanceArray, b: DistanceArray, dtype: DType): number;
324
+ export function dot(a: TensorBase, b: TensorBase): number;
325
+ export function dot(a: DistanceArray | TensorBase, b: DistanceArray | TensorBase, dtype?: DType): number {
326
+ if (a instanceof TensorBase) { const u = unwrapTensor(a), v = unwrapTensor(b as TensorBase); return compiled.dot(u.arr, v.arr, dtypeToString(u.dtype)); }
327
+ return dtype !== undefined ? compiled.dot(a, b, dtypeToString(dtype)) : compiled.dot(a, b);
328
+ }
329
+
330
+ /**
331
+ * Computes the bitwise Hamming distance between two vectors.
332
+ *
333
+ * Both vectors are treated as bit-packed (u1 dtype), where each byte contains 8 bits.
334
+ * Use toBinary() to convert numeric arrays to bit-packed format.
335
+ *
336
+ * @param {Uint8Array | BinaryArray} a - The first bit-packed vector.
337
+ * @param {Uint8Array | BinaryArray} b - The second bit-packed vector.
338
+ * @returns {number} The Hamming distance (number of differing bits) between vectors a and b.
339
+ */
340
+ export const hamming = (a: Uint8Array | BinaryArray | TensorBase, b: Uint8Array | BinaryArray | TensorBase): number => {
341
+ if (a instanceof TensorBase) { const u = unwrapTensor(a), v = unwrapTensor(b as TensorBase); return compiled.hamming(u.arr, v.arr); }
342
+ return compiled.hamming(a, b);
343
+ };
344
+
345
+ /**
346
+ * Computes the bitwise Jaccard distance between two vectors.
347
+ *
348
+ * Both vectors are treated as bit-packed (u1 dtype), where each byte contains 8 bits.
349
+ * Use toBinary() to convert numeric arrays to bit-packed format.
350
+ *
351
+ * @param {Uint8Array | BinaryArray} a - The first bit-packed vector.
352
+ * @param {Uint8Array | BinaryArray} b - The second bit-packed vector.
353
+ * @returns {number} The Jaccard distance (1 - Jaccard similarity) between vectors a and b.
354
+ */
355
+ export const jaccard = (a: Uint8Array | BinaryArray | TensorBase, b: Uint8Array | BinaryArray | TensorBase): number => {
356
+ if (a instanceof TensorBase) { const u = unwrapTensor(a), v = unwrapTensor(b as TensorBase); return compiled.jaccard(u.arr, v.arr); }
357
+ return compiled.jaccard(a, b);
358
+ };
359
+
360
+ /**
361
+ * Computes the Kullback-Leibler divergence between two probability distributions.
362
+ *
363
+ * Both vectors must represent valid probability distributions (non-negative, sum to 1).
364
+ * Supports f64, f32 (auto-detected) and f16, bf16 (with explicit dtype).
365
+ *
366
+ * @param a - The first probability distribution.
367
+ * @param b - The second probability distribution (must match the type of a).
368
+ * @param dtype - Optional dtype string for custom types (e.g. 'f16', 'bf16').
369
+ * @returns {number} The Kullback-Leibler divergence KL(a || b) = Σ a[i] * log(a[i] / b[i]).
370
+ */
371
+ export function kullbackleibler(a: Float64Array | Float32Array, b: Float64Array | Float32Array): number;
372
+ export function kullbackleibler(a: Float64Array | Float32Array | Uint16Array, b: Float64Array | Float32Array | Uint16Array, dtype: DType): number;
373
+ export function kullbackleibler(a: TensorBase, b: TensorBase): number;
374
+ export function kullbackleibler(a: Float64Array | Float32Array | Uint16Array | TensorBase, b: Float64Array | Float32Array | Uint16Array | TensorBase, dtype?: DType): number {
375
+ if (a instanceof TensorBase) { const u = unwrapTensor(a), v = unwrapTensor(b as TensorBase); return compiled.kullbackleibler(u.arr, v.arr, dtypeToString(u.dtype)); }
376
+ return dtype !== undefined ? compiled.kullbackleibler(a, b, dtypeToString(dtype)) : compiled.kullbackleibler(a, b);
377
+ }
378
+
379
+ /**
380
+ * Computes the Jensen-Shannon distance between two probability distributions.
381
+ *
382
+ * Both vectors must represent valid probability distributions (non-negative, sum to 1).
383
+ * Supports f64, f32 (auto-detected) and f16, bf16 (with explicit dtype).
384
+ * JSD is the square root of the symmetrized KL divergence, forming a true metric.
385
+ *
386
+ * @param a - The first probability distribution.
387
+ * @param b - The second probability distribution (must match the type of a).
388
+ * @param dtype - Optional dtype string for custom types (e.g. 'f16', 'bf16').
389
+ * @returns {number} The Jensen-Shannon distance d_JS(a, b) = √(0.5 × (KL(a‖m) + KL(b‖m))), where m = (a + b) / 2.
390
+ */
391
+ export function jensenshannon(a: Float64Array | Float32Array, b: Float64Array | Float32Array): number;
392
+ export function jensenshannon(a: Float64Array | Float32Array | Uint16Array, b: Float64Array | Float32Array | Uint16Array, dtype: DType): number;
393
+ export function jensenshannon(a: TensorBase, b: TensorBase): number;
394
+ export function jensenshannon(a: Float64Array | Float32Array | Uint16Array | TensorBase, b: Float64Array | Float32Array | Uint16Array | TensorBase, dtype?: DType): number {
395
+ if (a instanceof TensorBase) { const u = unwrapTensor(a), v = unwrapTensor(b as TensorBase); return compiled.jensenshannon(u.arr, v.arr, dtypeToString(u.dtype)); }
396
+ return dtype !== undefined ? compiled.jensenshannon(a, b, dtypeToString(dtype)) : compiled.jensenshannon(a, b);
397
+ }
398
+
399
+ /**
400
+ * Quantizes a numeric vector into a bit-packed binary representation.
401
+ *
402
+ * Converts each element to a single bit: 1 for positive values, 0 for non-positive values.
403
+ * The bits are packed into bytes (8 bits per byte) in big-endian bit order within each byte.
404
+ * This is the required format for hamming() and jaccard() distance functions.
405
+ *
406
+ * @param {Float32Array | Float64Array | Int8Array} vector - The vector to quantize and pack.
407
+ * @returns {Uint8Array} A bit-packed array where each byte contains 8 binary values.
408
+ *
409
+ * @example
410
+ * ```ts
411
+ * const vec = new Float32Array([1.5, -2.3, 0.0, 3.1, -1.0, 2.0, 0.5, -0.5]);
412
+ * const binary = toBinary(vec);
413
+ * // Result: Uint8Array([0b10010110]) = [0x96]
414
+ * // bits: [1, 0, 0, 1, 0, 1, 1, 0] for elements [+, -, 0, +, -, +, +, -]
415
+ *
416
+ * // Use with Hamming distance
417
+ * const a = toBinary(new Float32Array([1, 2, 3]));
418
+ * const b = toBinary(new Float32Array([1, -2, 3]));
419
+ * const dist = hamming(a, b); // Counts differing bits
420
+ * ```
421
+ */
422
+ export const toBinary = (vector: Float32Array | Float64Array | Int8Array): Uint8Array => {
423
+ const byteLength = Math.ceil(vector.length / 8);
424
+ const packedVector = new Uint8Array(byteLength);
425
+
426
+ for (let i = 0; i < vector.length; i++) {
427
+ if (vector[i] > 0) {
428
+ const byteIndex = Math.floor(i / 8);
429
+ const bitPosition = 7 - (i % 8);
430
+ packedVector[byteIndex] |= (1 << bitPosition);
431
+ }
432
+ }
433
+
434
+ return packedVector;
435
+ };
436
+
437
+ /**
438
+ * Extract a TypedArray from a Matrix for passing to the N-API backend.
439
+ */
440
+ function unwrapMatrix(matrix: Matrix): { array: DistanceArray; dtype: DType } {
441
+ switch (matrix.dtype) {
442
+ case DType.F64: return { array: new Float64Array(matrix.buffer, matrix.byteOffset, matrix.rows * matrix.cols), dtype: matrix.dtype };
443
+ case DType.F32: return { array: new Float32Array(matrix.buffer, matrix.byteOffset, matrix.rows * matrix.cols), dtype: matrix.dtype };
444
+ case DType.F16: case DType.BF16: return { array: new Uint16Array(matrix.buffer, matrix.byteOffset, matrix.rows * matrix.cols), dtype: matrix.dtype };
445
+ case DType.I8: return { array: new Int8Array(matrix.buffer, matrix.byteOffset, matrix.rows * matrix.cols), dtype: matrix.dtype };
446
+ case DType.U8: return { array: new Uint8Array(matrix.buffer, matrix.byteOffset, matrix.rows * matrix.cols), dtype: matrix.dtype };
447
+ default: return { array: new Uint8Array(matrix.buffer, matrix.byteOffset, matrix.rows * matrix.cols), dtype: matrix.dtype };
448
+ }
449
+ }
450
+
451
+ /**
452
+ * Extract a result TypedArray from a Matrix matching its output dtype.
453
+ */
454
+ function unwrapResultMatrix(matrix: Matrix): Float64Array | Float32Array | Int32Array | Uint32Array {
455
+ switch (matrix.dtype) {
456
+ case DType.F64: return new Float64Array(matrix.buffer, matrix.byteOffset, matrix.rows * matrix.cols);
457
+ case DType.F32: return new Float32Array(matrix.buffer, matrix.byteOffset, matrix.rows * matrix.cols);
458
+ case DType.I32: return new Int32Array(matrix.buffer, matrix.byteOffset, matrix.rows * matrix.cols);
459
+ case DType.U32: return new Uint32Array(matrix.buffer, matrix.byteOffset, matrix.rows * matrix.cols);
460
+ default: return new Float64Array(matrix.buffer, matrix.byteOffset, matrix.rows * matrix.cols);
461
+ }
462
+ }
463
+
464
+ /**
465
+ * Query the packed buffer byte count for a given matrix shape and dtype.
466
+ */
467
+ export function dotsPackedSize(width: number, depth: number, dtype: DType): number {
468
+ return compiled.dotsPackedSize(width, depth, dtypeToString(dtype));
469
+ }
470
+
471
+ /**
472
+ * Pack a Matrix for use with packed GEMM-like operations.
473
+ */
474
+ export function dotsPack(matrix: Matrix): PackedMatrix {
475
+ const { array, dtype } = unwrapMatrix(matrix);
476
+ const result = compiled.dotsPack(array, matrix.rows, matrix.cols, matrix.rowStride, dtypeToString(dtype));
477
+ return new PackedMatrix(result.buffer, result.width, result.depth, matrix.dtype, result.byteLength);
478
+ }
479
+
480
+ function packedOperation(compiledName: string, family: KernelFamily, a: Matrix, packed: PackedMatrix, out?: Matrix): Matrix {
481
+ if (a.cols !== packed.depth) {
482
+ throw new Error(`Matrix cols (${a.cols}) must match packed depth (${packed.depth})`);
483
+ }
484
+ const outDtype = outputDtype(family, a.dtype);
485
+ if (!out) {
486
+ out = new Matrix(a.rows, packed.width, outDtype);
487
+ }
488
+ const aUnwrapped = unwrapMatrix(a);
489
+ const resultArray = unwrapResultMatrix(out);
490
+ (compiled as any)[compiledName](
491
+ aUnwrapped.array, packed.buffer, resultArray,
492
+ a.rows, packed.width, a.cols,
493
+ a.rowStride, out.rowStride,
494
+ dtypeToString(a.dtype),
495
+ );
496
+ return out;
497
+ }
498
+
499
+ function symmetricOperation(compiledName: string, family: KernelFamily, vectors: Matrix, out?: Matrix, rowStart = 0, rowCount?: number): Matrix {
500
+ const count = rowCount ?? vectors.rows - rowStart;
501
+ const outDtype = outputDtype(family, vectors.dtype);
502
+ if (!out) {
503
+ out = new Matrix(vectors.rows, vectors.rows, outDtype);
504
+ }
505
+ const vectorsUnwrapped = unwrapMatrix(vectors);
506
+ const resultArray = unwrapResultMatrix(out);
507
+ (compiled as any)[compiledName](
508
+ vectorsUnwrapped.array, resultArray,
509
+ vectors.rows, vectors.cols,
510
+ vectors.rowStride, out.rowStride,
511
+ rowStart, count,
512
+ dtypeToString(vectors.dtype),
513
+ );
514
+ return out;
515
+ }
516
+
517
+ export function dotsPacked(a: Matrix, packed: PackedMatrix, out?: Matrix): Matrix {
518
+ return packedOperation('dotsPacked', 'dots', a, packed, out);
519
+ }
520
+
521
+ export function angularsPacked(a: Matrix, packed: PackedMatrix, out?: Matrix): Matrix {
522
+ return packedOperation('angularsPacked', 'angulars', a, packed, out);
523
+ }
524
+
525
+ export function euclideansPacked(a: Matrix, packed: PackedMatrix, out?: Matrix): Matrix {
526
+ return packedOperation('euclideansPacked', 'euclideans', a, packed, out);
527
+ }
528
+
529
+ export function dotsSymmetric(vectors: Matrix, out?: Matrix, options?: { rowStart?: number; rowCount?: number }): Matrix {
530
+ return symmetricOperation('dotsSymmetric', 'dots', vectors, out, options?.rowStart ?? 0, options?.rowCount);
531
+ }
532
+
533
+ export function angularsSymmetric(vectors: Matrix, out?: Matrix, options?: { rowStart?: number; rowCount?: number }): Matrix {
534
+ return symmetricOperation('angularsSymmetric', 'angulars', vectors, out, options?.rowStart ?? 0, options?.rowCount);
535
+ }
536
+
537
+ export function euclideansSymmetric(vectors: Matrix, out?: Matrix, options?: { rowStart?: number; rowCount?: number }): Matrix {
538
+ return symmetricOperation('euclideansSymmetric', 'euclideans', vectors, out, options?.rowStart ?? 0, options?.rowCount);
539
+ }
540
+
541
+ export default {
542
+ dot,
543
+ inner,
544
+ sqeuclidean,
545
+ euclidean,
546
+ angular,
547
+ hamming,
548
+ jaccard,
549
+ kullbackleibler,
550
+ jensenshannon,
551
+ toBinary,
552
+ Float16Array,
553
+ BFloat16Array,
554
+ E4M3Array,
555
+ E5M2Array,
556
+ BinaryArray,
557
+ TensorBase,
558
+ VectorBase,
559
+ VectorView,
560
+ Vector,
561
+ MatrixBase,
562
+ Matrix,
563
+ PackedMatrix,
564
+ castF16ToF32,
565
+ castF32ToF16,
566
+ castBF16ToF32,
567
+ castF32ToBF16,
568
+ castE4M3ToF32,
569
+ castF32ToE4M3,
570
+ castE5M2ToF32,
571
+ castF32ToE5M2,
572
+ cast,
573
+ dotsPack,
574
+ dotsPacked,
575
+ angularsPacked,
576
+ euclideansPacked,
577
+ dotsSymmetric,
578
+ angularsSymmetric,
579
+ euclideansSymmetric,
580
+ dotsPackedSize,
581
+ outputDtype,
582
+ };
583
+
584
+ /**
585
+ * Finds the directory where the native build of the numkong module is located.
586
+ * @param {string} dir - The directory to start the search from.
587
+ */
588
+ function getBuildDir(dir: string) {
589
+ if (existsSync(path.join(dir, "build"))) return dir;
590
+ if (existsSync(path.join(dir, "prebuilds"))) return dir;
591
+ if (path.basename(dir) === ".next") {
592
+ // special case for next.js on custom node (not vercel)
593
+ const sideways = path.join(dir, "..", "node_modules", "numkong");
594
+ if (existsSync(sideways)) return getBuildDir(sideways);
595
+ }
596
+ if (dir === "/") throw new Error("Could not find native build for numkong");
597
+ return getBuildDir(path.join(dir, ".."));
598
+ }
599
+
600
+ function getDirName() {
601
+ try {
602
+ if (__dirname) return __dirname;
603
+ } catch (e) { }
604
+ // Fall back to cwd, which is typically the project root in dev and CI.
605
+ // This helps runtimes like Deno and Bun where the `bindings` module's
606
+ // V8 stack-trace hack may not resolve correctly.
607
+ try {
608
+ const cwd = process.cwd();
609
+ if (existsSync(path.join(cwd, "build")) || existsSync(path.join(cwd, "prebuilds")))
610
+ return cwd;
611
+ } catch (e) { }
612
+ return getRoot(getFileName());
613
+ }
@@ -6,8 +6,10 @@
6
6
  ],
7
7
  "include": [
8
8
  "node-gyp-build.d.ts",
9
- "simsimd.ts",
10
- "fallback.ts"
9
+ "numkong.ts",
10
+ "numkong-wasm.ts",
11
+ "numkong-browser.ts",
12
+ "types.ts"
11
13
  ],
12
14
  "compilerOptions": {
13
15
  "allowJs": true,
@@ -17,8 +19,9 @@
17
19
  "esModuleInterop": true,
18
20
  "inlineSourceMap": false,
19
21
  "lib": [
20
- "esnext"
22
+ "ES2020"
21
23
  ],
24
+ "target": "ES2020",
22
25
  "listEmittedFiles": false,
23
26
  "listFiles": false,
24
27
  "moduleResolution": "node",
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "./tsconfig-base.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "outDir": "dist/cjs",
6
+ "target": "ES2020"
7
+ },
8
+ "exclude": [
9
+ "node_modules",
10
+ "dist",
11
+ "numkong-browser.ts"
12
+ ]
13
+ }
@@ -3,6 +3,6 @@
3
3
  "compilerOptions": {
4
4
  "module": "esnext",
5
5
  "outDir": "dist/esm",
6
- "target": "esnext"
6
+ "target": "ES2020"
7
7
  }
8
8
  }