numkong 7.0.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 (294) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +495 -0
  3. package/binding.gyp +540 -0
  4. package/c/dispatch.h +512 -0
  5. package/c/dispatch_bf16.c +389 -0
  6. package/c/dispatch_bf16c.c +52 -0
  7. package/c/dispatch_e2m3.c +263 -0
  8. package/c/dispatch_e3m2.c +243 -0
  9. package/c/dispatch_e4m3.c +276 -0
  10. package/c/dispatch_e5m2.c +272 -0
  11. package/c/dispatch_f16.c +376 -0
  12. package/c/dispatch_f16c.c +58 -0
  13. package/c/dispatch_f32.c +378 -0
  14. package/c/dispatch_f32c.c +99 -0
  15. package/c/dispatch_f64.c +296 -0
  16. package/c/dispatch_f64c.c +98 -0
  17. package/c/dispatch_i16.c +96 -0
  18. package/c/dispatch_i32.c +89 -0
  19. package/c/dispatch_i4.c +150 -0
  20. package/c/dispatch_i64.c +86 -0
  21. package/c/dispatch_i8.c +289 -0
  22. package/c/dispatch_other.c +330 -0
  23. package/c/dispatch_u1.c +148 -0
  24. package/c/dispatch_u16.c +124 -0
  25. package/c/dispatch_u32.c +118 -0
  26. package/c/dispatch_u4.c +150 -0
  27. package/c/dispatch_u64.c +102 -0
  28. package/c/dispatch_u8.c +303 -0
  29. package/c/numkong.c +950 -0
  30. package/include/README.md +573 -0
  31. package/include/module.modulemap +129 -0
  32. package/include/numkong/attention/sapphireamx.h +1361 -0
  33. package/include/numkong/attention/sme.h +2066 -0
  34. package/include/numkong/attention.h +49 -0
  35. package/include/numkong/capabilities.h +748 -0
  36. package/include/numkong/cast/README.md +262 -0
  37. package/include/numkong/cast/haswell.h +975 -0
  38. package/include/numkong/cast/icelake.h +470 -0
  39. package/include/numkong/cast/neon.h +1192 -0
  40. package/include/numkong/cast/rvv.h +1021 -0
  41. package/include/numkong/cast/sapphire.h +262 -0
  42. package/include/numkong/cast/serial.h +2262 -0
  43. package/include/numkong/cast/skylake.h +856 -0
  44. package/include/numkong/cast/v128relaxed.h +180 -0
  45. package/include/numkong/cast.h +230 -0
  46. package/include/numkong/curved/README.md +223 -0
  47. package/include/numkong/curved/genoa.h +182 -0
  48. package/include/numkong/curved/haswell.h +276 -0
  49. package/include/numkong/curved/neon.h +205 -0
  50. package/include/numkong/curved/neonbfdot.h +212 -0
  51. package/include/numkong/curved/neonhalf.h +212 -0
  52. package/include/numkong/curved/rvv.h +305 -0
  53. package/include/numkong/curved/serial.h +207 -0
  54. package/include/numkong/curved/skylake.h +457 -0
  55. package/include/numkong/curved/smef64.h +506 -0
  56. package/include/numkong/curved.h +517 -0
  57. package/include/numkong/curved.hpp +144 -0
  58. package/include/numkong/dot/README.md +425 -0
  59. package/include/numkong/dot/alder.h +563 -0
  60. package/include/numkong/dot/genoa.h +315 -0
  61. package/include/numkong/dot/haswell.h +1688 -0
  62. package/include/numkong/dot/icelake.h +883 -0
  63. package/include/numkong/dot/neon.h +818 -0
  64. package/include/numkong/dot/neonbfdot.h +244 -0
  65. package/include/numkong/dot/neonfhm.h +360 -0
  66. package/include/numkong/dot/neonhalf.h +198 -0
  67. package/include/numkong/dot/neonsdot.h +508 -0
  68. package/include/numkong/dot/rvv.h +714 -0
  69. package/include/numkong/dot/rvvbb.h +72 -0
  70. package/include/numkong/dot/rvvbf16.h +123 -0
  71. package/include/numkong/dot/rvvhalf.h +129 -0
  72. package/include/numkong/dot/sapphire.h +141 -0
  73. package/include/numkong/dot/serial.h +838 -0
  74. package/include/numkong/dot/sierra.h +405 -0
  75. package/include/numkong/dot/skylake.h +1084 -0
  76. package/include/numkong/dot/sve.h +379 -0
  77. package/include/numkong/dot/svebfdot.h +74 -0
  78. package/include/numkong/dot/svehalf.h +123 -0
  79. package/include/numkong/dot/v128relaxed.h +1258 -0
  80. package/include/numkong/dot.h +1070 -0
  81. package/include/numkong/dot.hpp +94 -0
  82. package/include/numkong/dots/README.md +496 -0
  83. package/include/numkong/dots/alder.h +114 -0
  84. package/include/numkong/dots/genoa.h +94 -0
  85. package/include/numkong/dots/haswell.h +295 -0
  86. package/include/numkong/dots/icelake.h +171 -0
  87. package/include/numkong/dots/neon.h +120 -0
  88. package/include/numkong/dots/neonbfdot.h +58 -0
  89. package/include/numkong/dots/neonfhm.h +94 -0
  90. package/include/numkong/dots/neonhalf.h +57 -0
  91. package/include/numkong/dots/neonsdot.h +108 -0
  92. package/include/numkong/dots/rvv.h +2486 -0
  93. package/include/numkong/dots/sapphireamx.h +3973 -0
  94. package/include/numkong/dots/serial.h +2844 -0
  95. package/include/numkong/dots/sierra.h +97 -0
  96. package/include/numkong/dots/skylake.h +196 -0
  97. package/include/numkong/dots/sme.h +5372 -0
  98. package/include/numkong/dots/smebi32.h +461 -0
  99. package/include/numkong/dots/smef64.h +1318 -0
  100. package/include/numkong/dots/smehalf.h +47 -0
  101. package/include/numkong/dots/v128relaxed.h +294 -0
  102. package/include/numkong/dots.h +2804 -0
  103. package/include/numkong/dots.hpp +639 -0
  104. package/include/numkong/each/README.md +469 -0
  105. package/include/numkong/each/haswell.h +1658 -0
  106. package/include/numkong/each/icelake.h +272 -0
  107. package/include/numkong/each/neon.h +1104 -0
  108. package/include/numkong/each/neonbfdot.h +212 -0
  109. package/include/numkong/each/neonhalf.h +410 -0
  110. package/include/numkong/each/rvv.h +1121 -0
  111. package/include/numkong/each/sapphire.h +477 -0
  112. package/include/numkong/each/serial.h +260 -0
  113. package/include/numkong/each/skylake.h +1562 -0
  114. package/include/numkong/each.h +2146 -0
  115. package/include/numkong/each.hpp +434 -0
  116. package/include/numkong/geospatial/README.md +147 -0
  117. package/include/numkong/geospatial/haswell.h +593 -0
  118. package/include/numkong/geospatial/neon.h +571 -0
  119. package/include/numkong/geospatial/rvv.h +701 -0
  120. package/include/numkong/geospatial/serial.h +309 -0
  121. package/include/numkong/geospatial/skylake.h +577 -0
  122. package/include/numkong/geospatial/v128relaxed.h +613 -0
  123. package/include/numkong/geospatial.h +453 -0
  124. package/include/numkong/geospatial.hpp +235 -0
  125. package/include/numkong/matrix.hpp +336 -0
  126. package/include/numkong/maxsim/README.md +187 -0
  127. package/include/numkong/maxsim/alder.h +511 -0
  128. package/include/numkong/maxsim/genoa.h +115 -0
  129. package/include/numkong/maxsim/haswell.h +553 -0
  130. package/include/numkong/maxsim/icelake.h +480 -0
  131. package/include/numkong/maxsim/neonsdot.h +394 -0
  132. package/include/numkong/maxsim/sapphireamx.h +877 -0
  133. package/include/numkong/maxsim/serial.h +490 -0
  134. package/include/numkong/maxsim/sme.h +929 -0
  135. package/include/numkong/maxsim/v128relaxed.h +280 -0
  136. package/include/numkong/maxsim.h +571 -0
  137. package/include/numkong/maxsim.hpp +133 -0
  138. package/include/numkong/mesh/README.md +227 -0
  139. package/include/numkong/mesh/haswell.h +2235 -0
  140. package/include/numkong/mesh/neon.h +1329 -0
  141. package/include/numkong/mesh/neonbfdot.h +842 -0
  142. package/include/numkong/mesh/neonhalf.h +616 -0
  143. package/include/numkong/mesh/rvv.h +916 -0
  144. package/include/numkong/mesh/serial.h +742 -0
  145. package/include/numkong/mesh/skylake.h +1135 -0
  146. package/include/numkong/mesh/v128relaxed.h +1052 -0
  147. package/include/numkong/mesh.h +652 -0
  148. package/include/numkong/mesh.hpp +762 -0
  149. package/include/numkong/numkong.h +78 -0
  150. package/include/numkong/numkong.hpp +57 -0
  151. package/include/numkong/probability/README.md +173 -0
  152. package/include/numkong/probability/haswell.h +267 -0
  153. package/include/numkong/probability/neon.h +225 -0
  154. package/include/numkong/probability/rvv.h +409 -0
  155. package/include/numkong/probability/serial.h +169 -0
  156. package/include/numkong/probability/skylake.h +324 -0
  157. package/include/numkong/probability.h +383 -0
  158. package/include/numkong/probability.hpp +120 -0
  159. package/include/numkong/random.h +50 -0
  160. package/include/numkong/random.hpp +285 -0
  161. package/include/numkong/reduce/README.md +547 -0
  162. package/include/numkong/reduce/alder.h +632 -0
  163. package/include/numkong/reduce/genoa.h +201 -0
  164. package/include/numkong/reduce/haswell.h +3783 -0
  165. package/include/numkong/reduce/icelake.h +549 -0
  166. package/include/numkong/reduce/neon.h +3841 -0
  167. package/include/numkong/reduce/neonbfdot.h +353 -0
  168. package/include/numkong/reduce/neonfhm.h +665 -0
  169. package/include/numkong/reduce/neonhalf.h +157 -0
  170. package/include/numkong/reduce/neonsdot.h +357 -0
  171. package/include/numkong/reduce/rvv.h +3407 -0
  172. package/include/numkong/reduce/serial.h +757 -0
  173. package/include/numkong/reduce/sierra.h +338 -0
  174. package/include/numkong/reduce/skylake.h +3792 -0
  175. package/include/numkong/reduce/v128relaxed.h +2302 -0
  176. package/include/numkong/reduce.h +1597 -0
  177. package/include/numkong/reduce.hpp +633 -0
  178. package/include/numkong/scalar/README.md +89 -0
  179. package/include/numkong/scalar/haswell.h +113 -0
  180. package/include/numkong/scalar/neon.h +122 -0
  181. package/include/numkong/scalar/neonhalf.h +70 -0
  182. package/include/numkong/scalar/rvv.h +211 -0
  183. package/include/numkong/scalar/sapphire.h +63 -0
  184. package/include/numkong/scalar/serial.h +332 -0
  185. package/include/numkong/scalar/v128relaxed.h +56 -0
  186. package/include/numkong/scalar.h +683 -0
  187. package/include/numkong/set/README.md +179 -0
  188. package/include/numkong/set/haswell.h +334 -0
  189. package/include/numkong/set/icelake.h +485 -0
  190. package/include/numkong/set/neon.h +364 -0
  191. package/include/numkong/set/rvv.h +226 -0
  192. package/include/numkong/set/rvvbb.h +117 -0
  193. package/include/numkong/set/serial.h +174 -0
  194. package/include/numkong/set/sve.h +185 -0
  195. package/include/numkong/set/v128relaxed.h +240 -0
  196. package/include/numkong/set.h +457 -0
  197. package/include/numkong/set.hpp +114 -0
  198. package/include/numkong/sets/README.md +149 -0
  199. package/include/numkong/sets/haswell.h +63 -0
  200. package/include/numkong/sets/icelake.h +66 -0
  201. package/include/numkong/sets/neon.h +61 -0
  202. package/include/numkong/sets/serial.h +43 -0
  203. package/include/numkong/sets/smebi32.h +1099 -0
  204. package/include/numkong/sets/v128relaxed.h +58 -0
  205. package/include/numkong/sets.h +339 -0
  206. package/include/numkong/sparse/README.md +156 -0
  207. package/include/numkong/sparse/icelake.h +463 -0
  208. package/include/numkong/sparse/neon.h +288 -0
  209. package/include/numkong/sparse/serial.h +117 -0
  210. package/include/numkong/sparse/sve2.h +507 -0
  211. package/include/numkong/sparse/turin.h +322 -0
  212. package/include/numkong/sparse.h +363 -0
  213. package/include/numkong/sparse.hpp +113 -0
  214. package/include/numkong/spatial/README.md +435 -0
  215. package/include/numkong/spatial/alder.h +607 -0
  216. package/include/numkong/spatial/genoa.h +290 -0
  217. package/include/numkong/spatial/haswell.h +960 -0
  218. package/include/numkong/spatial/icelake.h +586 -0
  219. package/include/numkong/spatial/neon.h +773 -0
  220. package/include/numkong/spatial/neonbfdot.h +165 -0
  221. package/include/numkong/spatial/neonhalf.h +118 -0
  222. package/include/numkong/spatial/neonsdot.h +261 -0
  223. package/include/numkong/spatial/rvv.h +984 -0
  224. package/include/numkong/spatial/rvvbf16.h +123 -0
  225. package/include/numkong/spatial/rvvhalf.h +117 -0
  226. package/include/numkong/spatial/sapphire.h +343 -0
  227. package/include/numkong/spatial/serial.h +346 -0
  228. package/include/numkong/spatial/sierra.h +323 -0
  229. package/include/numkong/spatial/skylake.h +606 -0
  230. package/include/numkong/spatial/sve.h +224 -0
  231. package/include/numkong/spatial/svebfdot.h +122 -0
  232. package/include/numkong/spatial/svehalf.h +109 -0
  233. package/include/numkong/spatial/v128relaxed.h +717 -0
  234. package/include/numkong/spatial.h +1425 -0
  235. package/include/numkong/spatial.hpp +183 -0
  236. package/include/numkong/spatials/README.md +580 -0
  237. package/include/numkong/spatials/alder.h +94 -0
  238. package/include/numkong/spatials/genoa.h +94 -0
  239. package/include/numkong/spatials/haswell.h +219 -0
  240. package/include/numkong/spatials/icelake.h +113 -0
  241. package/include/numkong/spatials/neon.h +109 -0
  242. package/include/numkong/spatials/neonbfdot.h +60 -0
  243. package/include/numkong/spatials/neonfhm.h +92 -0
  244. package/include/numkong/spatials/neonhalf.h +58 -0
  245. package/include/numkong/spatials/neonsdot.h +109 -0
  246. package/include/numkong/spatials/rvv.h +1960 -0
  247. package/include/numkong/spatials/sapphireamx.h +1149 -0
  248. package/include/numkong/spatials/serial.h +226 -0
  249. package/include/numkong/spatials/sierra.h +96 -0
  250. package/include/numkong/spatials/skylake.h +184 -0
  251. package/include/numkong/spatials/sme.h +1901 -0
  252. package/include/numkong/spatials/smef64.h +465 -0
  253. package/include/numkong/spatials/v128relaxed.h +240 -0
  254. package/include/numkong/spatials.h +3021 -0
  255. package/include/numkong/spatials.hpp +508 -0
  256. package/include/numkong/tensor.hpp +1592 -0
  257. package/include/numkong/trigonometry/README.md +184 -0
  258. package/include/numkong/trigonometry/haswell.h +652 -0
  259. package/include/numkong/trigonometry/neon.h +639 -0
  260. package/include/numkong/trigonometry/rvv.h +699 -0
  261. package/include/numkong/trigonometry/serial.h +703 -0
  262. package/include/numkong/trigonometry/skylake.h +721 -0
  263. package/include/numkong/trigonometry/v128relaxed.h +666 -0
  264. package/include/numkong/trigonometry.h +467 -0
  265. package/include/numkong/trigonometry.hpp +166 -0
  266. package/include/numkong/types.h +1384 -0
  267. package/include/numkong/types.hpp +5603 -0
  268. package/include/numkong/vector.hpp +698 -0
  269. package/javascript/README.md +246 -0
  270. package/javascript/dist/cjs/numkong-wasm.d.ts +166 -0
  271. package/javascript/dist/cjs/numkong-wasm.js +617 -0
  272. package/javascript/dist/cjs/numkong.d.ts +343 -0
  273. package/javascript/dist/cjs/numkong.js +523 -0
  274. package/javascript/dist/cjs/package.json +3 -0
  275. package/javascript/dist/cjs/types.d.ts +284 -0
  276. package/javascript/dist/cjs/types.js +653 -0
  277. package/javascript/dist/esm/numkong-wasm.d.ts +166 -0
  278. package/javascript/dist/esm/numkong-wasm.js +595 -0
  279. package/javascript/dist/esm/numkong.d.ts +343 -0
  280. package/javascript/dist/esm/numkong.js +452 -0
  281. package/javascript/dist/esm/package.json +3 -0
  282. package/javascript/dist/esm/types.d.ts +284 -0
  283. package/javascript/dist/esm/types.js +630 -0
  284. package/javascript/dist-package-cjs.json +3 -0
  285. package/javascript/dist-package-esm.json +3 -0
  286. package/javascript/node-gyp-build.d.ts +1 -0
  287. package/javascript/numkong-wasm.ts +756 -0
  288. package/javascript/numkong.c +689 -0
  289. package/javascript/numkong.ts +575 -0
  290. package/javascript/tsconfig-base.json +39 -0
  291. package/javascript/tsconfig-cjs.json +8 -0
  292. package/javascript/tsconfig-esm.json +8 -0
  293. package/javascript/types.ts +674 -0
  294. package/package.json +87 -0
@@ -0,0 +1,343 @@
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
+ import { Float16Array, BFloat16Array, E4M3Array, E5M2Array, BinaryArray, TensorBase, VectorBase, VectorView, Vector, MatrixBase, Matrix, PackedMatrix, DType, outputDtype } from "./types.js";
28
+ /**
29
+ * CPU capability bit masks in chronological order (by first commercial silicon).
30
+ * Use these with getCapabilities() to check for specific SIMD support.
31
+ */
32
+ export declare const Capability: {
33
+ readonly SERIAL: bigint;
34
+ readonly NEON: bigint;
35
+ readonly HASWELL: bigint;
36
+ readonly SKYLAKE: bigint;
37
+ readonly NEONHALF: bigint;
38
+ readonly NEONSDOT: bigint;
39
+ readonly NEONFHM: bigint;
40
+ readonly ICELAKE: bigint;
41
+ readonly GENOA: bigint;
42
+ readonly NEONBFDOT: bigint;
43
+ readonly SVE: bigint;
44
+ readonly SVEHALF: bigint;
45
+ readonly SVESDOT: bigint;
46
+ readonly SIERRA: bigint;
47
+ readonly SVEBFDOT: bigint;
48
+ readonly SVE2: bigint;
49
+ readonly V128RELAXED: bigint;
50
+ readonly SAPPHIRE: bigint;
51
+ readonly SAPPHIREAMX: bigint;
52
+ readonly RVV: bigint;
53
+ readonly RVVHALF: bigint;
54
+ readonly RVVBF16: bigint;
55
+ readonly GRANITEAMX: bigint;
56
+ readonly TURIN: bigint;
57
+ readonly SME: bigint;
58
+ readonly SME2: bigint;
59
+ readonly SMEF64: bigint;
60
+ readonly SMEFA64: bigint;
61
+ readonly SVE2P1: bigint;
62
+ readonly SME2P1: bigint;
63
+ readonly SMEHALF: bigint;
64
+ readonly SMEBF16: bigint;
65
+ readonly SMELUT2: bigint;
66
+ readonly RVVBB: bigint;
67
+ };
68
+ export { Float16Array, BFloat16Array, E4M3Array, E5M2Array, BinaryArray, TensorBase, VectorBase, VectorView, Vector, MatrixBase, Matrix, PackedMatrix, outputDtype };
69
+ /** Convert a single FP16 value (as uint16 bits) to FP32 */
70
+ export declare const castF16ToF32: any;
71
+ /** Convert a single FP32 value to FP16 (returns uint16 bits) */
72
+ export declare const castF32ToF16: any;
73
+ /** Convert a single BF16 value (as uint16 bits) to FP32 */
74
+ export declare const castBF16ToF32: any;
75
+ /** Convert a single FP32 value to BF16 (returns uint16 bits) */
76
+ export declare const castF32ToBF16: any;
77
+ /** Convert a single E4M3 value (as uint8 bits) to FP32 */
78
+ export declare const castE4M3ToF32: any;
79
+ /** Convert a single FP32 value to E4M3 (returns uint8 bits) */
80
+ export declare const castF32ToE4M3: any;
81
+ /** Convert a single E5M2 value (as uint8 bits) to FP32 */
82
+ export declare const castE5M2ToF32: any;
83
+ /** Convert a single FP32 value to E5M2 (returns uint8 bits) */
84
+ export declare const castF32ToE5M2: any;
85
+ /** Bulk conversion between different numeric types (modifies destination array in-place) */
86
+ export declare const cast: any;
87
+ export { DType };
88
+ /**
89
+ * Numeric arrays supported by distance metrics with auto-detected dtype.
90
+ *
91
+ * These standard TypedArrays are auto-detected by the N-API binding.
92
+ */
93
+ export type NumericArray = Float64Array | Float32Array | Int8Array | Uint8Array;
94
+ /**
95
+ * Extended array types supported by distance metrics with explicit dtype parameter.
96
+ *
97
+ * Includes Uint16Array (backing type for Float16Array and BFloat16Array) in addition
98
+ * to the auto-detected types. Pass a dtype string as the third argument to distance
99
+ * functions when using custom types.
100
+ */
101
+ export type DistanceArray = Float64Array | Float32Array | Int8Array | Uint8Array | Uint16Array;
102
+ /**
103
+ * Union type for all array types (including custom types for conversions)
104
+ */
105
+ export type NumKongArray = Float64Array | Float32Array | Float16Array | BFloat16Array | E4M3Array | E5M2Array | Int8Array | Uint8Array | BinaryArray;
106
+ /**
107
+ * Returns the runtime-detected SIMD capabilities as a bitmask.
108
+ *
109
+ * The bitmask includes flags for various SIMD instruction sets like AVX2, AVX-512,
110
+ * ARM NEON, ARM SVE, ARM SME, RISC-V Vector, and WASM SIMD extensions.
111
+ * Use with Capability constants to check for specific instruction sets.
112
+ *
113
+ * @returns {bigint} Bitmask of capability flags (use with Capability constants)
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * import { getCapabilities, Capability } from 'numkong';
118
+ *
119
+ * const caps = getCapabilities();
120
+ * console.log(`Capabilities: 0x${caps.toString(16)}`);
121
+ *
122
+ * // Check for specific SIMD support
123
+ * if (caps & Capability.HASWELL) {
124
+ * console.log('AVX2 available');
125
+ * }
126
+ * ```
127
+ */
128
+ export declare const getCapabilities: () => bigint;
129
+ /**
130
+ * Checks if a specific SIMD capability is available at runtime.
131
+ *
132
+ * This is a convenience wrapper around getCapabilities() that tests for a single capability.
133
+ *
134
+ * @param {bigint} cap - Capability flag to check (from Capability constants)
135
+ * @returns {boolean} True if the capability is available, false otherwise
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * import { hasCapability, Capability } from 'numkong';
140
+ *
141
+ * if (hasCapability(Capability.HASWELL)) {
142
+ * console.log('Intel AVX2 (Haswell) available');
143
+ * }
144
+ * if (hasCapability(Capability.NEON)) {
145
+ * console.log('ARM NEON available');
146
+ * }
147
+ * if (hasCapability(Capability.V128RELAXED)) {
148
+ * console.log('WASM Relaxed SIMD available');
149
+ * }
150
+ * ```
151
+ */
152
+ export declare const hasCapability: (cap: bigint) => boolean;
153
+ /**
154
+ * Computes the squared Euclidean distance between two vectors.
155
+ * @param a - The first vector.
156
+ * @param b - The second vector (must match the type of a).
157
+ * @param dtype - Optional dtype string for custom types (e.g. 'f16', 'bf16', 'e4m3').
158
+ * @returns {number} The squared Euclidean distance between vectors a and b.
159
+ */
160
+ export declare function sqeuclidean(a: NumericArray, b: NumericArray): number;
161
+ export declare function sqeuclidean(a: DistanceArray, b: DistanceArray, dtype: DType): number;
162
+ export declare function sqeuclidean(a: TensorBase, b: TensorBase): number;
163
+ /**
164
+ * Computes the Euclidean distance between two vectors.
165
+ * @param a - The first vector.
166
+ * @param b - The second vector (must match the type of a).
167
+ * @param dtype - Optional dtype string for custom types (e.g. 'f16', 'bf16', 'e4m3').
168
+ * @returns {number} The Euclidean distance between vectors a and b.
169
+ */
170
+ export declare function euclidean(a: NumericArray, b: NumericArray): number;
171
+ export declare function euclidean(a: DistanceArray, b: DistanceArray, dtype: DType): number;
172
+ export declare function euclidean(a: TensorBase, b: TensorBase): number;
173
+ /**
174
+ * Computes the angular distance between two vectors.
175
+ * @param a - The first vector.
176
+ * @param b - The second vector (must match the type of a).
177
+ * @param dtype - Optional dtype string for custom types (e.g. 'f16', 'bf16', 'e4m3').
178
+ * @returns {number} The angular distance between vectors a and b.
179
+ */
180
+ export declare function angular(a: NumericArray, b: NumericArray): number;
181
+ export declare function angular(a: DistanceArray, b: DistanceArray, dtype: DType): number;
182
+ export declare function angular(a: TensorBase, b: TensorBase): number;
183
+ /**
184
+ * Computes the inner product of two vectors (same as dot product).
185
+ * @param a - The first vector.
186
+ * @param b - The second vector (must match the type of a).
187
+ * @param dtype - Optional dtype string for custom types (e.g. 'f16', 'bf16', 'e4m3').
188
+ * @returns {number} The inner product of vectors a and b.
189
+ */
190
+ export declare function inner(a: NumericArray, b: NumericArray): number;
191
+ export declare function inner(a: DistanceArray, b: DistanceArray, dtype: DType): number;
192
+ export declare function inner(a: TensorBase, b: TensorBase): number;
193
+ /**
194
+ * Computes the dot product of two vectors (same as inner product).
195
+ * @param a - The first vector.
196
+ * @param b - The second vector (must match the type of a).
197
+ * @param dtype - Optional dtype string for custom types (e.g. 'f16', 'bf16', 'e4m3').
198
+ * @returns {number} The dot product of vectors a and b.
199
+ */
200
+ export declare function dot(a: NumericArray, b: NumericArray): number;
201
+ export declare function dot(a: DistanceArray, b: DistanceArray, dtype: DType): number;
202
+ export declare function dot(a: TensorBase, b: TensorBase): number;
203
+ /**
204
+ * Computes the bitwise Hamming distance between two vectors.
205
+ *
206
+ * Both vectors are treated as bit-packed (u1 dtype), where each byte contains 8 bits.
207
+ * Use toBinary() to convert numeric arrays to bit-packed format.
208
+ *
209
+ * @param {Uint8Array | BinaryArray} a - The first bit-packed vector.
210
+ * @param {Uint8Array | BinaryArray} b - The second bit-packed vector.
211
+ * @returns {number} The Hamming distance (number of differing bits) between vectors a and b.
212
+ */
213
+ export declare const hamming: (a: Uint8Array | BinaryArray | TensorBase, b: Uint8Array | BinaryArray | TensorBase) => number;
214
+ /**
215
+ * Computes the bitwise Jaccard distance between two vectors.
216
+ *
217
+ * Both vectors are treated as bit-packed (u1 dtype), where each byte contains 8 bits.
218
+ * Use toBinary() to convert numeric arrays to bit-packed format.
219
+ *
220
+ * @param {Uint8Array | BinaryArray} a - The first bit-packed vector.
221
+ * @param {Uint8Array | BinaryArray} b - The second bit-packed vector.
222
+ * @returns {number} The Jaccard distance (1 - Jaccard similarity) between vectors a and b.
223
+ */
224
+ export declare const jaccard: (a: Uint8Array | BinaryArray | TensorBase, b: Uint8Array | BinaryArray | TensorBase) => number;
225
+ /**
226
+ * Computes the Kullback-Leibler divergence between two probability distributions.
227
+ *
228
+ * Both vectors must represent valid probability distributions (non-negative, sum to 1).
229
+ * Supports f64, f32 (auto-detected) and f16, bf16 (with explicit dtype).
230
+ *
231
+ * @param a - The first probability distribution.
232
+ * @param b - The second probability distribution (must match the type of a).
233
+ * @param dtype - Optional dtype string for custom types (e.g. 'f16', 'bf16').
234
+ * @returns {number} The Kullback-Leibler divergence KL(a || b) = Σ a[i] * log(a[i] / b[i]).
235
+ */
236
+ export declare function kullbackleibler(a: Float64Array | Float32Array, b: Float64Array | Float32Array): number;
237
+ export declare function kullbackleibler(a: Float64Array | Float32Array | Uint16Array, b: Float64Array | Float32Array | Uint16Array, dtype: DType): number;
238
+ export declare function kullbackleibler(a: TensorBase, b: TensorBase): number;
239
+ /**
240
+ * Computes the Jensen-Shannon distance between two probability distributions.
241
+ *
242
+ * Both vectors must represent valid probability distributions (non-negative, sum to 1).
243
+ * Supports f64, f32 (auto-detected) and f16, bf16 (with explicit dtype).
244
+ * JSD is the square root of the symmetrized KL divergence, forming a true metric.
245
+ *
246
+ * @param a - The first probability distribution.
247
+ * @param b - The second probability distribution (must match the type of a).
248
+ * @param dtype - Optional dtype string for custom types (e.g. 'f16', 'bf16').
249
+ * @returns {number} The Jensen-Shannon distance d_JS(a, b) = √(0.5 × (KL(a‖m) + KL(b‖m))), where m = (a + b) / 2.
250
+ */
251
+ export declare function jensenshannon(a: Float64Array | Float32Array, b: Float64Array | Float32Array): number;
252
+ export declare function jensenshannon(a: Float64Array | Float32Array | Uint16Array, b: Float64Array | Float32Array | Uint16Array, dtype: DType): number;
253
+ export declare function jensenshannon(a: TensorBase, b: TensorBase): number;
254
+ /**
255
+ * Quantizes a numeric vector into a bit-packed binary representation.
256
+ *
257
+ * Converts each element to a single bit: 1 for positive values, 0 for non-positive values.
258
+ * The bits are packed into bytes (8 bits per byte) in big-endian bit order within each byte.
259
+ * This is the required format for hamming() and jaccard() distance functions.
260
+ *
261
+ * @param {Float32Array | Float64Array | Int8Array} vector - The vector to quantize and pack.
262
+ * @returns {Uint8Array} A bit-packed array where each byte contains 8 binary values.
263
+ *
264
+ * @example
265
+ * ```ts
266
+ * const vec = new Float32Array([1.5, -2.3, 0.0, 3.1, -1.0, 2.0, 0.5, -0.5]);
267
+ * const binary = toBinary(vec);
268
+ * // Result: Uint8Array([0b10010110]) = [0x96]
269
+ * // bits: [1, 0, 0, 1, 0, 1, 1, 0] for elements [+, -, 0, +, -, +, +, -]
270
+ *
271
+ * // Use with Hamming distance
272
+ * const a = toBinary(new Float32Array([1, 2, 3]));
273
+ * const b = toBinary(new Float32Array([1, -2, 3]));
274
+ * const dist = hamming(a, b); // Counts differing bits
275
+ * ```
276
+ */
277
+ export declare const toBinary: (vector: Float32Array | Float64Array | Int8Array) => Uint8Array;
278
+ /**
279
+ * Query the packed buffer byte count for a given matrix shape and dtype.
280
+ */
281
+ export declare function dotsPackedSize(width: number, depth: number, dtype: DType): number;
282
+ /**
283
+ * Pack a Matrix for use with packed GEMM-like operations.
284
+ */
285
+ export declare function dotsPack(matrix: Matrix): PackedMatrix;
286
+ export declare function dotsPacked(a: Matrix, packed: PackedMatrix, out?: Matrix): Matrix;
287
+ export declare function angularsPacked(a: Matrix, packed: PackedMatrix, out?: Matrix): Matrix;
288
+ export declare function euclideansPacked(a: Matrix, packed: PackedMatrix, out?: Matrix): Matrix;
289
+ export declare function dotsSymmetric(vectors: Matrix, out?: Matrix, options?: {
290
+ rowStart?: number;
291
+ rowCount?: number;
292
+ }): Matrix;
293
+ export declare function angularsSymmetric(vectors: Matrix, out?: Matrix, options?: {
294
+ rowStart?: number;
295
+ rowCount?: number;
296
+ }): Matrix;
297
+ export declare function euclideansSymmetric(vectors: Matrix, out?: Matrix, options?: {
298
+ rowStart?: number;
299
+ rowCount?: number;
300
+ }): Matrix;
301
+ declare const _default: {
302
+ dot: typeof dot;
303
+ inner: typeof inner;
304
+ sqeuclidean: typeof sqeuclidean;
305
+ euclidean: typeof euclidean;
306
+ angular: typeof angular;
307
+ hamming: (a: Uint8Array | BinaryArray | TensorBase, b: Uint8Array | BinaryArray | TensorBase) => number;
308
+ jaccard: (a: Uint8Array | BinaryArray | TensorBase, b: Uint8Array | BinaryArray | TensorBase) => number;
309
+ kullbackleibler: typeof kullbackleibler;
310
+ jensenshannon: typeof jensenshannon;
311
+ toBinary: (vector: Float32Array | Float64Array | Int8Array) => Uint8Array;
312
+ Float16Array: typeof Float16Array;
313
+ BFloat16Array: typeof BFloat16Array;
314
+ E4M3Array: typeof E4M3Array;
315
+ E5M2Array: typeof E5M2Array;
316
+ BinaryArray: typeof BinaryArray;
317
+ TensorBase: typeof TensorBase;
318
+ VectorBase: typeof VectorBase;
319
+ VectorView: typeof VectorView;
320
+ Vector: typeof Vector;
321
+ MatrixBase: typeof MatrixBase;
322
+ Matrix: typeof Matrix;
323
+ PackedMatrix: typeof PackedMatrix;
324
+ castF16ToF32: any;
325
+ castF32ToF16: any;
326
+ castBF16ToF32: any;
327
+ castF32ToBF16: any;
328
+ castE4M3ToF32: any;
329
+ castF32ToE4M3: any;
330
+ castE5M2ToF32: any;
331
+ castF32ToE5M2: any;
332
+ cast: any;
333
+ dotsPack: typeof dotsPack;
334
+ dotsPacked: typeof dotsPacked;
335
+ angularsPacked: typeof angularsPacked;
336
+ euclideansPacked: typeof euclideansPacked;
337
+ dotsSymmetric: typeof dotsSymmetric;
338
+ angularsSymmetric: typeof angularsSymmetric;
339
+ euclideansSymmetric: typeof euclideansSymmetric;
340
+ dotsPackedSize: typeof dotsPackedSize;
341
+ outputDtype: typeof outputDtype;
342
+ };
343
+ export default _default;