@danielsimonjr/mathts-matrix 0.1.2 → 0.1.3

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/README.md CHANGED
@@ -11,36 +11,32 @@ npm install @danielsimonjr/mathts-matrix
11
11
  ## Usage
12
12
 
13
13
  ```typescript
14
- import { Matrix, DenseMatrix, backends } from '@danielsimonjr/mathts-matrix';
14
+ import { DenseMatrix } from '@danielsimonjr/mathts-matrix';
15
15
 
16
16
  // Create a matrix from a 2D array
17
- const A = Matrix.from([
17
+ const A = DenseMatrix.fromArray([
18
18
  [1, 2, 3],
19
19
  [4, 5, 6],
20
- [7, 8, 9]
20
+ [7, 8, 9],
21
21
  ]);
22
22
 
23
- // Basic operations (coming soon)
24
- const det = A.determinant();
25
- const inv = A.inverse();
26
- const eig = A.eigenvalues();
27
-
28
- // Configure backend
29
- backends.configure({
30
- backend: 'wasm', // Force WASM backend
31
- autoBackend: true, // Or let it auto-select
32
- wasmThreshold: 1000, // Switch to WASM above 1000 elements
33
- gpuThreshold: 100000, // Switch to GPU above 100K elements
34
- });
23
+ // Basic operations
24
+ const sum = A.add(A);
25
+ const product = A.multiply(A);
26
+ const transposed = A.transpose();
27
+
28
+ // Decompositions (operate on number[][])
29
+ import { svd, eig } from '@danielsimonjr/mathts-matrix';
30
+ const { U, S, V } = svd(A.toArray());
35
31
  ```
36
32
 
37
33
  ## Backends
38
34
 
39
- | Backend | Trigger | Performance |
40
- |---------|---------|-------------|
41
- | **JS** | Default | 1x baseline |
42
- | **WASM** | >1K elements | ~10x faster |
43
- | **GPU** | >100K elements | ~100x faster |
35
+ | Backend | Trigger | Performance |
36
+ | -------- | -------------- | ------------ |
37
+ | **JS** | Default | 1x baseline |
38
+ | **WASM** | >1K elements | ~10x faster |
39
+ | **GPU** | >100K elements | ~100x faster |
44
40
 
45
41
  ## Matrix Types
46
42
 
@@ -55,11 +51,11 @@ This package is under active development. Currently implemented:
55
51
  - [x] Backend infrastructure
56
52
  - [x] Dense matrix structure
57
53
  - [x] Sparse matrix (CSR) structure
58
- - [ ] Matrix operations (add, multiply, etc.)
59
- - [ ] WASM backend
60
- - [ ] GPU backend
61
- - [ ] LU/QR/SVD decompositions
62
- - [ ] Eigenvalue solvers
54
+ - [x] Matrix operations (add, multiply, transpose, etc.)
55
+ - [x] WASM backend (Rust primary, AssemblyScript legacy)
56
+ - [x] GPU backend (WebGPU)
57
+ - [x] SVD decomposition
58
+ - [x] Eigenvalue solvers
63
59
 
64
60
  ## License
65
61
 
@@ -0,0 +1,26 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __esm = (fn, res) => function __init() {
6
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
7
+ };
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ export {
23
+ __esm,
24
+ __export,
25
+ __toCommonJS
26
+ };
@@ -1,24 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __esm = (fn, res) => function __init() {
6
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
7
- };
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
-
22
1
  // src/operations/eig.ts
23
2
  var DEFAULT_MAX_ITERATIONS = 1e3;
24
3
  var DEFAULT_TOLERANCE = 1e-12;
@@ -103,7 +82,7 @@ function applyHouseholderRight(A, v, beta, startRow, startCol) {
103
82
  function hessenberg(A) {
104
83
  const n = A.length;
105
84
  const H = cloneMatrix(A);
106
- let Q = eye(n);
85
+ const Q = eye(n);
107
86
  for (let k = 0; k < n - 2; k++) {
108
87
  const x = [];
109
88
  for (let i = k + 1; i < n; i++) {
@@ -300,7 +279,7 @@ function inverseIteration(A, eigenvalue, tolerance, maxIterations) {
300
279
  }
301
280
  }
302
281
  }
303
- let v = new Array(n).fill(1);
282
+ const v = new Array(n).fill(1);
304
283
  let prevNorm = 0;
305
284
  for (let iter = 0; iter < maxIterations; iter++) {
306
285
  const y = new Array(n).fill(0);
@@ -352,10 +331,7 @@ function eig(matrix, options = {}) {
352
331
  if (n2 !== Math.floor(n2)) {
353
332
  throw new Error("Float64Array length must be a perfect square");
354
333
  }
355
- A = Array.from(
356
- { length: n2 },
357
- (_, i) => Array.from({ length: n2 }, (_2, j) => matrix[i * n2 + j])
358
- );
334
+ A = Array.from({ length: n2 }, (_, i) => Array.from({ length: n2 }, (_2, j) => matrix[i * n2 + j]));
359
335
  } else {
360
336
  A = matrix;
361
337
  }
@@ -387,7 +363,10 @@ function eig(matrix, options = {}) {
387
363
  const sqrtDisc = Math.sqrt(disc);
388
364
  const e1 = (trace + sqrtDisc) / 2;
389
365
  const e2 = (trace - sqrtDisc) / 2;
390
- values2 = [{ re: e1, im: 0 }, { re: e2, im: 0 }];
366
+ values2 = [
367
+ { re: e1, im: 0 },
368
+ { re: e2, im: 0 }
369
+ ];
391
370
  if (computeVectors) {
392
371
  vectors2 = [];
393
372
  for (const e of [e1, e2]) {
@@ -488,9 +467,6 @@ function powerIteration(matrix, options = {}) {
488
467
  }
489
468
 
490
469
  export {
491
- __esm,
492
- __export,
493
- __toCommonJS,
494
470
  eig,
495
471
  eigvals,
496
472
  powerIteration
@@ -2,7 +2,8 @@ import {
2
2
  eig,
3
3
  eigvals,
4
4
  powerIteration
5
- } from "./chunk-I6QDZ7SC.js";
5
+ } from "./chunk-VCPLE6ED.js";
6
+ import "./chunk-PNKVD2UK.js";
6
7
  export {
7
8
  eig,
8
9
  eigvals,