numkong 7.0.0 → 7.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +239 -122
- package/binding.gyp +25 -491
- package/c/dispatch_bf16.c +59 -1
- package/c/dispatch_e2m3.c +41 -8
- package/c/dispatch_e3m2.c +49 -8
- package/c/dispatch_e4m3.c +51 -9
- package/c/dispatch_e5m2.c +45 -1
- package/c/dispatch_f16.c +79 -26
- package/c/dispatch_f16c.c +5 -5
- package/c/dispatch_f32.c +56 -0
- package/c/dispatch_f64.c +52 -0
- package/c/dispatch_i4.c +3 -0
- package/c/dispatch_i8.c +62 -3
- package/c/dispatch_other.c +18 -0
- package/c/dispatch_u1.c +54 -9
- package/c/dispatch_u4.c +3 -0
- package/c/dispatch_u8.c +64 -3
- package/c/numkong.c +3 -0
- package/include/README.md +79 -9
- package/include/numkong/attention/sapphireamx.h +278 -276
- package/include/numkong/attention/sme.h +983 -977
- package/include/numkong/attention.h +1 -1
- package/include/numkong/capabilities.h +289 -94
- package/include/numkong/cast/README.md +40 -40
- package/include/numkong/cast/diamond.h +64 -0
- package/include/numkong/cast/haswell.h +42 -194
- package/include/numkong/cast/icelake.h +42 -37
- package/include/numkong/cast/loongsonasx.h +252 -0
- package/include/numkong/cast/neon.h +216 -249
- package/include/numkong/cast/powervsx.h +449 -0
- package/include/numkong/cast/rvv.h +223 -274
- package/include/numkong/cast/sapphire.h +18 -18
- package/include/numkong/cast/serial.h +1018 -944
- package/include/numkong/cast/skylake.h +82 -23
- package/include/numkong/cast/v128relaxed.h +462 -105
- package/include/numkong/cast.h +24 -0
- package/include/numkong/cast.hpp +44 -0
- package/include/numkong/curved/README.md +17 -17
- package/include/numkong/curved/neon.h +131 -7
- package/include/numkong/curved/neonbfdot.h +6 -7
- package/include/numkong/curved/rvv.h +26 -26
- package/include/numkong/curved/smef64.h +186 -182
- package/include/numkong/curved.h +14 -18
- package/include/numkong/dot/README.md +154 -137
- package/include/numkong/dot/alder.h +43 -43
- package/include/numkong/dot/diamond.h +158 -0
- package/include/numkong/dot/genoa.h +4 -30
- package/include/numkong/dot/haswell.h +215 -180
- package/include/numkong/dot/icelake.h +190 -76
- package/include/numkong/dot/loongsonasx.h +671 -0
- package/include/numkong/dot/neon.h +124 -73
- package/include/numkong/dot/neonbfdot.h +11 -12
- package/include/numkong/dot/neonfhm.h +44 -46
- package/include/numkong/dot/neonfp8.h +323 -0
- package/include/numkong/dot/neonsdot.h +190 -76
- package/include/numkong/dot/powervsx.h +752 -0
- package/include/numkong/dot/rvv.h +92 -84
- package/include/numkong/dot/rvvbf16.h +12 -12
- package/include/numkong/dot/rvvhalf.h +12 -12
- package/include/numkong/dot/sapphire.h +4 -4
- package/include/numkong/dot/serial.h +66 -30
- package/include/numkong/dot/sierra.h +31 -31
- package/include/numkong/dot/skylake.h +142 -110
- package/include/numkong/dot/sve.h +217 -177
- package/include/numkong/dot/svebfdot.h +10 -10
- package/include/numkong/dot/svehalf.h +85 -41
- package/include/numkong/dot/svesdot.h +89 -0
- package/include/numkong/dot/v128relaxed.h +124 -89
- package/include/numkong/dot.h +114 -48
- package/include/numkong/dots/README.md +203 -203
- package/include/numkong/dots/alder.h +12 -9
- package/include/numkong/dots/diamond.h +86 -0
- package/include/numkong/dots/genoa.h +10 -4
- package/include/numkong/dots/haswell.h +63 -48
- package/include/numkong/dots/icelake.h +27 -18
- package/include/numkong/dots/loongsonasx.h +176 -0
- package/include/numkong/dots/neon.h +14 -11
- package/include/numkong/dots/neonbfdot.h +4 -3
- package/include/numkong/dots/neonfhm.h +11 -9
- package/include/numkong/dots/neonfp8.h +99 -0
- package/include/numkong/dots/neonsdot.h +48 -12
- package/include/numkong/dots/powervsx.h +194 -0
- package/include/numkong/dots/rvv.h +451 -344
- package/include/numkong/dots/sapphireamx.h +1028 -984
- package/include/numkong/dots/serial.h +213 -197
- package/include/numkong/dots/sierra.h +10 -7
- package/include/numkong/dots/skylake.h +47 -36
- package/include/numkong/dots/sme.h +2001 -2364
- package/include/numkong/dots/smebi32.h +175 -162
- package/include/numkong/dots/smef64.h +328 -323
- package/include/numkong/dots/v128relaxed.h +64 -41
- package/include/numkong/dots.h +573 -293
- package/include/numkong/dots.hpp +45 -43
- package/include/numkong/each/README.md +133 -137
- package/include/numkong/each/haswell.h +6 -6
- package/include/numkong/each/icelake.h +7 -7
- package/include/numkong/each/neon.h +76 -42
- package/include/numkong/each/neonbfdot.h +11 -12
- package/include/numkong/each/neonhalf.h +24 -116
- package/include/numkong/each/rvv.h +28 -28
- package/include/numkong/each/sapphire.h +27 -161
- package/include/numkong/each/serial.h +6 -6
- package/include/numkong/each/skylake.h +7 -7
- package/include/numkong/each/v128relaxed.h +562 -0
- package/include/numkong/each.h +148 -62
- package/include/numkong/each.hpp +2 -2
- package/include/numkong/geospatial/README.md +18 -18
- package/include/numkong/geospatial/haswell.h +365 -325
- package/include/numkong/geospatial/neon.h +350 -306
- package/include/numkong/geospatial/rvv.h +4 -4
- package/include/numkong/geospatial/skylake.h +376 -340
- package/include/numkong/geospatial/v128relaxed.h +366 -327
- package/include/numkong/geospatial.h +17 -17
- package/include/numkong/matrix.hpp +4 -4
- package/include/numkong/maxsim/README.md +14 -14
- package/include/numkong/maxsim/alder.h +6 -6
- package/include/numkong/maxsim/genoa.h +4 -4
- package/include/numkong/maxsim/haswell.h +6 -6
- package/include/numkong/maxsim/icelake.h +18 -18
- package/include/numkong/maxsim/neonsdot.h +21 -21
- package/include/numkong/maxsim/sapphireamx.h +14 -14
- package/include/numkong/maxsim/serial.h +6 -6
- package/include/numkong/maxsim/sme.h +221 -196
- package/include/numkong/maxsim/v128relaxed.h +6 -6
- package/include/numkong/mesh/README.md +62 -56
- package/include/numkong/mesh/haswell.h +339 -464
- package/include/numkong/mesh/neon.h +1100 -519
- package/include/numkong/mesh/neonbfdot.h +36 -68
- package/include/numkong/mesh/rvv.h +530 -435
- package/include/numkong/mesh/serial.h +75 -91
- package/include/numkong/mesh/skylake.h +1627 -302
- package/include/numkong/mesh/v128relaxed.h +443 -330
- package/include/numkong/mesh.h +63 -49
- package/include/numkong/mesh.hpp +4 -4
- package/include/numkong/numkong.h +3 -3
- package/include/numkong/numkong.hpp +1 -0
- package/include/numkong/probability/README.md +23 -19
- package/include/numkong/probability/neon.h +82 -52
- package/include/numkong/probability/rvv.h +28 -23
- package/include/numkong/probability/serial.h +51 -39
- package/include/numkong/probability.h +20 -23
- package/include/numkong/random.h +1 -1
- package/include/numkong/reduce/README.md +143 -138
- package/include/numkong/reduce/alder.h +81 -77
- package/include/numkong/reduce/haswell.h +222 -220
- package/include/numkong/reduce/neon.h +629 -519
- package/include/numkong/reduce/neonbfdot.h +7 -218
- package/include/numkong/reduce/neonfhm.h +9 -381
- package/include/numkong/reduce/neonsdot.h +9 -9
- package/include/numkong/reduce/rvv.h +928 -802
- package/include/numkong/reduce/serial.h +23 -27
- package/include/numkong/reduce/sierra.h +20 -20
- package/include/numkong/reduce/skylake.h +326 -324
- package/include/numkong/reduce/v128relaxed.h +52 -52
- package/include/numkong/reduce.h +4 -23
- package/include/numkong/reduce.hpp +156 -11
- package/include/numkong/scalar/README.md +6 -6
- package/include/numkong/scalar/haswell.h +26 -17
- package/include/numkong/scalar/loongsonasx.h +74 -0
- package/include/numkong/scalar/neon.h +9 -9
- package/include/numkong/scalar/powervsx.h +96 -0
- package/include/numkong/scalar/rvv.h +2 -2
- package/include/numkong/scalar/sapphire.h +21 -10
- package/include/numkong/scalar/serial.h +21 -21
- package/include/numkong/scalar.h +13 -0
- package/include/numkong/set/README.md +28 -28
- package/include/numkong/set/haswell.h +12 -12
- package/include/numkong/set/icelake.h +14 -14
- package/include/numkong/set/loongsonasx.h +181 -0
- package/include/numkong/set/neon.h +17 -18
- package/include/numkong/set/powervsx.h +326 -0
- package/include/numkong/set/rvv.h +4 -4
- package/include/numkong/set/serial.h +6 -6
- package/include/numkong/set/sve.h +60 -59
- package/include/numkong/set/v128relaxed.h +6 -6
- package/include/numkong/set.h +21 -7
- package/include/numkong/sets/README.md +26 -26
- package/include/numkong/sets/loongsonasx.h +52 -0
- package/include/numkong/sets/powervsx.h +65 -0
- package/include/numkong/sets/smebi32.h +395 -364
- package/include/numkong/sets.h +83 -40
- package/include/numkong/sparse/README.md +4 -4
- package/include/numkong/sparse/icelake.h +101 -101
- package/include/numkong/sparse/serial.h +1 -1
- package/include/numkong/sparse/sve2.h +137 -141
- package/include/numkong/sparse/turin.h +12 -12
- package/include/numkong/sparse.h +10 -10
- package/include/numkong/spatial/README.md +230 -226
- package/include/numkong/spatial/alder.h +113 -116
- package/include/numkong/spatial/diamond.h +240 -0
- package/include/numkong/spatial/genoa.h +0 -68
- package/include/numkong/spatial/haswell.h +74 -55
- package/include/numkong/spatial/icelake.h +539 -58
- package/include/numkong/spatial/loongsonasx.h +483 -0
- package/include/numkong/spatial/neon.h +125 -52
- package/include/numkong/spatial/neonbfdot.h +8 -9
- package/include/numkong/spatial/neonfp8.h +258 -0
- package/include/numkong/spatial/neonsdot.h +180 -12
- package/include/numkong/spatial/powervsx.h +738 -0
- package/include/numkong/spatial/rvv.h +146 -139
- package/include/numkong/spatial/rvvbf16.h +17 -12
- package/include/numkong/spatial/rvvhalf.h +13 -10
- package/include/numkong/spatial/serial.h +13 -12
- package/include/numkong/spatial/sierra.h +232 -39
- package/include/numkong/spatial/skylake.h +73 -74
- package/include/numkong/spatial/sve.h +93 -72
- package/include/numkong/spatial/svebfdot.h +29 -29
- package/include/numkong/spatial/svehalf.h +52 -26
- package/include/numkong/spatial/svesdot.h +142 -0
- package/include/numkong/spatial/v128relaxed.h +293 -41
- package/include/numkong/spatial.h +338 -82
- package/include/numkong/spatials/README.md +194 -194
- package/include/numkong/spatials/diamond.h +82 -0
- package/include/numkong/spatials/haswell.h +2 -2
- package/include/numkong/spatials/loongsonasx.h +153 -0
- package/include/numkong/spatials/neonfp8.h +111 -0
- package/include/numkong/spatials/neonsdot.h +34 -0
- package/include/numkong/spatials/powervsx.h +153 -0
- package/include/numkong/spatials/rvv.h +259 -243
- package/include/numkong/spatials/sapphireamx.h +173 -173
- package/include/numkong/spatials/serial.h +2 -2
- package/include/numkong/spatials/skylake.h +2 -2
- package/include/numkong/spatials/sme.h +590 -605
- package/include/numkong/spatials/smef64.h +139 -130
- package/include/numkong/spatials/v128relaxed.h +2 -2
- package/include/numkong/spatials.h +820 -500
- package/include/numkong/spatials.hpp +49 -48
- package/include/numkong/tensor.hpp +406 -17
- package/include/numkong/trigonometry/README.md +19 -19
- package/include/numkong/trigonometry/haswell.h +402 -401
- package/include/numkong/trigonometry/neon.h +386 -387
- package/include/numkong/trigonometry/rvv.h +52 -51
- package/include/numkong/trigonometry/serial.h +13 -13
- package/include/numkong/trigonometry/skylake.h +373 -369
- package/include/numkong/trigonometry/v128relaxed.h +375 -374
- package/include/numkong/trigonometry.h +13 -13
- package/include/numkong/trigonometry.hpp +2 -2
- package/include/numkong/types.h +287 -49
- package/include/numkong/types.hpp +436 -12
- package/include/numkong/vector.hpp +82 -14
- package/javascript/dist/cjs/numkong-wasm.js +6 -12
- package/javascript/dist/cjs/numkong.d.ts +7 -1
- package/javascript/dist/cjs/numkong.js +37 -11
- package/javascript/dist/cjs/types.d.ts +9 -0
- package/javascript/dist/cjs/types.js +96 -0
- package/javascript/dist/esm/numkong-browser.d.ts +14 -0
- package/javascript/dist/esm/numkong-browser.js +23 -0
- package/javascript/dist/esm/numkong-wasm.js +6 -12
- package/javascript/dist/esm/numkong.d.ts +7 -1
- package/javascript/dist/esm/numkong.js +37 -11
- package/javascript/dist/esm/types.d.ts +9 -0
- package/javascript/dist/esm/types.js +96 -0
- package/javascript/node-gyp-build.d.ts +4 -1
- package/javascript/numkong-browser.ts +40 -0
- package/javascript/numkong-wasm.ts +7 -13
- package/javascript/numkong.c +5 -26
- package/javascript/numkong.ts +36 -11
- package/javascript/tsconfig-base.json +1 -0
- package/javascript/tsconfig-cjs.json +6 -1
- package/javascript/types.ts +110 -0
- package/numkong.gypi +101 -0
- package/package.json +34 -13
- package/probes/arm_neon.c +8 -0
- package/probes/arm_neon_bfdot.c +9 -0
- package/probes/arm_neon_fhm.c +9 -0
- package/probes/arm_neon_half.c +8 -0
- package/probes/arm_neon_sdot.c +9 -0
- package/probes/arm_neonfp8.c +9 -0
- package/probes/arm_sme.c +16 -0
- package/probes/arm_sme2.c +16 -0
- package/probes/arm_sme2p1.c +16 -0
- package/probes/arm_sme_bf16.c +16 -0
- package/probes/arm_sme_bi32.c +16 -0
- package/probes/arm_sme_f64.c +16 -0
- package/probes/arm_sme_fa64.c +14 -0
- package/probes/arm_sme_half.c +16 -0
- package/probes/arm_sme_lut2.c +15 -0
- package/probes/arm_sve.c +18 -0
- package/probes/arm_sve2.c +20 -0
- package/probes/arm_sve2p1.c +18 -0
- package/probes/arm_sve_bfdot.c +20 -0
- package/probes/arm_sve_half.c +18 -0
- package/probes/arm_sve_sdot.c +21 -0
- package/probes/loongarch_lasx.c +12 -0
- package/probes/power_vsx.c +12 -0
- package/probes/probe.js +127 -0
- package/probes/riscv_rvv.c +14 -0
- package/probes/riscv_rvv_bb.c +15 -0
- package/probes/riscv_rvv_bf16.c +17 -0
- package/probes/riscv_rvv_half.c +14 -0
- package/probes/wasm_v128relaxed.c +11 -0
- package/probes/x86_alder.c +17 -0
- package/probes/x86_diamond.c +17 -0
- package/probes/x86_genoa.c +17 -0
- package/probes/x86_graniteamx.c +19 -0
- package/probes/x86_haswell.c +11 -0
- package/probes/x86_icelake.c +17 -0
- package/probes/x86_sapphire.c +16 -0
- package/probes/x86_sapphireamx.c +18 -0
- package/probes/x86_sierra.c +17 -0
- package/probes/x86_skylake.c +15 -0
- package/probes/x86_turin.c +17 -0
- package/wasm/numkong-emscripten.js +2 -0
- package/wasm/numkong.d.ts +14 -0
- package/wasm/numkong.js +1124 -0
- package/wasm/numkong.wasm +0 -0
- package/include/numkong/curved/neonhalf.h +0 -212
- package/include/numkong/dot/neonhalf.h +0 -198
- package/include/numkong/dots/neonhalf.h +0 -57
- package/include/numkong/mesh/neonhalf.h +0 -616
- package/include/numkong/reduce/neonhalf.h +0 -157
- package/include/numkong/spatial/neonhalf.h +0 -118
- package/include/numkong/spatial/sapphire.h +0 -343
- package/include/numkong/spatials/neonhalf.h +0 -58
- package/javascript/README.md +0 -246
package/javascript/README.md
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
# NumKong for JavaScript
|
|
2
|
-
|
|
3
|
-
NumKong's JavaScript package brings low-latency vector kernels to Node and Bun-style runtimes, targeting the space between handwritten loops over `TypedArray`s and much heavier tensor frameworks.
|
|
4
|
-
It keeps the JS surface intentionally compact: dense distances, dot products, binary metrics, probability divergences, packed GEMM-like matrix multiplication, symmetric Gram matrices, dtype-tagged low-precision storage, typed views, and runtime capability inspection.
|
|
5
|
-
|
|
6
|
-
## Quickstart
|
|
7
|
-
|
|
8
|
-
```ts
|
|
9
|
-
import { dot } from "numkong";
|
|
10
|
-
|
|
11
|
-
const a = new Float32Array([1, 2, 3]);
|
|
12
|
-
const b = new Float32Array([4, 5, 6]);
|
|
13
|
-
console.log(dot(a, b)); // 32
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## Highlights
|
|
17
|
-
|
|
18
|
-
This SDK is deliberately smaller than Python or Rust.
|
|
19
|
-
Its job is to make the hot vector kernels easy to use from modern JavaScript runtimes.
|
|
20
|
-
|
|
21
|
-
__TypedArray-first API.__
|
|
22
|
-
Standard `Float32Array`, `Float64Array`, `Int8Array`, and `Uint8Array` work directly.
|
|
23
|
-
__DType tags for exotic storage.__
|
|
24
|
-
`f16`, `bf16`, fp8, and packed bits stay explicit.
|
|
25
|
-
__Owned and borrowed views.__
|
|
26
|
-
`Vector`, `VectorView`, and base tensor wrappers preserve dtype metadata.
|
|
27
|
-
__Portable runtime story.__
|
|
28
|
-
The same package can target native addons and WASM runtimes.
|
|
29
|
-
__No fake tensor-framework scope.__
|
|
30
|
-
This binding stays centered on the vector families it actually exports.
|
|
31
|
-
|
|
32
|
-
## Ecosystem Comparison
|
|
33
|
-
|
|
34
|
-
| Feature | NumKong | [mathjs](https://github.com/josdejong/mathjs) | [tensorflow.js](https://github.com/tensorflow/tfjs) |
|
|
35
|
-
| ---------------------------- | -------------------------------------------------------------- | --------------------------------------------- | --------------------------------------------------- |
|
|
36
|
-
| Operation families | dots, distances, binary, probability, cast, packed, symmetric | general arithmetic, matrix ops, statistics | matmul, elementwise, reductions |
|
|
37
|
-
| Precision | BFloat16 through sub-byte; automatic widening; Kahan summation | Float64 only; standard accuracy | Float32 primarily; no sub-byte; standard accuracy |
|
|
38
|
-
| Runtime SIMD dispatch | auto-selects best ISA per-thread across x86, ARM, RISC-V | none; pure JS | fixed at build time via WASM SIMD or WebGL |
|
|
39
|
-
| Packed matrix, GEMM-like | `dotsPack` + `dotsPacked`; persistent packing; amortized | `math.multiply` — no persistent packing | `tf.matMul` — no persistent packing |
|
|
40
|
-
| Symmetric kernels, SYRK-like | `dotsSymmetric`; upper triangle only; row-range partitioning | no duplicate-pair skipping | no duplicate-pair skipping |
|
|
41
|
-
| WASM fallback | yes — portable, runs in browser without native addon | yes — pure JS, no native required | yes — also WebGL/WebGPU |
|
|
42
|
-
| Bundle size | small | moderate | large |
|
|
43
|
-
|
|
44
|
-
## Installation
|
|
45
|
-
|
|
46
|
-
The package targets Node `>= 22`.
|
|
47
|
-
|
|
48
|
-
```sh
|
|
49
|
-
npm install numkong
|
|
50
|
-
yarn add numkong
|
|
51
|
-
pnpm add numkong
|
|
52
|
-
bun add numkong
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
If you build from source, the package uses `node-gyp-build` on install and TypeScript sources under `javascript/`.
|
|
56
|
-
|
|
57
|
-
## Browser and WASM
|
|
58
|
-
|
|
59
|
-
NumKong ships pre-built WASM binaries attached to each [GitHub Release](https://github.com/ashvardanian/NumKong/releases).
|
|
60
|
-
Download `numkong.js` and `numkong.wasm` and serve them from the same directory.
|
|
61
|
-
|
|
62
|
-
```html
|
|
63
|
-
<script type="module">
|
|
64
|
-
import * as numkong from "./numkong-wasm.js";
|
|
65
|
-
import NumKongModule from "./numkong.js";
|
|
66
|
-
|
|
67
|
-
const wasm = await NumKongModule();
|
|
68
|
-
numkong.initWasm(wasm);
|
|
69
|
-
|
|
70
|
-
// Same API as the native addon
|
|
71
|
-
const a = new Float32Array([1, 2, 3]);
|
|
72
|
-
const b = new Float32Array([4, 5, 6]);
|
|
73
|
-
console.log(numkong.dot(a, b));
|
|
74
|
-
</script>
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
For Node.js WASM usage without the native addon:
|
|
78
|
-
|
|
79
|
-
```js
|
|
80
|
-
import * as numkong from "numkong/wasm";
|
|
81
|
-
import NumKongModule from "./numkong.js";
|
|
82
|
-
|
|
83
|
-
const wasm = await NumKongModule();
|
|
84
|
-
numkong.initWasm(wasm);
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## Dot Products
|
|
88
|
-
|
|
89
|
-
Dot products are separate from distances because dtype tagging and low-precision storage matter more here.
|
|
90
|
-
|
|
91
|
-
```ts
|
|
92
|
-
import { dot, inner } from "numkong";
|
|
93
|
-
|
|
94
|
-
const a = new Float32Array([1, 2, 3]);
|
|
95
|
-
const b = new Float32Array([4, 5, 6]);
|
|
96
|
-
|
|
97
|
-
console.log(dot(a, b));
|
|
98
|
-
console.log(inner(a, b)); // alias for ecosystem familiarity
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
For non-native numeric layouts, pass an explicit `DType` or wrap the storage in a typed NumKong view.
|
|
102
|
-
|
|
103
|
-
## Dense Distances
|
|
104
|
-
|
|
105
|
-
Dense distance entrypoints work directly on the standard numeric `TypedArray` types.
|
|
106
|
-
|
|
107
|
-
```ts
|
|
108
|
-
import { sqeuclidean, euclidean, angular } from "numkong";
|
|
109
|
-
|
|
110
|
-
const a = new Float32Array([1, 2, 3]);
|
|
111
|
-
const b = new Float32Array([4, 5, 6]);
|
|
112
|
-
|
|
113
|
-
console.log(sqeuclidean(a, b)); // equivalent shape to a manual sum((a[i] - b[i]) ** 2)
|
|
114
|
-
console.log(euclidean(a, b));
|
|
115
|
-
console.log(angular(a, b));
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
When the storage type is one of the standard JS typed arrays, dtype inference is automatic.
|
|
119
|
-
|
|
120
|
-
## Binary Metrics
|
|
121
|
-
|
|
122
|
-
Binary metrics operate on packed storage rather than on generic boolean arrays.
|
|
123
|
-
|
|
124
|
-
```ts
|
|
125
|
-
import { toBinary, hamming, jaccard } from "numkong";
|
|
126
|
-
|
|
127
|
-
const a = toBinary(new Float32Array([1, -2, 3, -4, 5, -6, 7, -8]));
|
|
128
|
-
const b = toBinary(new Float32Array([1, 2, -3, -4, 5, 6, -7, -8]));
|
|
129
|
-
|
|
130
|
-
console.log(hamming(a, b));
|
|
131
|
-
console.log(jaccard(a, b));
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
That is a better model for sign-quantized embeddings and semantic hashes than looping over JS booleans.
|
|
135
|
-
|
|
136
|
-
## Probability Metrics
|
|
137
|
-
|
|
138
|
-
```ts
|
|
139
|
-
import { kullbackleibler, jensenshannon } from "numkong";
|
|
140
|
-
|
|
141
|
-
const p = new Float32Array([0.2, 0.3, 0.5]);
|
|
142
|
-
const q = new Float32Array([0.1, 0.3, 0.6]);
|
|
143
|
-
|
|
144
|
-
console.log(kullbackleibler(p, q));
|
|
145
|
-
console.log(jensenshannon(p, q));
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
These are direct divergence kernels, not scalar JS loops hidden behind a helper.
|
|
149
|
-
|
|
150
|
-
## DType Tags and Low-Precision Arrays
|
|
151
|
-
|
|
152
|
-
JavaScript has no built-in `f16`, `bf16`, fp8, or packed-bit numeric model.
|
|
153
|
-
NumKong handles that with explicit dtype tags and wrapper arrays.
|
|
154
|
-
|
|
155
|
-
The supported low-precision types and their bit layouts are:
|
|
156
|
-
|
|
157
|
-
- `Float16Array`: 1 sign + 5 exponent + 10 mantissa bits, 2 bytes per element, range ±65504, supports Inf and NaN
|
|
158
|
-
- `BFloat16Array`: 1 sign + 8 exponent + 7 mantissa bits, 2 bytes per element, full `f32` dynamic range, supports Inf and NaN
|
|
159
|
-
- `E4M3Array`: 1 sign + 4 exponent + 3 mantissa bits, 1 byte per element, range ±448, no Inf, NaN is 0x7F only
|
|
160
|
-
- `E5M2Array`: 1 sign + 5 exponent + 2 mantissa bits, 1 byte per element, range ±57344, supports Inf and NaN
|
|
161
|
-
- `BinaryArray`: packed bits in bytes, 8 elements per byte
|
|
162
|
-
|
|
163
|
-
Use `.byteLength` for the exact payload size.
|
|
164
|
-
|
|
165
|
-
```ts
|
|
166
|
-
import { Float16Array, E4M3Array, DType, dot, angular } from "numkong";
|
|
167
|
-
|
|
168
|
-
const a16 = new Float16Array([1, 2, 3]);
|
|
169
|
-
const b16 = new Float16Array([4, 5, 6]);
|
|
170
|
-
console.log(dot(a16, b16, DType.F16));
|
|
171
|
-
console.log(a16.byteLength);
|
|
172
|
-
|
|
173
|
-
const a8 = new E4M3Array([1, 2, 3]);
|
|
174
|
-
const b8 = new E4M3Array([4, 5, 6]);
|
|
175
|
-
console.log(angular(a8, b8, DType.E4M3));
|
|
176
|
-
console.log(a8.byteLength);
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
If the underlying storage is a raw `Uint16Array` or `Uint8Array`, JS itself cannot know whether those bytes mean integers, `f16`, `bf16`, mini-floats, or packed bits.
|
|
180
|
-
That is exactly when the `DType` tag becomes mandatory.
|
|
181
|
-
You can also pass it to `cast` to convert many values between all supported types:
|
|
182
|
-
|
|
183
|
-
```ts
|
|
184
|
-
numkong.cast(f32Source, "f32", bf16Dest, "bf16");
|
|
185
|
-
numkong.cast(f32Source, "f32", bf16Dest, DType.E4M3);
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
## Vector Views and Owned Buffers
|
|
189
|
-
|
|
190
|
-
The wrapper hierarchy exists to keep dtype and ownership explicit across addon and WASM boundaries.
|
|
191
|
-
|
|
192
|
-
- `TensorBase` carries `buffer`, `byteOffset`, and `dtype`
|
|
193
|
-
- `VectorBase` adds rank-1 semantics
|
|
194
|
-
- `VectorView` is a zero-copy borrowed wrapper over existing memory
|
|
195
|
-
- `Vector` owns its `ArrayBuffer`
|
|
196
|
-
|
|
197
|
-
```ts
|
|
198
|
-
import { VectorView, Vector, DType, dot } from "numkong";
|
|
199
|
-
|
|
200
|
-
const raw = new Uint16Array([0x3c00, 0x4000, 0x4200]); // f16 payload, not uint16 values
|
|
201
|
-
const view = VectorView.from(raw, DType.F16);
|
|
202
|
-
|
|
203
|
-
const owned = new Vector(3, DType.F32);
|
|
204
|
-
owned.toTypedArray().set(new Float32Array([4, 5, 6]));
|
|
205
|
-
|
|
206
|
-
console.log(dot(view, view));
|
|
207
|
-
console.log(dot(owned, owned));
|
|
208
|
-
console.log(owned.byteLength);
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
Use `VectorView` when the bytes already live somewhere else.
|
|
212
|
-
Use `Vector` when NumKong should own the storage.
|
|
213
|
-
|
|
214
|
-
## Capabilities and Runtime Selection
|
|
215
|
-
|
|
216
|
-
Capability detection is explicit:
|
|
217
|
-
|
|
218
|
-
```ts
|
|
219
|
-
import { Capability, getCapabilities, hasCapability } from "numkong";
|
|
220
|
-
|
|
221
|
-
const caps = getCapabilities();
|
|
222
|
-
|
|
223
|
-
console.log(caps);
|
|
224
|
-
console.log(hasCapability(Capability.HASWELL));
|
|
225
|
-
console.log(hasCapability(Capability.NEON));
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
The exact bitmask depends on whether you are running the native addon or a WASM runtime.
|
|
229
|
-
|
|
230
|
-
There is no `configure_thread` call in the JS binding.
|
|
231
|
-
Thread configuration is managed internally by the native addon or WASM runtime.
|
|
232
|
-
|
|
233
|
-
## Native Addon and WASM Runtimes
|
|
234
|
-
|
|
235
|
-
The top-level package is native-first.
|
|
236
|
-
It loads the compiled addon through `node-gyp-build`.
|
|
237
|
-
|
|
238
|
-
The repository also ships WASM wrappers.
|
|
239
|
-
Those are useful for portable or sandboxed environments.
|
|
240
|
-
They should not be described as feature-complete replacements for the native-heavy SDKs.
|
|
241
|
-
|
|
242
|
-
Practical guidance:
|
|
243
|
-
|
|
244
|
-
- Use the native addon for the lowest host-call latency.
|
|
245
|
-
- Use the WASM path when portability matters more than absolute latency.
|
|
246
|
-
- Keep your expectations scoped to the vector and matrix-oriented API that this binding actually exports.
|