@danielsimonjr/mathts-tensor 0.2.2 → 0.2.4

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/index.d.ts CHANGED
@@ -78,14 +78,15 @@ declare function idx(dim: number, name?: string, opts?: Omit<IndexOpts, 'name'>)
78
78
 
79
79
  /**
80
80
  * Tensor — rank-N, Float64Array-backed, row-major dense tensor. The
81
- * compute primitive behind @danielsimonjr/mathts-tensor. Construction +
82
- * elementwise here; einsum / matMul / transpose / reshape in the same
83
- * file, added by the next task.
84
- *
85
- * Naive O(n) algorithms — a correctness baseline. Mirrors the storage
86
- * pattern of DenseMatrix (Float64Array, row-major) but generalised to
87
- * arbitrary rank, filling the `Matrix<T>` base class's documented
88
- * "generic template for future rank-N support".
81
+ * compute primitive behind @danielsimonjr/mathts-tensor. Construction,
82
+ * elementwise, einsum, matMul, transpose, reshape live here.
83
+ *
84
+ * Element-wise and data-movement ops are straightforward O(n) loops (a
85
+ * correctness baseline). Heavy ops delegate to the standard packages rather
86
+ * than reinventing them: `matMul` uses matrix's backend-selected multiply
87
+ * (SIMD-WASM for large inputs), and the decompositions (in `operations/`)
88
+ * route through matrix's `svd`/`eig`/`lu`/`qr`/`cholesky`. Storage mirrors
89
+ * DenseMatrix (Float64Array, row-major), generalised to arbitrary rank.
89
90
  */
90
91
 
91
92
  type NestedArray = number | NestedArray[];
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/Tensor.ts
2
- import { DenseMatrix } from "@danielsimonjr/mathts-matrix";
2
+ import { DenseMatrix, backendManager } from "@danielsimonjr/mathts-matrix";
3
3
  var Tensor = class _Tensor {
4
4
  shape;
5
5
  data;
@@ -535,15 +535,11 @@ var Tensor = class _Tensor {
535
535
  const [m, k] = this.shape;
536
536
  const [k2, n] = other.shape;
537
537
  if (k !== k2) throw new Error(`Tensor.matMul: inner dimension mismatch ${k} != ${k2}`);
538
- const out = new Float64Array(m * n);
539
- for (let i = 0; i < m; i++) {
540
- for (let j = 0; j < n; j++) {
541
- let sum = 0;
542
- for (let q = 0; q < k; q++) sum += this.data[i * k + q] * other.data[q * n + j];
543
- out[i * n + j] = sum;
544
- }
545
- }
546
- return new _Tensor([m, n], out);
538
+ const c = backendManager.multiply(
539
+ new DenseMatrix(m, k, this.data),
540
+ new DenseMatrix(k, n, other.data)
541
+ );
542
+ return new _Tensor([m, n], c.toFloat64Array());
547
543
  }
548
544
  static einsum(spec, ...operands) {
549
545
  const inStrides = operands.map((o) => _Tensor.rowMajorStrides(o.shape));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielsimonjr/mathts-tensor",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Rank-N dense Tensor type for MathTS with Float64Array-backed storage",
5
5
  "author": "Daniel Simon Jr.",
6
6
  "license": "MIT",
@@ -31,8 +31,8 @@
31
31
  "build:prod": "tsup src/index.ts --format esm --dts --clean --minify --treeshake"
32
32
  },
33
33
  "dependencies": {
34
- "@danielsimonjr/mathts-core": "^0.3.0",
35
- "@danielsimonjr/mathts-matrix": "^0.1.12"
34
+ "@danielsimonjr/mathts-core": "^0.4.0",
35
+ "@danielsimonjr/mathts-matrix": "^0.1.14"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/node": "^25.5.2",