@danielsimonjr/mathts-parallel 0.4.0 → 0.5.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.
Files changed (2) hide show
  1. package/dist/index.js +8 -7
  2. package/package.json +58 -58
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/ComputePool.ts
2
- import { pairwiseSum, norm2 } from "@danielsimonjr/mathts-core";
2
+ import { pairwiseSum, norm2, pairwiseDot, scaledDistance } from "@danielsimonjr/mathts-core";
3
3
  import {
4
4
  MathWorkerPool,
5
5
  Transfer
@@ -366,6 +366,11 @@ var DEFAULT_THRESHOLD_BY_OP = {
366
366
  // to the global threshold; benchmarked memory-bound (0.09–1.19×, occasional noise
367
367
  // spikes but no persistent win) → 'never'.
368
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.
369
374
  dot: "never",
370
375
  // Added 2026-07-02 (WS-2): `min`/`max` are now `OpName`s (added to the union) so
371
376
  // they're tunable. Same memory-bound reduction profile as sum/mean/norm above →
@@ -636,9 +641,7 @@ var ComputePool = class {
636
641
  async dot(a, b) {
637
642
  if (!this.shouldParallelize(a.length, "dot")) {
638
643
  if (a.length !== b.length) throw new Error("dot: vectors must have the same length");
639
- let s = 0;
640
- for (let i = 0; i < a.length; i++) s += a[i] * b[i];
641
- return this.seqResult(s);
644
+ return this.seqResult(pairwiseDot(a, b));
642
645
  }
643
646
  return toParallelResult(await this.workerPool.dot(a, b));
644
647
  }
@@ -764,9 +767,7 @@ var ComputePool = class {
764
767
  async distance(a, b) {
765
768
  if (!this.shouldParallelize(a.length, "distance")) {
766
769
  if (a.length !== b.length) throw new Error("distance: vectors must have the same length");
767
- let s = 0;
768
- for (let i = 0; i < a.length; i++) s += (a[i] - b[i]) ** 2;
769
- return this.seqResult(Math.sqrt(s));
770
+ return this.seqResult(scaledDistance(a, b));
770
771
  }
771
772
  return toParallelResult(await this.workerPool.distance(a, b));
772
773
  }
package/package.json CHANGED
@@ -1,58 +1,58 @@
1
- {
2
- "name": "@danielsimonjr/mathts-parallel",
3
- "version": "0.4.0",
4
- "description": "WebWorker parallelization for MathTS computations",
5
- "author": "Daniel Simon Jr.",
6
- "license": "MIT",
7
- "type": "module",
8
- "main": "./dist/index.js",
9
- "module": "./dist/index.js",
10
- "types": "./dist/index.d.ts",
11
- "exports": {
12
- ".": {
13
- "import": "./dist/index.js",
14
- "types": "./dist/index.d.ts"
15
- }
16
- },
17
- "files": [
18
- "dist",
19
- "README.md"
20
- ],
21
- "scripts": {
22
- "build": "tsup src/index.ts src/matrix.worker.ts --format esm --dts --clean",
23
- "dev": "tsup src/index.ts src/matrix.worker.ts --format esm --dts --watch",
24
- "test": "vitest run",
25
- "test:watch": "vitest",
26
- "test:coverage": "vitest run --coverage",
27
- "typecheck": "tsc --noEmit",
28
- "lint": "eslint src --ext .ts",
29
- "lint:fix": "eslint src --ext .ts --fix",
30
- "clean": "rm -rf dist",
31
- "build:prod": "tsup src/index.ts src/matrix.worker.ts --format esm --dts --clean --minify --treeshake"
32
- },
33
- "dependencies": {
34
- "@danielsimonjr/mathts-workerpool": "^0.2.1",
35
- "@danielsimonjr/mathts-core": "^0.7.0"
36
- },
37
- "devDependencies": {
38
- "@types/node": "^25.5.2",
39
- "tsup": "^8.0.0",
40
- "typescript": "^5.3.0",
41
- "vitest": "^4.1.5"
42
- },
43
- "publishConfig": {
44
- "access": "public"
45
- },
46
- "repository": {
47
- "type": "git",
48
- "url": "https://github.com/danielsimonjr/mathts",
49
- "directory": "parallel"
50
- },
51
- "keywords": [
52
- "math",
53
- "typescript",
54
- "parallel",
55
- "webworker",
56
- "worker-pool"
57
- ]
58
- }
1
+ {
2
+ "name": "@danielsimonjr/mathts-parallel",
3
+ "version": "0.5.1",
4
+ "description": "WebWorker parallelization for MathTS computations",
5
+ "author": "Daniel Simon Jr.",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsup src/index.ts src/matrix.worker.ts --format esm --dts --clean",
23
+ "dev": "tsup src/index.ts src/matrix.worker.ts --format esm --dts --watch",
24
+ "test": "vitest run",
25
+ "test:watch": "vitest",
26
+ "test:coverage": "vitest run --coverage",
27
+ "typecheck": "tsc --noEmit",
28
+ "lint": "eslint src --ext .ts",
29
+ "lint:fix": "eslint src --ext .ts --fix",
30
+ "clean": "rm -rf dist",
31
+ "build:prod": "tsup src/index.ts src/matrix.worker.ts --format esm --dts --clean --minify --treeshake"
32
+ },
33
+ "dependencies": {
34
+ "@danielsimonjr/mathts-workerpool": "^0.2.1",
35
+ "@danielsimonjr/mathts-core": "^0.9.0"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^25.5.2",
39
+ "tsup": "^8.0.0",
40
+ "typescript": "^5.3.0",
41
+ "vitest": "^4.1.5"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/danielsimonjr/mathts",
49
+ "directory": "parallel"
50
+ },
51
+ "keywords": [
52
+ "math",
53
+ "typescript",
54
+ "parallel",
55
+ "webworker",
56
+ "worker-pool"
57
+ ]
58
+ }