spear-kernels 1.7.0 → 1.8.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 (4) hide show
  1. package/README.md +2 -2
  2. package/index.cjs +23 -23
  3. package/index.js +23 -23
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -42,5 +42,5 @@ instance.exports.spear(2); // same protected-division semantics as the JS backen
42
42
  ```
43
43
 
44
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 `/`.
45
+ ±1e-4 (sign-preserving), results clamped to ±1e4. Discovered formulas rely on
46
+ these rails do not swap in bare `/`.
package/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- // Auto-generated by scripts/gen-kernels-package.ts — DO NOT EDIT.
1
+ // Auto-generated by scripts/gen-kernels-package.ts DO NOT EDIT.
2
2
  'use strict';
3
3
  const kernels = {
4
4
  "silu": {
@@ -29,11 +29,11 @@ const kernels = {
29
29
  "gelu": {
30
30
  id: "gelu",
31
31
  precise: {
32
- js: "((x) => ((0.999993 * ((0.5 * x) * (1 + Math.tanh((0.797885 * (x + (0.044715 * (x) * (x) * (x)))))))) + -0.000058))",
33
- eval: ((x) => ((0.999993 * ((0.5 * x) * (1 + Math.tanh((0.797885 * (x + (0.044715 * (x) * (x) * (x)))))))) + -0.000058)),
34
- c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return ((0.999993f * ((0.5f * x) * (1f + tanhf((0.797885f * (x + (0.044715f * powf(x, 3.0f)))))))) + -0.000058f);\n}",
35
- py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return ((0.999993 * ((0.5 * x) * (1 + torch.tanh((0.797885 * (x + (0.044715 * (x ** 3)))))))) + -0.000058)",
36
- wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AgwBA2VudgR0YW5oAAEDAgEABwkBBXNwZWFyAAEKUAFOAERhU+dR8f/vP0QAAAAAAADgPyAAokQAAAAAAADwP0S4AZ8fRojpPyAARPcBSG3i5KY/IAAgACAAoqKioKIQAKCiokSQvknToGgOv6AL",
32
+ js: "((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return ((0.5 * x) * (1 + __erf((x * 0.7071067811865475)))); })",
33
+ eval: ((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return ((0.5 * x) * (1 + __erf((x * 0.7071067811865475)))); }),
34
+ c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return ((0.5f * x) * (1f + erff((x * 0.707107f))));\n}",
35
+ py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return ((0.5 * x) * (1 + torch.erf((x * 0.707107))))",
36
+ wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AgsBA2VudgNlcmYAAQMCAQAHCQEFc3BlYXIAAQopAScARAAAAAAAAOA/IACiRAAAAAAAAPA/IABEzDt/Zp6g5j+iEACgogs=",
37
37
  },
38
38
  fast: {
39
39
  js: "((x) => Math.max(0, x))",
@@ -43,11 +43,11 @@ const kernels = {
43
43
  wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AwIBAAcJAQVzcGVhcgAAChABDgAgAEQAAAAAAAAAAKUL",
44
44
  },
45
45
  meta: {
46
- metric: 3.55135869310835e-8,
46
+ metric: 1.5455587803707568e-34,
47
47
  level: 5,
48
- formulaCost: 11,
48
+ formulaCost: 5,
49
49
  exactCost: 46,
50
- speedupVsExact: 4.181818181818182,
50
+ speedupVsExact: 9.2,
51
51
  vsIterative: null,
52
52
  },
53
53
  },
@@ -919,25 +919,25 @@ const kernels = {
919
919
  "erf_prob": {
920
920
  id: "erf_prob",
921
921
  precise: {
922
- js: "((x) => (1.106774 * Math.min(1e4, Math.max(-1e4, ((x + (0.034298 * (x) * (x) * (x)))) / (((0.995 + (0.378089 * (x) * (x)))) < 1e-4 && ((0.995 + (0.378089 * (x) * (x)))) > -1e-4 ? (((0.995 + (0.378089 * (x) * (x)))) >= 0 ? 1e-4 : -1e-4) : ((0.995 + (0.378089 * (x) * (x)))))))))",
923
- eval: ((x) => (1.106774 * Math.min(1e4, Math.max(-1e4, ((x + (0.034298 * (x) * (x) * (x)))) / (((0.995 + (0.378089 * (x) * (x)))) < 1e-4 && ((0.995 + (0.378089 * (x) * (x)))) > -1e-4 ? (((0.995 + (0.378089 * (x) * (x)))) >= 0 ? 1e-4 : -1e-4) : ((0.995 + (0.378089 * (x) * (x))))))))),
924
- c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return (1.106774f * fminf(fmaxf(((x + (0.034298f * powf(x, 3.0f))) / copysignf(fmaxf(fabsf((0.995f + (0.378089f * powf(x, 2.0f)))), 1.0e-4f), (0.995f + (0.378089f * powf(x, 2.0f))))), -1.0e4f), 1.0e4f));\n}",
925
- py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return (1.106774 * ((x + (0.034298 * (x ** 3))) / (abs((0.995 + (0.378089 * (x * x)))) < 1e-4 ? 1e-4 : (0.995 + (0.378089 * (x * x))))))",
926
- wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AwIBAAcJAQVzcGVhcgAACnYBdABEeQJhp1i18T8gAEQp7KLogY+hPyAAIAAgAKKioqBE16NwPQrX7z9Ezox+NJwy2D8gACAAoqKgmUQtQxzr4jYaP6VE16NwPQrX7z9Ezox+NJwy2D8gACAAoqKgpqNEAAAAAACIw8ClRAAAAAAAiMNApKIL",
922
+ js: "((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return __erf(x); })",
923
+ eval: ((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return __erf(x); }),
924
+ c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return erff(x);\n}",
925
+ py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return torch.erf(x)",
926
+ wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AgsBA2VudgNlcmYAAQMCAQAHCQEFc3BlYXIAAQoIAQYAIAAQAAs=",
927
927
  },
928
928
  fast: {
929
- js: "((x) => Math.atan(x))",
930
- eval: ((x) => Math.atan(x)),
931
- c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return atanf(x);\n}",
932
- py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return torch.atan(x)",
933
- wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AgwBA2VudgRhdGFuAAEDAgEABwkBBXNwZWFyAAEKCAEGACAAEAAL",
929
+ js: "((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return __erf(x); })",
930
+ eval: ((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return __erf(x); }),
931
+ c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return erff(x);\n}",
932
+ py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return torch.erf(x)",
933
+ wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AgsBA2VudgNlcmYAAQMCAQAHCQEFc3BlYXIAAQoIAQYAIAAQAAs=",
934
934
  },
935
935
  meta: {
936
- metric: 0.00004650870031371604,
937
- level: 3,
938
- formulaCost: 12,
936
+ metric: 0,
937
+ level: 5,
938
+ formulaCost: 1,
939
939
  exactCost: 26,
940
- speedupVsExact: 2.1666666666666665,
940
+ speedupVsExact: 26,
941
941
  vsIterative: null,
942
942
  },
943
943
  },
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // Auto-generated by scripts/gen-kernels-package.ts — DO NOT EDIT.
1
+ // Auto-generated by scripts/gen-kernels-package.ts DO NOT EDIT.
2
2
  // Self-contained runtime: the arrow functions below ARE the kernels.
3
3
  export const kernels = {
4
4
  "silu": {
@@ -29,11 +29,11 @@ export const kernels = {
29
29
  "gelu": {
30
30
  id: "gelu",
31
31
  precise: {
32
- js: "((x) => ((0.999993 * ((0.5 * x) * (1 + Math.tanh((0.797885 * (x + (0.044715 * (x) * (x) * (x)))))))) + -0.000058))",
33
- eval: ((x) => ((0.999993 * ((0.5 * x) * (1 + Math.tanh((0.797885 * (x + (0.044715 * (x) * (x) * (x)))))))) + -0.000058)),
34
- c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return ((0.999993f * ((0.5f * x) * (1f + tanhf((0.797885f * (x + (0.044715f * powf(x, 3.0f)))))))) + -0.000058f);\n}",
35
- py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return ((0.999993 * ((0.5 * x) * (1 + torch.tanh((0.797885 * (x + (0.044715 * (x ** 3)))))))) + -0.000058)",
36
- wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AgwBA2VudgR0YW5oAAEDAgEABwkBBXNwZWFyAAEKUAFOAERhU+dR8f/vP0QAAAAAAADgPyAAokQAAAAAAADwP0S4AZ8fRojpPyAARPcBSG3i5KY/IAAgACAAoqKioKIQAKCiokSQvknToGgOv6AL",
32
+ js: "((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return ((0.5 * x) * (1 + __erf((x * 0.7071067811865475)))); })",
33
+ eval: ((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return ((0.5 * x) * (1 + __erf((x * 0.7071067811865475)))); }),
34
+ c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return ((0.5f * x) * (1f + erff((x * 0.707107f))));\n}",
35
+ py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return ((0.5 * x) * (1 + torch.erf((x * 0.707107))))",
36
+ wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AgsBA2VudgNlcmYAAQMCAQAHCQEFc3BlYXIAAQopAScARAAAAAAAAOA/IACiRAAAAAAAAPA/IABEzDt/Zp6g5j+iEACgogs=",
37
37
  },
38
38
  fast: {
39
39
  js: "((x) => Math.max(0, x))",
@@ -43,11 +43,11 @@ export const kernels = {
43
43
  wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AwIBAAcJAQVzcGVhcgAAChABDgAgAEQAAAAAAAAAAKUL",
44
44
  },
45
45
  meta: {
46
- metric: 3.55135869310835e-8,
46
+ metric: 1.5455587803707568e-34,
47
47
  level: 5,
48
- formulaCost: 11,
48
+ formulaCost: 5,
49
49
  exactCost: 46,
50
- speedupVsExact: 4.181818181818182,
50
+ speedupVsExact: 9.2,
51
51
  vsIterative: null,
52
52
  },
53
53
  },
@@ -919,25 +919,25 @@ export const kernels = {
919
919
  "erf_prob": {
920
920
  id: "erf_prob",
921
921
  precise: {
922
- js: "((x) => (1.106774 * Math.min(1e4, Math.max(-1e4, ((x + (0.034298 * (x) * (x) * (x)))) / (((0.995 + (0.378089 * (x) * (x)))) < 1e-4 && ((0.995 + (0.378089 * (x) * (x)))) > -1e-4 ? (((0.995 + (0.378089 * (x) * (x)))) >= 0 ? 1e-4 : -1e-4) : ((0.995 + (0.378089 * (x) * (x)))))))))",
923
- eval: ((x) => (1.106774 * Math.min(1e4, Math.max(-1e4, ((x + (0.034298 * (x) * (x) * (x)))) / (((0.995 + (0.378089 * (x) * (x)))) < 1e-4 && ((0.995 + (0.378089 * (x) * (x)))) > -1e-4 ? (((0.995 + (0.378089 * (x) * (x)))) >= 0 ? 1e-4 : -1e-4) : ((0.995 + (0.378089 * (x) * (x))))))))),
924
- c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return (1.106774f * fminf(fmaxf(((x + (0.034298f * powf(x, 3.0f))) / copysignf(fmaxf(fabsf((0.995f + (0.378089f * powf(x, 2.0f)))), 1.0e-4f), (0.995f + (0.378089f * powf(x, 2.0f))))), -1.0e4f), 1.0e4f));\n}",
925
- py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return (1.106774 * ((x + (0.034298 * (x ** 3))) / (abs((0.995 + (0.378089 * (x * x)))) < 1e-4 ? 1e-4 : (0.995 + (0.378089 * (x * x))))))",
926
- wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AwIBAAcJAQVzcGVhcgAACnYBdABEeQJhp1i18T8gAEQp7KLogY+hPyAAIAAgAKKioqBE16NwPQrX7z9Ezox+NJwy2D8gACAAoqKgmUQtQxzr4jYaP6VE16NwPQrX7z9Ezox+NJwy2D8gACAAoqKgpqNEAAAAAACIw8ClRAAAAAAAiMNApKIL",
922
+ js: "((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return __erf(x); })",
923
+ eval: ((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return __erf(x); }),
924
+ c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return erff(x);\n}",
925
+ py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return torch.erf(x)",
926
+ wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AgsBA2VudgNlcmYAAQMCAQAHCQEFc3BlYXIAAQoIAQYAIAAQAAs=",
927
927
  },
928
928
  fast: {
929
- js: "((x) => Math.atan(x))",
930
- eval: ((x) => Math.atan(x)),
931
- c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return atanf(x);\n}",
932
- py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return torch.atan(x)",
933
- wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AgwBA2VudgRhdGFuAAEDAgEABwkBBXNwZWFyAAEKCAEGACAAEAAL",
929
+ js: "((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return __erf(x); })",
930
+ eval: ((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return __erf(x); }),
931
+ c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return erff(x);\n}",
932
+ py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return torch.erf(x)",
933
+ wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AgsBA2VudgNlcmYAAQMCAQAHCQEFc3BlYXIAAQoIAQYAIAAQAAs=",
934
934
  },
935
935
  meta: {
936
- metric: 0.00004650870031371604,
937
- level: 3,
938
- formulaCost: 12,
936
+ metric: 0,
937
+ level: 5,
938
+ formulaCost: 1,
939
939
  exactCost: 26,
940
- speedupVsExact: 2.1666666666666665,
940
+ speedupVsExact: 26,
941
941
  vsIterative: null,
942
942
  },
943
943
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spear-kernels",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "Closed-form kernels discovered by the SPEAR symbolic regression engine, shipped as JS, CUDA C, PyTorch and WebAssembly.",
5
5
  "license": "MIT",
6
6
  "type": "module",