@danielsimonjr/mathts-parallel 0.3.4 → 0.5.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 (2) hide show
  1. package/dist/index.js +10 -12
  2. package/package.json +3 -2
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/ComputePool.ts
2
+ import { pairwiseSum, norm2, pairwiseDot, scaledDistance } from "@danielsimonjr/mathts-core";
2
3
  import {
3
4
  MathWorkerPool,
4
5
  Transfer
@@ -365,6 +366,11 @@ var DEFAULT_THRESHOLD_BY_OP = {
365
366
  // to the global threshold; benchmarked memory-bound (0.09–1.19×, occasional noise
366
367
  // spikes but no persistent win) → 'never'.
367
368
  norm: "never",
369
+ // ACCURACY NOTE: `dot`/`distance` staying 'never' is also what keeps them stable. The
370
+ // sequential fallbacks use core's pairwiseDot / scaledDistance, but the worker kernels
371
+ // (dotChunk / distanceChunk in workerpool) still accumulate naively. Do NOT tune these off
372
+ // 'never' without giving those kernels the same pairwise/scaled accumulation first, or large
373
+ // inputs — the regime where O(n)·ε is worst — would silently revert to naive accuracy.
368
374
  dot: "never",
369
375
  // Added 2026-07-02 (WS-2): `min`/`max` are now `OpName`s (added to the union) so
370
376
  // they're tunable. Same memory-bound reduction profile as sum/mean/norm above →
@@ -614,9 +620,7 @@ var ComputePool = class {
614
620
  */
615
621
  async sum(data) {
616
622
  if (!this.shouldParallelize(data.length, "sum")) {
617
- let s = 0;
618
- for (let i = 0; i < data.length; i++) s += data[i];
619
- return this.seqResult(s);
623
+ return this.seqResult(pairwiseSum(data));
620
624
  }
621
625
  return toParallelResult(await this.workerPool.sum(data));
622
626
  }
@@ -637,9 +641,7 @@ var ComputePool = class {
637
641
  async dot(a, b) {
638
642
  if (!this.shouldParallelize(a.length, "dot")) {
639
643
  if (a.length !== b.length) throw new Error("dot: vectors must have the same length");
640
- let s = 0;
641
- for (let i = 0; i < a.length; i++) s += a[i] * b[i];
642
- return this.seqResult(s);
644
+ return this.seqResult(pairwiseDot(a, b));
643
645
  }
644
646
  return toParallelResult(await this.workerPool.dot(a, b));
645
647
  }
@@ -755,9 +757,7 @@ var ComputePool = class {
755
757
  */
756
758
  async norm(data) {
757
759
  if (!this.shouldParallelize(data.length, "norm")) {
758
- let s = 0;
759
- for (let i = 0; i < data.length; i++) s += data[i] * data[i];
760
- return this.seqResult(Math.sqrt(s));
760
+ return this.seqResult(norm2(data));
761
761
  }
762
762
  return toParallelResult(await this.workerPool.norm(data));
763
763
  }
@@ -767,9 +767,7 @@ var ComputePool = class {
767
767
  async distance(a, b) {
768
768
  if (!this.shouldParallelize(a.length, "distance")) {
769
769
  if (a.length !== b.length) throw new Error("distance: vectors must have the same length");
770
- let s = 0;
771
- for (let i = 0; i < a.length; i++) s += (a[i] - b[i]) ** 2;
772
- return this.seqResult(Math.sqrt(s));
770
+ return this.seqResult(scaledDistance(a, b));
773
771
  }
774
772
  return toParallelResult(await this.workerPool.distance(a, b));
775
773
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielsimonjr/mathts-parallel",
3
- "version": "0.3.4",
3
+ "version": "0.5.0",
4
4
  "description": "WebWorker parallelization for MathTS computations",
5
5
  "author": "Daniel Simon Jr.",
6
6
  "license": "MIT",
@@ -31,7 +31,8 @@
31
31
  "build:prod": "tsup src/index.ts src/matrix.worker.ts --format esm --dts --clean --minify --treeshake"
32
32
  },
33
33
  "dependencies": {
34
- "@danielsimonjr/mathts-workerpool": "^0.2.1"
34
+ "@danielsimonjr/mathts-workerpool": "^0.2.1",
35
+ "@danielsimonjr/mathts-core": "^0.8.0"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@types/node": "^25.5.2",