spear-kernels 1.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.
- package/README.md +46 -0
- package/index.cjs +1092 -0
- package/index.d.ts +35 -0
- package/index.js +1092 -0
- package/package.json +28 -0
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# spear-kernels
|
|
2
|
+
|
|
3
|
+
Every closed-form kernel discovered by the [SPEAR](https://github.com/) symbolic
|
|
4
|
+
regression engine, published as a zero-dependency, fully self-contained package.
|
|
5
|
+
Each kernel ships four interchangeable backends plus metadata:
|
|
6
|
+
|
|
7
|
+
| Field | What it is |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `precise.js` / `precise.eval` | standalone JS arrow-function (source string / compiled) |
|
|
10
|
+
| `precise.c` | CUDA C `__device__` source |
|
|
11
|
+
| `precise.py` | PyTorch source |
|
|
12
|
+
| `precise.wasmBase64` | compiled f64 WebAssembly module |
|
|
13
|
+
| `fast` | algebraic-only variant when one was discovered |
|
|
14
|
+
| `meta` | `metric`, `level`, `formulaCost`, `exactCost`, `speedupVsExact`, `vsIterative` |
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import { kernels, kernelIds } from "spear-kernels";
|
|
20
|
+
|
|
21
|
+
kernelIds; // list of all kernel ids
|
|
22
|
+
|
|
23
|
+
kernels.silu.precise.eval(2); // ~1.762 (SiLU approximant)
|
|
24
|
+
|
|
25
|
+
if (kernels.sigmoid.fast) {
|
|
26
|
+
kernels.sigmoid.fast.eval(3); // algebraic fast path
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
kernels.gaussian_cdf.meta.speedupVsExact; // metadata access
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### WebAssembly backend
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
const bytes = Uint8Array.from(atob(kernels.silu.precise.wasmBase64), (c) => c.charCodeAt(0));
|
|
36
|
+
const env = {
|
|
37
|
+
exp: Math.exp, sin: Math.sin, cos: Math.cos, atan: Math.atan,
|
|
38
|
+
log: (v) => Math.log(v > 1e-30 ? v : 1e-30),
|
|
39
|
+
};
|
|
40
|
+
const { instance } = await WebAssembly.instantiate(bytes, { env });
|
|
41
|
+
instance.exports.spear(2); // same protected-division semantics as the JS backend
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Division is **protected** exactly like the engine: denominators floored at
|
|
45
|
+
±1e-4 (sign-preserving), results clamped to ±1e4. Discovered formulas rely on
|
|
46
|
+
these rails — do not swap in bare `/`.
|