@danielsimonjr/mathts-functions 0.17.1 → 0.18.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/dist/gpu/elementwise-gpu.d.ts +34 -28
- package/dist/gpu/elementwise-gpu.d.ts.map +1 -1
- package/dist/index.js +119 -75
- package/dist/typed/fused.d.ts +13 -4
- package/dist/typed/fused.d.ts.map +1 -1
- package/dist/typed/index.d.ts +1 -1
- package/dist/typed/index.d.ts.map +1 -1
- package/dist/utils/map.d.ts +18 -0
- package/dist/utils/map.d.ts.map +1 -1
- package/package.json +4 -3
- package/types/assemblyscript.d.ts +101 -0
- package/types/index.d.ts +7801 -0
- package/types/modules.d.ts +19 -0
|
@@ -2,52 +2,58 @@
|
|
|
2
2
|
* WebGPU fused element-wise chain.
|
|
3
3
|
*
|
|
4
4
|
* Why a *chain* and not a single op: a lone element-wise op on the GPU is pure
|
|
5
|
-
* transfer tax — upload n floats, do one flop each, read n floats back.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* is amortized across the whole chain.
|
|
5
|
+
* transfer tax — upload n floats, do one flop each, read n floats back. A
|
|
6
|
+
* **fused chain** uploads once, runs every op on-device by ping-ponging two
|
|
7
|
+
* storage buffers, and reads back once, so the transfer is amortized across the
|
|
8
|
+
* whole chain.
|
|
10
9
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
10
|
+
* **Read this before reaching for the GPU:** for element-wise work the GPU is
|
|
11
|
+
* *slower* than WASM (~1.9×, measured) *and* less precise (f32 vs f64). It earns
|
|
12
|
+
* its place only where WASM cannot load. `fuseUnaryChainAsync` therefore tries
|
|
13
|
+
* WASM first. The GPU wins decisively on **compute-bound** work — see
|
|
14
|
+
* `gpuMatmul`, where O(n³) arithmetic amortizes the O(n²) transfer.
|
|
16
15
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Contract (mirrors the WASM `elementwiseChainDispatch`): a **never-throw**
|
|
17
|
+
* best-effort fast path. It returns `null` — never rejects — whenever the GPU is
|
|
18
|
+
* unavailable, not opted in, the input is too small, or the chain contains an op
|
|
19
|
+
* with no GPU kernel. The caller then falls through to the CPU tiers.
|
|
19
20
|
*/
|
|
20
21
|
import { type GPUContextOptions } from '@danielsimonjr/mathts-gpu';
|
|
21
|
-
/**
|
|
22
|
-
* WGSL expressions for each supported op, as a function of `x`.
|
|
23
|
-
*
|
|
24
|
-
* Deliberately a SUBSET of the WASM op set. `erfc` is absent: WGSL has no
|
|
25
|
-
* `erfc` builtin, and hand-rolling a polynomial approximation would silently
|
|
26
|
-
* change the accuracy contract. A chain containing an unsupported op returns
|
|
27
|
-
* `null` and falls back, rather than quietly computing something else.
|
|
28
|
-
*/
|
|
29
22
|
declare const WGSL_OP_BODY: {
|
|
30
23
|
readonly abs: "return abs(x);";
|
|
31
24
|
readonly sin: "return sin(x);";
|
|
32
25
|
readonly cos: "return cos(x);";
|
|
33
26
|
readonly tan: "return tan(x);";
|
|
34
27
|
readonly exp: "return exp(x);";
|
|
35
|
-
readonly log: "return log(x);";
|
|
36
28
|
readonly atan: "return atan(x);";
|
|
37
29
|
readonly sinh: "return sinh(x);";
|
|
38
30
|
readonly tanh: "return tanh(x);";
|
|
39
|
-
readonly
|
|
40
|
-
readonly log2: "return
|
|
41
|
-
readonly log10: "return
|
|
42
|
-
readonly
|
|
43
|
-
readonly
|
|
44
|
-
readonly
|
|
31
|
+
readonly log: "return safe_log(x);";
|
|
32
|
+
readonly log2: "return safe_log(x) * 1.4426950408889634;";
|
|
33
|
+
readonly log10: "return safe_log(x) * 0.4342944819032518;";
|
|
34
|
+
readonly atanh: "return safe_atanh(x);";
|
|
35
|
+
readonly sec: "return safe_recip(cos(x));";
|
|
36
|
+
readonly csc: "return safe_recip(sin(x));";
|
|
37
|
+
readonly cot: "return safe_recip(tan(x));";
|
|
45
38
|
};
|
|
46
39
|
/** Ops that have a GPU kernel. A chain outside this set falls back. */
|
|
47
40
|
export type GpuElementwiseOp = keyof typeof WGSL_OP_BODY;
|
|
48
41
|
export declare const GPU_ELEMENTWISE_OPS: GpuElementwiseOp[];
|
|
49
42
|
/** Whether every op in the chain has a GPU kernel. */
|
|
50
43
|
export declare function isGpuChainSupported(ops: readonly string[]): ops is readonly GpuElementwiseOp[];
|
|
44
|
+
/** Drop the cached shaders/buffers (device loss, or between tests). */
|
|
45
|
+
export declare function resetGpuElementwise(): void;
|
|
46
|
+
/** Options for a GPU element-wise dispatch. */
|
|
47
|
+
export interface GpuChainOptions extends GPUContextOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Per-call override of the global `enableGpu()` flag.
|
|
50
|
+
*
|
|
51
|
+
* The global flag is process-wide mutable state: any dependency that calls
|
|
52
|
+
* `enableGpu()` would otherwise change *your* call's behaviour. Passing `gpu`
|
|
53
|
+
* explicitly makes a call self-describing and immune to that.
|
|
54
|
+
*/
|
|
55
|
+
gpu?: boolean;
|
|
56
|
+
}
|
|
51
57
|
/**
|
|
52
58
|
* Run a fused element-wise chain on the GPU.
|
|
53
59
|
*
|
|
@@ -55,6 +61,6 @@ export declare function isGpuChainSupported(ops: readonly string[]): ops is read
|
|
|
55
61
|
* @param xs - input samples
|
|
56
62
|
* @returns the f32 results, or `null` to signal "fall back to another tier"
|
|
57
63
|
*/
|
|
58
|
-
export declare function elementwiseChainGpuDispatch(ops: readonly string[], xs: Float64Array | Float32Array, options?:
|
|
64
|
+
export declare function elementwiseChainGpuDispatch(ops: readonly string[], xs: Float64Array | Float32Array, options?: GpuChainOptions): Promise<Float32Array | null>;
|
|
59
65
|
export {};
|
|
60
66
|
//# sourceMappingURL=elementwise-gpu.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elementwise-gpu.d.ts","sourceRoot":"","sources":["../../src/gpu/elementwise-gpu.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"elementwise-gpu.d.ts","sourceRoot":"","sources":["../../src/gpu/elementwise-gpu.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAOL,KAAK,iBAAiB,EACvB,MAAM,2BAA2B,CAAC;AA+CnC,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;CAgCR,CAAC;AAEX,uEAAuE;AACvE,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,YAAY,CAAC;AAEzD,eAAO,MAAM,mBAAmB,EAAgC,gBAAgB,EAAE,CAAC;AAEnF,sDAAsD;AACtD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,GAAG,IAAI,SAAS,gBAAgB,EAAE,CAE9F;AAsED,uEAAuE;AACvE,wBAAgB,mBAAmB,IAAI,IAAI,CAG1C;AAED,+CAA+C;AAC/C,MAAM,WAAW,eAAgB,SAAQ,iBAAiB;IACxD;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,SAAS,MAAM,EAAE,EACtB,EAAE,EAAE,YAAY,GAAG,YAAY,EAC/B,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAuH9B"}
|
package/dist/index.js
CHANGED
|
@@ -396,6 +396,7 @@ __export(typed_exports, {
|
|
|
396
396
|
reduce: () => reduce,
|
|
397
397
|
reflectVector: () => reflectVector,
|
|
398
398
|
resample: () => resample,
|
|
399
|
+
resetGpuElementwise: () => resetGpuElementwise,
|
|
399
400
|
residue: () => residue,
|
|
400
401
|
resultant: () => resultant,
|
|
401
402
|
rightArithShift: () => rightArithShift,
|
|
@@ -7341,41 +7342,76 @@ var typedSpecial = {
|
|
|
7341
7342
|
// src/gpu/elementwise-gpu.ts
|
|
7342
7343
|
import {
|
|
7343
7344
|
getGpuDevice,
|
|
7345
|
+
getGlobalGPUContext,
|
|
7344
7346
|
isGpuEnabled,
|
|
7345
|
-
GPU_MIN_ELEMENTS
|
|
7347
|
+
GPU_MIN_ELEMENTS,
|
|
7348
|
+
ShaderManager,
|
|
7349
|
+
BufferPool
|
|
7346
7350
|
} from "@danielsimonjr/mathts-gpu";
|
|
7351
|
+
var WGSL_IEEE = `
|
|
7352
|
+
// NaN / \xB1Inf are supplied through the UNIFORM, not written as literals.
|
|
7353
|
+
//
|
|
7354
|
+
// WGSL const-folds \`bitcast<f32>(0x7fc00000u)\` even inside a function body and
|
|
7355
|
+
// then rejects the result: "value nan cannot be represented as 'f32'" \u2014 a const
|
|
7356
|
+
// expression may not BE NaN or Inf. Reading the bit pattern from \`params\` (a
|
|
7357
|
+
// runtime uniform) is not const-foldable, so the bitcast survives to runtime.
|
|
7358
|
+
// params = (n, nanBits, posInfBits, negInfBits).
|
|
7359
|
+
fn nan_f32() -> f32 { return bitcast<f32>(params.y); }
|
|
7360
|
+
fn pos_inf() -> f32 { return bitcast<f32>(params.z); }
|
|
7361
|
+
fn neg_inf() -> f32 { return bitcast<f32>(params.w); }
|
|
7362
|
+
|
|
7363
|
+
fn safe_log(x: f32) -> f32 {
|
|
7364
|
+
if (x < 0.0) { return nan_f32(); }
|
|
7365
|
+
if (x == 0.0) { return neg_inf(); }
|
|
7366
|
+
return log(x);
|
|
7367
|
+
}
|
|
7368
|
+
fn safe_atanh(x: f32) -> f32 {
|
|
7369
|
+
if (x > 1.0 || x < -1.0) { return nan_f32(); }
|
|
7370
|
+
if (x == 1.0) { return pos_inf(); }
|
|
7371
|
+
if (x == -1.0) { return neg_inf(); }
|
|
7372
|
+
return atanh(x);
|
|
7373
|
+
}
|
|
7374
|
+
// 1/d with IEEE division-by-zero semantics (JS: 1/0 = +Inf, 1/-0 = -Inf).
|
|
7375
|
+
fn safe_recip(d: f32) -> f32 {
|
|
7376
|
+
if (d == 0.0) {
|
|
7377
|
+
// Distinguish +0 from -0 by its sign bit, as IEEE division does.
|
|
7378
|
+
if ((bitcast<u32>(d) & 0x80000000u) != 0u) { return neg_inf(); }
|
|
7379
|
+
return pos_inf();
|
|
7380
|
+
}
|
|
7381
|
+
return 1.0 / d;
|
|
7382
|
+
}
|
|
7383
|
+
`;
|
|
7347
7384
|
var WGSL_OP_BODY = {
|
|
7348
7385
|
abs: "return abs(x);",
|
|
7349
7386
|
sin: "return sin(x);",
|
|
7350
7387
|
cos: "return cos(x);",
|
|
7351
7388
|
tan: "return tan(x);",
|
|
7352
7389
|
exp: "return exp(x);",
|
|
7353
|
-
log: "return log(x);",
|
|
7354
7390
|
atan: "return atan(x);",
|
|
7355
7391
|
sinh: "return sinh(x);",
|
|
7356
7392
|
tanh: "return tanh(x);",
|
|
7357
|
-
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
|
|
7362
|
-
//
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
|
|
7366
|
-
|
|
7393
|
+
// Domain-guarded: WGSL says indeterminate outside the domain; JS does not.
|
|
7394
|
+
log: "return safe_log(x);",
|
|
7395
|
+
log2: "return safe_log(x) * 1.4426950408889634;",
|
|
7396
|
+
// ln(x) / ln(2)
|
|
7397
|
+
log10: "return safe_log(x) * 0.4342944819032518;",
|
|
7398
|
+
// ln(x) / ln(10)
|
|
7399
|
+
atanh: "return safe_atanh(x);",
|
|
7400
|
+
sec: "return safe_recip(cos(x));",
|
|
7401
|
+
csc: "return safe_recip(sin(x));",
|
|
7402
|
+
cot: "return safe_recip(tan(x));"
|
|
7403
|
+
// NOTE — `expm1`, `log1p` and `erfc` are DELIBERATELY ABSENT.
|
|
7367
7404
|
//
|
|
7368
|
-
//
|
|
7369
|
-
//
|
|
7370
|
-
//
|
|
7371
|
-
//
|
|
7372
|
-
//
|
|
7405
|
+
// WGSL has no builtin for any of them. For expm1/log1p the naive identities
|
|
7406
|
+
// (`exp(x)-1`, `log(1+x)`) are catastrophically wrong near zero in f32
|
|
7407
|
+
// (`1.0 + 1e-8` rounds to exactly 1.0f, so `log(1+x)` returns 0 where the true
|
|
7408
|
+
// value is 1e-8 — 100% relative error), and the standard Kahan-compensated
|
|
7409
|
+
// forms were implemented and MEASURED on real hardware: still 38% (expm1) and
|
|
7410
|
+
// 62% (log1p) max relative error, because the compensation needs an accurate
|
|
7411
|
+
// `log()` near 1.0 and the GPU's fast-math `log()` is not.
|
|
7373
7412
|
//
|
|
7374
|
-
// An f32 fast path
|
|
7375
|
-
//
|
|
7376
|
-
sec: "return 1.0 / cos(x);",
|
|
7377
|
-
csc: "return 1.0 / sin(x);",
|
|
7378
|
-
cot: "return 1.0 / tan(x);"
|
|
7413
|
+
// An f32 fast path may be less precise. It may not be WRONG. Chains containing
|
|
7414
|
+
// these fall back to the exact WASM/JS tiers.
|
|
7379
7415
|
};
|
|
7380
7416
|
var GPU_ELEMENTWISE_OPS = Object.keys(WGSL_OP_BODY);
|
|
7381
7417
|
function isGpuChainSupported(ops) {
|
|
@@ -7386,6 +7422,9 @@ function wgslFor(op) {
|
|
|
7386
7422
|
return `
|
|
7387
7423
|
@group(0) @binding(0) var<storage, read> inp: array<f32>;
|
|
7388
7424
|
@group(0) @binding(1) var<storage, read_write> outp: array<f32>;
|
|
7425
|
+
@group(0) @binding(2) var<uniform> params: vec4<u32>; // n, nanBits, +infBits, -infBits
|
|
7426
|
+
|
|
7427
|
+
${WGSL_IEEE}
|
|
7389
7428
|
|
|
7390
7429
|
fn apply(x: f32) -> f32 {
|
|
7391
7430
|
${WGSL_OP_BODY[op]}
|
|
@@ -7394,80 +7433,72 @@ function wgslFor(op) {
|
|
|
7394
7433
|
@compute @workgroup_size(${WORKGROUP_SIZE})
|
|
7395
7434
|
fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
7396
7435
|
let i = gid.x;
|
|
7397
|
-
if (i >=
|
|
7436
|
+
if (i >= params.x) { return; }
|
|
7398
7437
|
outp[i] = apply(inp[i]);
|
|
7399
7438
|
}
|
|
7400
7439
|
`;
|
|
7401
7440
|
}
|
|
7402
|
-
var
|
|
7403
|
-
function
|
|
7404
|
-
|
|
7405
|
-
if (!
|
|
7406
|
-
|
|
7407
|
-
|
|
7408
|
-
|
|
7409
|
-
const
|
|
7410
|
-
|
|
7411
|
-
|
|
7412
|
-
|
|
7413
|
-
|
|
7414
|
-
|
|
7415
|
-
|
|
7416
|
-
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
byOp.set(op, pipeline);
|
|
7420
|
-
return pipeline;
|
|
7441
|
+
var resources = null;
|
|
7442
|
+
async function getResources(options) {
|
|
7443
|
+
const device = await getGpuDevice(options);
|
|
7444
|
+
if (!device) return null;
|
|
7445
|
+
if (resources && resources.device === device) return resources;
|
|
7446
|
+
const ctx = getGlobalGPUContext();
|
|
7447
|
+
const shaders = new ShaderManager(ctx);
|
|
7448
|
+
for (const op of GPU_ELEMENTWISE_OPS) {
|
|
7449
|
+
shaders.registerShader(op, wgslFor(op));
|
|
7450
|
+
}
|
|
7451
|
+
shaders.precompileRegistered();
|
|
7452
|
+
resources = { device, shaders, pool: new BufferPool(ctx) };
|
|
7453
|
+
return resources;
|
|
7454
|
+
}
|
|
7455
|
+
function resetGpuElementwise() {
|
|
7456
|
+
resources?.pool.destroy();
|
|
7457
|
+
resources = null;
|
|
7421
7458
|
}
|
|
7422
7459
|
async function elementwiseChainGpuDispatch(ops, xs, options) {
|
|
7423
7460
|
const n = xs.length;
|
|
7424
|
-
|
|
7461
|
+
const enabled = options?.gpu ?? isGpuEnabled();
|
|
7462
|
+
if (!enabled) return null;
|
|
7425
7463
|
if (ops.length === 0) return null;
|
|
7426
7464
|
if (n < GPU_MIN_ELEMENTS) return null;
|
|
7427
7465
|
if (!isGpuChainSupported(ops)) return null;
|
|
7428
7466
|
const bytes = n * 4;
|
|
7429
7467
|
const workgroups = Math.ceil(n / WORKGROUP_SIZE);
|
|
7468
|
+
let res;
|
|
7430
7469
|
let bufA;
|
|
7431
7470
|
let bufB;
|
|
7432
7471
|
let staging;
|
|
7472
|
+
let params;
|
|
7433
7473
|
let scopePopped = false;
|
|
7434
|
-
let device;
|
|
7435
7474
|
try {
|
|
7436
|
-
const
|
|
7437
|
-
if (!
|
|
7438
|
-
|
|
7475
|
+
const r = await getResources(options);
|
|
7476
|
+
if (!r) return null;
|
|
7477
|
+
res = r;
|
|
7478
|
+
const { device, shaders, pool } = r;
|
|
7439
7479
|
const limits = device.limits;
|
|
7440
7480
|
if (workgroups > limits.maxComputeWorkgroupsPerDimension) return null;
|
|
7441
7481
|
if (bytes > limits.maxStorageBufferBindingSize) return null;
|
|
7442
7482
|
if (bytes > limits.maxBufferSize) return null;
|
|
7443
7483
|
const input = xs instanceof Float32Array ? xs : Float32Array.from(xs);
|
|
7444
7484
|
device.pushErrorScope("validation");
|
|
7445
|
-
bufA =
|
|
7446
|
-
|
|
7447
|
-
|
|
7448
|
-
|
|
7449
|
-
});
|
|
7450
|
-
bufB = device.createBuffer({
|
|
7451
|
-
size: bytes,
|
|
7452
|
-
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC,
|
|
7453
|
-
label: "chain-b"
|
|
7454
|
-
});
|
|
7455
|
-
staging = device.createBuffer({
|
|
7456
|
-
size: bytes,
|
|
7457
|
-
usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST,
|
|
7458
|
-
label: "chain-staging"
|
|
7459
|
-
});
|
|
7485
|
+
bufA = pool.acquireStorageBuffer(bytes, "chain-a", true, true);
|
|
7486
|
+
bufB = pool.acquireStorageBuffer(bytes, "chain-b", true, true);
|
|
7487
|
+
staging = pool.acquireStagingBuffer(bytes, "chain-staging");
|
|
7488
|
+
params = pool.acquireUniformBuffer(16, "chain-params");
|
|
7460
7489
|
device.queue.writeBuffer(bufA, 0, input);
|
|
7490
|
+
device.queue.writeBuffer(params, 0, new Uint32Array([n, 2143289344, 2139095040, 4286578688]));
|
|
7461
7491
|
const encoder = device.createCommandEncoder({ label: "elementwise-chain" });
|
|
7462
7492
|
let src = bufA;
|
|
7463
7493
|
let dst2 = bufB;
|
|
7464
7494
|
for (const op of ops) {
|
|
7465
|
-
const pipeline =
|
|
7495
|
+
const pipeline = shaders.getRegisteredPipeline(op);
|
|
7466
7496
|
const bindGroup = device.createBindGroup({
|
|
7467
7497
|
layout: pipeline.getBindGroupLayout(0),
|
|
7468
7498
|
entries: [
|
|
7469
7499
|
{ binding: 0, resource: { buffer: src } },
|
|
7470
|
-
{ binding: 1, resource: { buffer: dst2 } }
|
|
7500
|
+
{ binding: 1, resource: { buffer: dst2 } },
|
|
7501
|
+
{ binding: 2, resource: { buffer: params } }
|
|
7471
7502
|
]
|
|
7472
7503
|
});
|
|
7473
7504
|
const pass = encoder.beginComputePass({ label: `chain:${op}` });
|
|
@@ -7482,22 +7513,25 @@ async function elementwiseChainGpuDispatch(ops, xs, options) {
|
|
|
7482
7513
|
const validationError = await device.popErrorScope();
|
|
7483
7514
|
scopePopped = true;
|
|
7484
7515
|
if (validationError) return null;
|
|
7485
|
-
await staging.mapAsync(GPUMapMode.READ);
|
|
7486
|
-
const out = new Float32Array(staging.getMappedRange().slice(0));
|
|
7516
|
+
await staging.mapAsync(GPUMapMode.READ, 0, bytes);
|
|
7517
|
+
const out = new Float32Array(staging.getMappedRange(0, bytes).slice(0));
|
|
7487
7518
|
staging.unmap();
|
|
7488
7519
|
return out;
|
|
7489
7520
|
} catch {
|
|
7490
7521
|
return null;
|
|
7491
7522
|
} finally {
|
|
7492
|
-
if (
|
|
7523
|
+
if (res && !scopePopped) {
|
|
7493
7524
|
try {
|
|
7494
|
-
await device.popErrorScope();
|
|
7525
|
+
await res.device.popErrorScope();
|
|
7495
7526
|
} catch {
|
|
7496
7527
|
}
|
|
7497
7528
|
}
|
|
7498
|
-
|
|
7499
|
-
|
|
7500
|
-
|
|
7529
|
+
if (res) {
|
|
7530
|
+
if (bufA) res.pool.release(bufA);
|
|
7531
|
+
if (bufB) res.pool.release(bufB);
|
|
7532
|
+
if (staging) res.pool.release(staging);
|
|
7533
|
+
if (params) res.pool.release(params);
|
|
7534
|
+
}
|
|
7501
7535
|
}
|
|
7502
7536
|
}
|
|
7503
7537
|
|
|
@@ -7535,11 +7569,11 @@ function jsChain(ops, xs) {
|
|
|
7535
7569
|
}
|
|
7536
7570
|
return out;
|
|
7537
7571
|
}
|
|
7538
|
-
async function fuseUnaryChainAsync(ops, xs) {
|
|
7572
|
+
async function fuseUnaryChainAsync(ops, xs, options) {
|
|
7539
7573
|
const wasm = elementwiseChainDispatch(ops, xs);
|
|
7540
7574
|
if (wasm) return wasm;
|
|
7541
|
-
const gpu = await elementwiseChainGpuDispatch(ops, xs);
|
|
7542
|
-
if (gpu) return gpu;
|
|
7575
|
+
const gpu = await elementwiseChainGpuDispatch(ops, xs, options);
|
|
7576
|
+
if (gpu) return Float64Array.from(gpu);
|
|
7543
7577
|
return jsChain(ops, xs);
|
|
7544
7578
|
}
|
|
7545
7579
|
|
|
@@ -30739,7 +30773,16 @@ var ObjectWrappingMap = class {
|
|
|
30739
30773
|
[Symbol.toStringTag] = "ObjectWrappingMap";
|
|
30740
30774
|
constructor(object) {
|
|
30741
30775
|
this.wrappedObject = object;
|
|
30742
|
-
|
|
30776
|
+
}
|
|
30777
|
+
/**
|
|
30778
|
+
* Declared as a real method rather than assigned in the constructor through a
|
|
30779
|
+
* cast. The old form satisfied the runtime but never appeared in the emitted
|
|
30780
|
+
* type, so `implements Map<K, V>` was a lie that only surfaced downstream:
|
|
30781
|
+
* consumers compiling with `skipLibCheck: false` got TS2420 ("incorrectly
|
|
30782
|
+
* implements interface 'Map'... '[Symbol.iterator]' is missing").
|
|
30783
|
+
*/
|
|
30784
|
+
[Symbol.iterator]() {
|
|
30785
|
+
return this.entries();
|
|
30743
30786
|
}
|
|
30744
30787
|
// @ts-expect-error: Implementation is compatible but TS can't infer it
|
|
30745
30788
|
keys() {
|
|
@@ -45584,6 +45627,7 @@ export {
|
|
|
45584
45627
|
reflectVector,
|
|
45585
45628
|
replacer,
|
|
45586
45629
|
resample,
|
|
45630
|
+
resetGpuElementwise,
|
|
45587
45631
|
reshape2 as reshape,
|
|
45588
45632
|
residue,
|
|
45589
45633
|
resize2 as resize,
|
package/dist/typed/fused.d.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* array is below threshold, so the result is always correct.
|
|
14
14
|
*/
|
|
15
15
|
import { type WasmElementwiseOp } from '../wasm/elementwise/wasm-bridge.js';
|
|
16
|
+
import { type GpuChainOptions } from '../gpu/elementwise-gpu.js';
|
|
16
17
|
/**
|
|
17
18
|
* Apply `ops` left-to-right over `xs` (i.e. `ops[last](…ops[0](x))`), fused in
|
|
18
19
|
* WASM when possible. Returns a new `Float64Array`; never mutates `xs`.
|
|
@@ -51,9 +52,17 @@ export declare function fuseUnaryChain(ops: WasmElementwiseOp[], xs: Float64Arra
|
|
|
51
52
|
* (The GPU *does* win decisively for compute-bound work like a large matmul —
|
|
52
53
|
* see `gpuMatmul`. This ordering is specific to memory-bound element-wise work.)
|
|
53
54
|
*
|
|
54
|
-
* **Precision
|
|
55
|
-
* (~7 significant digits)
|
|
56
|
-
*
|
|
55
|
+
* **Precision.** Always returns a `Float64Array`. When the GPU tier runs, the
|
|
56
|
+
* *values* carry f32 precision (~7 significant digits) even though the container
|
|
57
|
+
* is f64 — the GPU cannot compute in f64 at all.
|
|
58
|
+
*
|
|
59
|
+
* It previously returned `Float64Array | Float32Array` to encode which path ran.
|
|
60
|
+
* That union was a footgun: `.map` / `.filter` / `.set` on it are TS2349 errors,
|
|
61
|
+
* so **every** caller had to narrow with `instanceof` before touching the result,
|
|
62
|
+
* and `new Float64Array(r.buffer)` silently produced garbage when the f32 branch
|
|
63
|
+
* hit. A narrowing tax on 100% of callers, for a branch most never take, is a bad
|
|
64
|
+
* trade. Callers who specifically want the raw f32 buffer can call
|
|
65
|
+
* `elementwiseChainGpuDispatch` directly — it is exported for exactly that.
|
|
57
66
|
*/
|
|
58
|
-
export declare function fuseUnaryChainAsync(ops: WasmElementwiseOp[], xs: Float64Array): Promise<Float64Array
|
|
67
|
+
export declare function fuseUnaryChainAsync(ops: WasmElementwiseOp[], xs: Float64Array, options?: GpuChainOptions): Promise<Float64Array>;
|
|
59
68
|
//# sourceMappingURL=fused.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fused.d.ts","sourceRoot":"","sources":["../../src/typed/fused.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"fused.d.ts","sourceRoot":"","sources":["../../src/typed/fused.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAA+B,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAyB9F;;;GAGG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,iBAAiB,EAAE,EAAE,EAAE,EAAE,YAAY,GAAG,YAAY,CAIvF;AAYD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,iBAAiB,EAAE,EACxB,EAAE,EAAE,YAAY,EAChB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,YAAY,CAAC,CAUvB"}
|
package/dist/typed/index.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ export * from './matrix-ops.js';
|
|
|
47
47
|
export { cond } from './matrix-ops.js';
|
|
48
48
|
export * from './gpu.js';
|
|
49
49
|
export { enableGpu, disableGpu, isGpuEnabled, GPU_MIN_ELEMENTS } from '@danielsimonjr/mathts-gpu';
|
|
50
|
-
export { elementwiseChainGpuDispatch, isGpuChainSupported, GPU_ELEMENTWISE_OPS, type GpuElementwiseOp, } from '../gpu/elementwise-gpu.js';
|
|
50
|
+
export { elementwiseChainGpuDispatch, isGpuChainSupported, resetGpuElementwise, GPU_ELEMENTWISE_OPS, type GpuElementwiseOp, type GpuChainOptions, } from '../gpu/elementwise-gpu.js';
|
|
51
51
|
export * from './relational.js';
|
|
52
52
|
export { typedRelational } from './relational.js';
|
|
53
53
|
export * from './string.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/typed/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAOH,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtD,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAK5C,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGpC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD,cAAc,eAAe,CAAC;AAG9B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,cAAc,kBAAkB,CAAC;AAGjC,cAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8B1B,CAAC"}
|
package/dist/utils/map.d.ts
CHANGED
|
@@ -6,10 +6,25 @@
|
|
|
6
6
|
* will stop using this method, as all objects will be Maps, rather than
|
|
7
7
|
* more security prone objects.
|
|
8
8
|
*/
|
|
9
|
+
/**
|
|
10
|
+
* The iterator type `Map` itself declares, derived from the installed TS lib
|
|
11
|
+
* rather than hard-coded: older libs say `IterableIterator<[K, V]>`, TS >= 5.6
|
|
12
|
+
* says `MapIterator<[K, V]>` (which additionally requires `[Symbol.dispose]`).
|
|
13
|
+
* Deriving it keeps `implements Map<K, V>` honest on every TS version.
|
|
14
|
+
*/
|
|
15
|
+
type MapEntryIterator<K, V> = ReturnType<Map<K, V>[typeof Symbol.iterator]>;
|
|
9
16
|
export declare class ObjectWrappingMap<K = string, V = unknown> implements Map<K, V> {
|
|
10
17
|
wrappedObject: Record<string, V>;
|
|
11
18
|
readonly [Symbol.toStringTag]: string;
|
|
12
19
|
constructor(object: Record<string, V>);
|
|
20
|
+
/**
|
|
21
|
+
* Declared as a real method rather than assigned in the constructor through a
|
|
22
|
+
* cast. The old form satisfied the runtime but never appeared in the emitted
|
|
23
|
+
* type, so `implements Map<K, V>` was a lie that only surfaced downstream:
|
|
24
|
+
* consumers compiling with `skipLibCheck: false` got TS2420 ("incorrectly
|
|
25
|
+
* implements interface 'Map'... '[Symbol.iterator]' is missing").
|
|
26
|
+
*/
|
|
27
|
+
[Symbol.iterator](): MapEntryIterator<K, V>;
|
|
13
28
|
keys(): IterableIterator<K>;
|
|
14
29
|
get(key: K): V | undefined;
|
|
15
30
|
set(key: K, value: V): this;
|
|
@@ -46,6 +61,8 @@ export declare class PartitionedMap<K = unknown, V = unknown> implements Map<K,
|
|
|
46
61
|
* @param bKeys - Set of keys that should be read/written to map b
|
|
47
62
|
*/
|
|
48
63
|
constructor(a: Map<K, V>, b: Map<K, V>, bKeys: Set<K>);
|
|
64
|
+
/** See the note on `ObjectWrappingMap[Symbol.iterator]` — same fix. */
|
|
65
|
+
[Symbol.iterator](): MapEntryIterator<K, V>;
|
|
49
66
|
get(key: K): V | undefined;
|
|
50
67
|
set(key: K, value: V): this;
|
|
51
68
|
has(key: K): boolean;
|
|
@@ -85,4 +102,5 @@ export declare function assign<K = unknown, V = unknown>(map: Map<K, V>, ...obje
|
|
|
85
102
|
* `map.ts` — that import was the sole edge closing the `is`/`map` cycle.
|
|
86
103
|
*/
|
|
87
104
|
export declare function isObjectWrappingMap(object: unknown): object is ObjectWrappingMap;
|
|
105
|
+
export {};
|
|
88
106
|
//# sourceMappingURL=map.d.ts.map
|
package/dist/utils/map.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/utils/map.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,qBAAa,iBAAiB,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,OAAO,CAAE,YAAW,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAC1E,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACjC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,CAAuB;gBAEhD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/utils/map.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH;;;;;GAKG;AACH,KAAK,gBAAgB,CAAC,CAAC,EAAE,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;AAE5E,qBAAa,iBAAiB,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,GAAG,OAAO,CA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AAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,IAAI,GACjD,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAYX;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAC7C,GAAG,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EACd,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,GAC/D,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAgBX;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,iBAAiB,CAIhF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielsimonjr/mathts-functions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Mathematical functions for MathTS - arithmetic, algebra, trigonometry, statistics, and more",
|
|
5
5
|
"author": "Daniel Simon Jr.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"dist",
|
|
19
|
+
"types",
|
|
19
20
|
"README.md"
|
|
20
21
|
],
|
|
21
22
|
"scripts": {
|
|
@@ -35,8 +36,8 @@
|
|
|
35
36
|
"dependencies": {
|
|
36
37
|
"@danielsimonjr/mathts-core": "^0.6.0",
|
|
37
38
|
"@danielsimonjr/mathts-expression": "^0.6.0",
|
|
38
|
-
"@danielsimonjr/mathts-gpu": "^0.1.
|
|
39
|
-
"@danielsimonjr/mathts-matrix": "^0.3.
|
|
39
|
+
"@danielsimonjr/mathts-gpu": "^0.1.1",
|
|
40
|
+
"@danielsimonjr/mathts-matrix": "^0.3.2",
|
|
40
41
|
"@danielsimonjr/mathts-parallel": "^0.3.4",
|
|
41
42
|
"bignumber.js": "^9.1.2",
|
|
42
43
|
"complex.js": "^2.2.5",
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ambient type declarations for AssemblyScript builtins.
|
|
3
|
+
* These types are provided by the AssemblyScript compiler at build time
|
|
4
|
+
* but need declarations for TypeScript type-checking when WASM files
|
|
5
|
+
* are transitively included via imports from src/function/.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// AssemblyScript numeric types
|
|
9
|
+
declare type usize = number;
|
|
10
|
+
declare type i64 = number;
|
|
11
|
+
declare type u8 = number;
|
|
12
|
+
declare type u32 = number;
|
|
13
|
+
declare type f32 = number;
|
|
14
|
+
|
|
15
|
+
// f64: type alias + namespace with constants
|
|
16
|
+
declare type f64 = number;
|
|
17
|
+
declare namespace f64 {
|
|
18
|
+
const NaN: f64;
|
|
19
|
+
const POSITIVE_INFINITY: f64;
|
|
20
|
+
const NEGATIVE_INFINITY: f64;
|
|
21
|
+
const MAX_VALUE: f64;
|
|
22
|
+
const MIN_VALUE: f64;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// i32: type alias + namespace with builtins
|
|
26
|
+
declare type i32 = number;
|
|
27
|
+
declare namespace i32 {
|
|
28
|
+
function clz(value: i32): i32;
|
|
29
|
+
function ctz(value: i32): i32;
|
|
30
|
+
function rotl(value: i32, shift: i32): i32;
|
|
31
|
+
function rotr(value: i32, shift: i32): i32;
|
|
32
|
+
const MAX_VALUE: i32;
|
|
33
|
+
const MIN_VALUE: i32;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** SIMD 128-bit vector type */
|
|
37
|
+
declare type v128 = object;
|
|
38
|
+
|
|
39
|
+
/** v128 SIMD intrinsics namespace */
|
|
40
|
+
declare namespace v128 {
|
|
41
|
+
function load(ptr: usize, immOffset?: u32, immAlign?: u32): v128;
|
|
42
|
+
function store(ptr: usize, value: v128, immOffset?: u32, immAlign?: u32): void;
|
|
43
|
+
function splat<T>(value: T): v128;
|
|
44
|
+
function extract_lane<T>(vec: v128, idx: u8): T;
|
|
45
|
+
function replace_lane<T>(vec: v128, idx: u8, value: T): v128;
|
|
46
|
+
function add<T>(a: v128, b: v128): v128;
|
|
47
|
+
function sub<T>(a: v128, b: v128): v128;
|
|
48
|
+
function mul<T>(a: v128, b: v128): v128;
|
|
49
|
+
function div<T>(a: v128, b: v128): v128;
|
|
50
|
+
function neg<T>(a: v128): v128;
|
|
51
|
+
function abs<T>(a: v128): v128;
|
|
52
|
+
function sqrt<T>(a: v128): v128;
|
|
53
|
+
function min<T>(a: v128, b: v128): v128;
|
|
54
|
+
function max<T>(a: v128, b: v128): v128;
|
|
55
|
+
function and(a: v128, b: v128): v128;
|
|
56
|
+
function or(a: v128, b: v128): v128;
|
|
57
|
+
function xor(a: v128, b: v128): v128;
|
|
58
|
+
function not(a: v128): v128;
|
|
59
|
+
function shuffle<T>(a: v128, b: v128, ...lanes: u8[]): v128;
|
|
60
|
+
function swizzle(a: v128, s: v128): v128;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** f64x2 SIMD namespace (2 x f64 packed into v128) */
|
|
64
|
+
declare namespace f64x2 {
|
|
65
|
+
function splat(value: f64): v128;
|
|
66
|
+
function extract_lane(vec: v128, idx: 0 | 1): f64;
|
|
67
|
+
function replace_lane(vec: v128, idx: 0 | 1, value: f64): v128;
|
|
68
|
+
function add(a: v128, b: v128): v128;
|
|
69
|
+
function sub(a: v128, b: v128): v128;
|
|
70
|
+
function mul(a: v128, b: v128): v128;
|
|
71
|
+
function div(a: v128, b: v128): v128;
|
|
72
|
+
function neg(a: v128): v128;
|
|
73
|
+
function abs(a: v128): v128;
|
|
74
|
+
function sqrt(a: v128): v128;
|
|
75
|
+
function min(a: v128, b: v128): v128;
|
|
76
|
+
function max(a: v128, b: v128): v128;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// AssemblyScript type cast functions (e.g., f64(intValue) converts i32 to f64)
|
|
80
|
+
declare function f64(value: number): number;
|
|
81
|
+
declare function i32(value: number): number;
|
|
82
|
+
declare function i64(value: number): number;
|
|
83
|
+
declare function u32(value: number): number;
|
|
84
|
+
|
|
85
|
+
// AssemblyScript builtins
|
|
86
|
+
declare function unchecked<T>(expr: T): T;
|
|
87
|
+
declare function changetype<T>(value: unknown): T;
|
|
88
|
+
declare function isFinite<T>(value: T): boolean;
|
|
89
|
+
declare function isNaN<T>(value: T): boolean;
|
|
90
|
+
declare function sizeof<T>(): usize;
|
|
91
|
+
declare function assert<T>(value: T, message?: string): T;
|
|
92
|
+
declare function idof<T>(): u32;
|
|
93
|
+
|
|
94
|
+
// AssemblyScript memory intrinsics
|
|
95
|
+
declare function load<T>(ptr: usize, immOffset?: u32): T;
|
|
96
|
+
declare function store<T>(ptr: usize, value: T, immOffset?: u32): void;
|
|
97
|
+
|
|
98
|
+
declare namespace memory {
|
|
99
|
+
function grow(pages: i32): i32;
|
|
100
|
+
function size(): i32;
|
|
101
|
+
}
|