@danielsimonjr/mathts-matrix 0.7.1 → 0.7.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.
Files changed (99) hide show
  1. package/dist/backends/Backend.d.ts +146 -0
  2. package/dist/backends/Backend.d.ts.map +1 -0
  3. package/dist/backends/BackendManager.d.ts +189 -0
  4. package/dist/backends/BackendManager.d.ts.map +1 -0
  5. package/dist/backends/GPUBackend.d.ts +128 -0
  6. package/dist/backends/GPUBackend.d.ts.map +1 -0
  7. package/dist/backends/GPUMatrixBackend.d.ts +123 -0
  8. package/dist/backends/GPUMatrixBackend.d.ts.map +1 -0
  9. package/dist/backends/JSBackend.d.ts +93 -0
  10. package/dist/backends/JSBackend.d.ts.map +1 -0
  11. package/dist/backends/ParallelBackend.d.ts +131 -0
  12. package/dist/backends/ParallelBackend.d.ts.map +1 -0
  13. package/dist/backends/WASMBackend.d.ts +156 -0
  14. package/dist/backends/WASMBackend.d.ts.map +1 -0
  15. package/dist/backends/WasmLoader.d.ts +326 -0
  16. package/dist/backends/WasmLoader.d.ts.map +1 -0
  17. package/dist/backends/gpu/BatchExecutor.d.ts +190 -0
  18. package/dist/backends/gpu/BatchExecutor.d.ts.map +1 -0
  19. package/dist/backends/gpu/Sync.d.ts +167 -0
  20. package/dist/backends/gpu/Sync.d.ts.map +1 -0
  21. package/dist/backends/gpu/builtin-shaders.d.ts +178 -0
  22. package/dist/backends/gpu/builtin-shaders.d.ts.map +1 -0
  23. package/dist/backends/gpu/index.d.ts +13 -0
  24. package/dist/backends/gpu/index.d.ts.map +1 -0
  25. package/dist/backends/index.d.ts +18 -0
  26. package/dist/backends/index.d.ts.map +1 -0
  27. package/dist/backends/register-backends.d.ts +18 -0
  28. package/dist/backends/register-backends.d.ts.map +1 -0
  29. package/dist/backends/wasm/detect.d.ts +58 -0
  30. package/dist/backends/wasm/detect.d.ts.map +1 -0
  31. package/dist/backends/wasm/fft-wasm.d.ts +120 -0
  32. package/dist/backends/wasm/fft-wasm.d.ts.map +1 -0
  33. package/dist/backends/wasm/index.d.ts +9 -0
  34. package/dist/backends/wasm/index.d.ts.map +1 -0
  35. package/dist/backends/wasm/integrity.d.ts +18 -0
  36. package/dist/backends/wasm/integrity.d.ts.map +1 -0
  37. package/dist/backends/wasm/resolve.d.ts +12 -0
  38. package/dist/backends/wasm/resolve.d.ts.map +1 -0
  39. package/dist/{chunk-4VMDO6W2.js → chunk-PNKVD2UK.js} +2 -7
  40. package/dist/config.d.ts +145 -0
  41. package/dist/config.d.ts.map +1 -0
  42. package/dist/index.d.ts +14 -3037
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +9 -9
  45. package/dist/{integrity-LIWCCDIJ.js → integrity-IBNQNHXP.js} +1 -1
  46. package/dist/operations/cholesky.d.ts +24 -0
  47. package/dist/operations/cholesky.d.ts.map +1 -0
  48. package/dist/operations/common.d.ts +61 -0
  49. package/dist/operations/common.d.ts.map +1 -0
  50. package/dist/operations/condest.d.ts +27 -0
  51. package/dist/operations/condest.d.ts.map +1 -0
  52. package/dist/operations/eig-wasm.d.ts +35 -0
  53. package/dist/operations/eig-wasm.d.ts.map +1 -0
  54. package/dist/operations/eig.d.ts +75 -0
  55. package/dist/operations/eig.d.ts.map +1 -0
  56. package/dist/operations/expm.d.ts +46 -0
  57. package/dist/operations/expm.d.ts.map +1 -0
  58. package/dist/operations/index.d.ts +21 -0
  59. package/dist/operations/index.d.ts.map +1 -0
  60. package/dist/operations/logm.d.ts +59 -0
  61. package/dist/operations/logm.d.ts.map +1 -0
  62. package/dist/operations/lu.d.ts +51 -0
  63. package/dist/operations/lu.d.ts.map +1 -0
  64. package/dist/operations/pinv.d.ts +36 -0
  65. package/dist/operations/pinv.d.ts.map +1 -0
  66. package/dist/operations/qr-family.d.ts +52 -0
  67. package/dist/operations/qr-family.d.ts.map +1 -0
  68. package/dist/operations/qr-pivoted.d.ts +39 -0
  69. package/dist/operations/qr-pivoted.d.ts.map +1 -0
  70. package/dist/operations/qr.d.ts +35 -0
  71. package/dist/operations/qr.d.ts.map +1 -0
  72. package/dist/operations/schur.d.ts +58 -0
  73. package/dist/operations/schur.d.ts.map +1 -0
  74. package/dist/operations/sqrtm.d.ts +76 -0
  75. package/dist/operations/sqrtm.d.ts.map +1 -0
  76. package/dist/operations/svd-wasm.d.ts +23 -0
  77. package/dist/operations/svd-wasm.d.ts.map +1 -0
  78. package/dist/operations/svd.d.ts +70 -0
  79. package/dist/operations/svd.d.ts.map +1 -0
  80. package/dist/parallel-matrix.d.ts +223 -0
  81. package/dist/parallel-matrix.d.ts.map +1 -0
  82. package/dist/{resolve-DDCEWHWX.js → resolve-2SX6WJ6R.js} +1 -1
  83. package/dist/typed-operations.d.ts +162 -0
  84. package/dist/typed-operations.d.ts.map +1 -0
  85. package/dist/types/DenseMatrix.d.ts +213 -0
  86. package/dist/types/DenseMatrix.d.ts.map +1 -0
  87. package/dist/types/Matrix.d.ts +188 -0
  88. package/dist/types/Matrix.d.ts.map +1 -0
  89. package/dist/types/SparseMatrix.d.ts +214 -0
  90. package/dist/types/SparseMatrix.d.ts.map +1 -0
  91. package/dist/types/dense/arithmetic.d.ts +8 -0
  92. package/dist/types/dense/arithmetic.d.ts.map +1 -0
  93. package/dist/types/dense/reduction.d.ts +8 -0
  94. package/dist/types/dense/reduction.d.ts.map +1 -0
  95. package/dist/types/index.d.ts +9 -0
  96. package/dist/types/index.d.ts.map +1 -0
  97. package/dist/wasm/mathts-as.wasm +0 -0
  98. package/dist/wasm/wasm-manifest.json +1 -1
  99. package/package.json +70 -70
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Rank-Revealing Pivoted QR Decomposition (Businger-Golub column pivoting)
3
+ *
4
+ * Computes `A[:, P] = Q · R` via Householder reflections, choosing at each
5
+ * step the remaining column of largest norm as the next pivot. This is the
6
+ * classical column-pivoted QR (LAPACK `dgeqp3`'s algorithm, simplified —
7
+ * exact remaining-column-norm recomputation rather than the cheaper
8
+ * downdating formula, since these matrices are small): it guarantees
9
+ * `|R[0,0]| ≥ |R[1,1]| ≥ … ≥ |R[k-1,k-1]|`, which makes `R`'s diagonal a
10
+ * reliable numerical-rank indicator — unlike the plain (unpivoted)
11
+ * Gram-Schmidt `qr()` in this directory, whose diagonal can be small for an
12
+ * early column purely by column order, not by rank deficiency.
13
+ *
14
+ * Reuses the Householder helpers in `./common.js` (already exercised by
15
+ * `svd.ts`/`schur.ts`) rather than re-deriving reflection algebra here.
16
+ */
17
+ import { DenseMatrix } from '../types/DenseMatrix.js';
18
+ export interface QRPivotedResult {
19
+ /** Orthonormal Q factor (m × k, k = min(m, n)). */
20
+ Q: DenseMatrix;
21
+ /** Upper-triangular R factor (k × n) with |diag(R)| non-increasing. */
22
+ R: DenseMatrix;
23
+ /** Column permutation: `P[j]` is the original column index now at position `j`, so `A[:, P] = Q · R`. */
24
+ P: number[];
25
+ /** Numerical rank: count of `i` with `|R[i,i]| > tolerance · |R[0,0]|`. */
26
+ rank: number;
27
+ }
28
+ export interface QRPivotedOptions {
29
+ /** Relative rank tolerance (default `1e-10`). */
30
+ tolerance?: number;
31
+ }
32
+ /**
33
+ * Compute the column-pivoted rank-revealing QR decomposition of `A`.
34
+ *
35
+ * @param A - Input matrix (m × n).
36
+ * @param opts - Optional rank tolerance.
37
+ */
38
+ export declare function qrPivoted(A: DenseMatrix, opts?: QRPivotedOptions): QRPivotedResult;
39
+ //# sourceMappingURL=qr-pivoted.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qr-pivoted.d.ts","sourceRoot":"","sources":["../../src/operations/qr-pivoted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,MAAM,WAAW,eAAe;IAC9B,mDAAmD;IACnD,CAAC,EAAE,WAAW,CAAC;IACf,uEAAuE;IACvE,CAAC,EAAE,WAAW,CAAC;IACf,yGAAyG;IACzG,CAAC,EAAE,MAAM,EAAE,CAAC;IACZ,2EAA2E;IAC3E,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,gBAAgB;IAC/B,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,eAAe,CA6GlF"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * QR Decomposition (DenseMatrix primitive)
3
+ *
4
+ * Classical Gram-Schmidt with re-orthogonalisation. Adequate for the
5
+ * well-conditioned matrices that arise in the tensor wrappers + the
6
+ * `randomTensor` orthogonal-distribution code path. For pathological
7
+ * matrices the Householder QR implemented in `WASMBackend.qrDecompositionJS`
8
+ * is preferable, but Gram-Schmidt suffices for the current call sites.
9
+ *
10
+ * Two modes:
11
+ * - 'reduced' (thin QR): Q is (m × k), R is (k × n), k = min(m, n).
12
+ * - 'full' : Q is (m × m), R is (m × n).
13
+ *
14
+ * In 'reduced' mode A = Q · R reconstructs A to within `1e-12`.
15
+ * Q's columns are orthonormal (Qᵀ · Q = I_k); R is upper-triangular.
16
+ */
17
+ import { DenseMatrix } from '../types/DenseMatrix.js';
18
+ export interface QRResult {
19
+ /** Orthonormal Q factor. Reduced: (m × k); full: (m × m). */
20
+ Q: DenseMatrix;
21
+ /** Upper-triangular R factor. Reduced: (k × n); full: (m × n). */
22
+ R: DenseMatrix;
23
+ }
24
+ export interface QROptions {
25
+ /** 'reduced' (default, thin QR) or 'full'. */
26
+ mode?: 'reduced' | 'full';
27
+ }
28
+ /**
29
+ * Compute the QR decomposition of `A` such that `A = Q · R`.
30
+ *
31
+ * @param A - Input matrix (m × n, m ≥ 0, n ≥ 0).
32
+ * @param opts - Optional mode selector (`'reduced'` thin QR or `'full'` square Q).
33
+ */
34
+ export declare function qr(A: DenseMatrix, opts?: QROptions): QRResult;
35
+ //# sourceMappingURL=qr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qr.d.ts","sourceRoot":"","sources":["../../src/operations/qr.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,MAAM,WAAW,QAAQ;IACvB,6DAA6D;IAC7D,CAAC,EAAE,WAAW,CAAC;IACf,kEAAkE;IAClE,CAAC,EAAE,WAAW,CAAC;CAChB;AAED,MAAM,WAAW,SAAS;IACxB,8CAA8C;IAC9C,IAAI,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;CAC3B;AAED;;;;;GAKG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,CAqJ7D"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Schur Decomposition — Francis QR with double shifts (Slice 6.1)
3
+ *
4
+ * Computes the real Schur decomposition A = Q · T · Q^T where:
5
+ * - Q is orthogonal (Q^T · Q = I)
6
+ * - T is quasi-upper-triangular (real Schur form): diagonal blocks are
7
+ * 1×1 (real eigenvalue) or 2×2 (complex-conjugate eigenvalue pair)
8
+ *
9
+ * Algorithm: Householder reduction to upper Hessenberg form followed by
10
+ * Francis double-shift implicit QR iteration (Golub & Van Loan §7.5).
11
+ *
12
+ * References:
13
+ * Golub & Van Loan (2013) "Matrix Computations," 4th ed., §7.5.
14
+ * Higham (2008) "Functions of Matrices: Theory and Computation," §1.
15
+ */
16
+ import { DenseMatrix } from '../types/DenseMatrix.js';
17
+ export interface SchurResult {
18
+ /** Orthogonal factor Q (Q^T · Q = I, Q · Q^T = I). */
19
+ Q: DenseMatrix;
20
+ /** Quasi-upper-triangular Schur form T (real Schur form). */
21
+ T: DenseMatrix;
22
+ }
23
+ export interface SchurOptions {
24
+ /** Maximum QR iterations (default: 1000). */
25
+ maxIterations?: number;
26
+ /** Deflation tolerance (default: 1e-12). */
27
+ tolerance?: number;
28
+ }
29
+ /**
30
+ * Compute the real Schur decomposition of a square matrix:
31
+ * A = Q · T · Q^T
32
+ *
33
+ * T is quasi-upper-triangular (real Schur form): 1×1 diagonal blocks for
34
+ * real eigenvalues and 2×2 blocks for complex-conjugate pairs. Q is
35
+ * orthogonal.
36
+ *
37
+ * For matrices with all real eigenvalues, T is upper triangular with
38
+ * eigenvalues on the diagonal. For matrices with complex-conjugate eigenvalue
39
+ * pairs, the corresponding 2×2 diagonal block has the form
40
+ * [[a, b], [-b, a]] (approximately)
41
+ * and the complex pair is a ± bi.
42
+ *
43
+ * @param A - Square DenseMatrix (n × n, real entries).
44
+ * @param opts - Optional algorithm parameters.
45
+ * @returns { Q, T } satisfying Q · T · Q^T ≈ A.
46
+ * @throws Error if A is not square.
47
+ */
48
+ export declare function matrixSchur(A: DenseMatrix, opts?: SchurOptions): SchurResult;
49
+ /**
50
+ * Low-level Schur decomposition on a 2-D number array.
51
+ * Returns mutable H and Q arrays suitable for further in-place operations.
52
+ * @internal
53
+ */
54
+ export declare function schurInternal(A: number[][], maxIterations?: number, tolerance?: number): {
55
+ H: number[][];
56
+ Q: number[][];
57
+ };
58
+ //# sourceMappingURL=schur.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schur.d.ts","sourceRoot":"","sources":["../../src/operations/schur.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAqVtD,MAAM,WAAW,WAAW;IAC1B,sDAAsD;IACtD,CAAC,EAAE,WAAW,CAAC;IACf,6DAA6D;IAC7D,CAAC,EAAE,WAAW,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,6CAA6C;IAC7C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,WAAW,CA+B5E;AAMD;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,CAAC,EAAE,MAAM,EAAE,EAAE,EACb,aAAa,SAAO,EACpB,SAAS,SAAQ,GAChB;IAAE,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;IAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAA;CAAE,CAElC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Matrix Square Root — Hybrid approach (Slices 5.9a + 6.1)
3
+ *
4
+ * Computes the principal square root of a square matrix.
5
+ *
6
+ * Algorithm selection:
7
+ * 1. For symmetric positive semi-definite matrices: symmetric eigendecomposition
8
+ * with Gram-Schmidt re-orthogonalisation (handles repeated eigenvalues).
9
+ * 2. For general matrices: Björck-Hammarling Schur-based algorithm
10
+ * (Higham 2008, Algorithm 6.3):
11
+ * a. Schur decompose: A = Q · T · Q^T.
12
+ * b. Compute upper-triangular U with U^2 = T via back-substitution.
13
+ * c. Rotate back: sqrtm(A) = Q · U · Q^T.
14
+ * Falls back to Newton iteration for diagonalisable matrices when the
15
+ * Schur path is unsuitable (e.g. negative eigenvalues in 1×1 blocks).
16
+ *
17
+ * References:
18
+ * - Higham (2008) "Functions of Matrices" §6 (Algorithm 6.3).
19
+ * - Björck & Hammarling (1983) "A Schur method for the square root of a matrix."
20
+ */
21
+ import { DenseMatrix } from '../types/DenseMatrix.js';
22
+ export interface SqrtmOptions {
23
+ /**
24
+ * Force the symmetric-eigendecomposition path even for non-SPD matrices.
25
+ * By default, symmetry is auto-detected.
26
+ */
27
+ assumeSymmetric?: boolean;
28
+ }
29
+ /**
30
+ * Compute the principal square root of a square DenseMatrix.
31
+ *
32
+ * For symmetric positive semi-definite A:
33
+ * Uses symmetric eigendecomposition with Gram-Schmidt re-orthogonalisation.
34
+ *
35
+ * For general diagonalisable A with non-negative eigenvalues:
36
+ * Uses Newton iteration Y_{k+1} = (Y_k + A * Y_k^{-1}) / 2, falling back
37
+ * to the eig-based formula if Newton fails to converge.
38
+ *
39
+ * Slice 5.9a limitations:
40
+ * - Matrices with negative real eigenvalues: throws.
41
+ * - Matrices with complex eigenvalues: throws.
42
+ * - Non-diagonalisable (defective) matrices: Newton may fail + eig fallback
43
+ * may also fail. Full Schur-based Björck-Hammarling deferred to Slice 5.9b.
44
+ *
45
+ * @param A - Square DenseMatrix (n × n).
46
+ * @param opts - Optional flags.
47
+ * @returns sqrtm(A), the principal square root.
48
+ * @throws Error for matrices with negative or complex eigenvalues.
49
+ *
50
+ * @example
51
+ * // sqrtm(I) = I
52
+ * matrixSqrtm(DenseMatrix.eye(3)) // => identity 3×3
53
+ *
54
+ * @example
55
+ * // sqrtm(4*I) = 2*I
56
+ * const A = DenseMatrix.fromArray([[4,0],[0,4]]);
57
+ * matrixSqrtm(A) // => [[2,0],[0,2]]
58
+ *
59
+ * @example
60
+ * // Round-trip: sqrtm(A)^2 ≈ A
61
+ * const S = DenseMatrix.fromArray([[4,2],[2,3]]);
62
+ * const R = matrixSqrtm(S);
63
+ * // R * R ≈ S (to machine precision for SPD matrices)
64
+ */
65
+ export declare function matrixSqrtm(A: DenseMatrix, opts?: SqrtmOptions): DenseMatrix;
66
+ /**
67
+ * Newton iteration square root (exported for logm.ts internal use).
68
+ * Y_{k+1} = (Y_k + A * Y_k^{-1}) / 2, starting from Y_0 = I.
69
+ *
70
+ * This is a robust complement to sqrtmGeneral for matrices near the identity
71
+ * and is used internally by matrixLogm's inverse-scaling phase.
72
+ *
73
+ * @internal
74
+ */
75
+ export declare function matrixSqrtNewtonInternal(A: number[][]): number[][];
76
+ //# sourceMappingURL=sqrtm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqrtm.d.ts","sourceRoot":"","sources":["../../src/operations/sqrtm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAuatD,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,WAAW,CAqC5E;AAUD;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAsBlE"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * `svdWasm` — thin wrapper kept for API compatibility (consumed by `tensor` and `linalg`).
3
+ *
4
+ * The WASM SVD path was RETIRED and REMOVED (2026-07-01): the AssemblyScript one-sided
5
+ * Jacobi kernel was scalar + async and measured 0.4–0.7× of the pure-JS Golub-Reinsch
6
+ * {@link svd}, worsening with size — see `tools/benchmarks/decomp-audit`. It now delegates
7
+ * to the JS `svd`, truncated to the **thin / economy** form (`U` is `m×k`, `V` is `n×k`,
8
+ * `k = min(m, n)`) so the result shape is unchanged. The `async` signature is retained so
9
+ * existing callers (which `await`) are unaffected.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ import { type SVDResult, type SVDOptions } from './svd.js';
14
+ /**
15
+ * Thin SVD. Delegates to the JS {@link svd} and truncates to the economy form
16
+ * (WASM path retired — see file header).
17
+ *
18
+ * @param matrix - Input matrix (m x n) as a row-major 2D array
19
+ * @param options - SVD options; `rankTolerance` controls the rank estimate
20
+ * @returns thin SVD `{ U (m x k), S (k), V (n x k), rank }`
21
+ */
22
+ export declare function svdWasm(matrix: number[][], options?: SVDOptions): Promise<SVDResult>;
23
+ //# sourceMappingURL=svd-wasm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svd-wasm.d.ts","sourceRoot":"","sources":["../../src/operations/svd-wasm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAO,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAsBhE;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAS1F"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Singular Value Decomposition (SVD)
3
+ *
4
+ * Implements SVD using Golub-Reinsch bidiagonalization and implicit QR.
5
+ * A = U * S * V^T where:
6
+ * - U: m x m orthogonal matrix (left singular vectors)
7
+ * - S: m x n diagonal matrix (singular values)
8
+ * - V: n x n orthogonal matrix (right singular vectors)
9
+ */
10
+ /**
11
+ * Result of SVD decomposition
12
+ */
13
+ export interface SVDResult {
14
+ /** Left singular vectors (m x m) */
15
+ U: number[][];
16
+ /** Singular values (min(m,n) values) */
17
+ S: number[];
18
+ /** Right singular vectors (n x n) */
19
+ V: number[][];
20
+ /** Rank estimate */
21
+ rank: number;
22
+ }
23
+ /**
24
+ * Options for SVD computation
25
+ */
26
+ export interface SVDOptions {
27
+ /** Maximum number of iterations */
28
+ maxIterations?: number;
29
+ /** Convergence tolerance */
30
+ tolerance?: number;
31
+ /**
32
+ * Complete the thin factor to a square orthonormal basis (U → m×m for tall
33
+ * inputs, V → n×n for wide ones), numpy `full_matrices=True` style, so the
34
+ * rectangular-Σ reconstruction `A = U·Σ·Vᵀ` holds. Default `false` = thin
35
+ * factors (the library's long-standing behavior; the option was previously
36
+ * accepted but ignored — B-4).
37
+ */
38
+ fullMatrices?: boolean;
39
+ /** Threshold for rank determination */
40
+ rankTolerance?: number;
41
+ }
42
+ export declare function svd(matrix: number[][] | Float64Array, options?: SVDOptions): SVDResult;
43
+ /**
44
+ * Compute only singular values (faster than full SVD)
45
+ */
46
+ export declare function singularValues(matrix: number[][] | Float64Array, options?: Omit<SVDOptions, 'fullMatrices'>): number[];
47
+ /**
48
+ * Compute the pseudoinverse (Moore-Penrose inverse) using SVD
49
+ */
50
+ export declare function pinv(matrix: number[][], options?: SVDOptions): number[][];
51
+ /**
52
+ * Low-rank approximation using SVD
53
+ * Keeps only the top r singular values
54
+ */
55
+ export declare function lowRankApprox(matrix: number[][], r: number, options?: SVDOptions): number[][];
56
+ /**
57
+ * Compute condition number using SVD
58
+ */
59
+ export declare function cond(matrix: number[][], options?: SVDOptions): number;
60
+ /**
61
+ * Compute matrix norm using SVD
62
+ * Returns the spectral norm (largest singular value)
63
+ */
64
+ export declare function norm2(matrix: number[][], options?: SVDOptions): number;
65
+ /**
66
+ * Compute Frobenius norm using SVD
67
+ * Equals sqrt(sum of squared singular values)
68
+ */
69
+ export declare function normFro(matrix: number[][]): number;
70
+ //# sourceMappingURL=svd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svd.d.ts","sourceRoot":"","sources":["../../src/operations/svd.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAUH;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,oCAAoC;IACpC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;IACd,wCAAwC;IACxC,CAAC,EAAE,MAAM,EAAE,CAAC;IACZ,qCAAqC;IACrC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;IACd,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,mCAAmC;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,4BAA4B;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,uCAAuC;IACvC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAuVD,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,GAAG,YAAY,EAAE,OAAO,GAAE,UAAe,GAAG,SAAS,CA0K1F;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EAAE,EAAE,GAAG,YAAY,EACjC,OAAO,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,GACzC,MAAM,EAAE,CAEV;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,EAAE,EAAE,CAmCzE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,EAAE,EAAE,CAqB7F;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,CAQrE;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,CAGtE;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,CAQlD"}
@@ -0,0 +1,223 @@
1
+ /**
2
+ * Parallel-First Matrix Operations
3
+ *
4
+ * AssemblyScript-friendly TypeScript implementations with typed-function
5
+ * integration and workerpool parallel execution via @danielsimonjr/mathts-parallel.
6
+ *
7
+ * These operations use Float64Array flat row-major format for efficient
8
+ * parallel processing through the ComputePool worker infrastructure.
9
+ *
10
+ * Following the parallel-first philosophy per CLAUDE.md:
11
+ * - Use workers for ALL matrix operations (matmul, transpose, etc.)
12
+ * - Use workers for ALL element-wise operations on matrices
13
+ * - Only fall back to sequential for trivial scalar operations
14
+ *
15
+ * @packageDocumentation
16
+ */
17
+ import type { TypedFunction } from '@danielsimonjr/mathts-core';
18
+ /**
19
+ * Create a matrix from various input types - parallel-first
20
+ */
21
+ export declare const parallelMatrix: TypedFunction;
22
+ /**
23
+ * Create an identity matrix
24
+ */
25
+ export declare const parallelIdentity: TypedFunction;
26
+ /**
27
+ * Create a matrix of zeros
28
+ */
29
+ export declare const parallelZeros: TypedFunction;
30
+ /**
31
+ * Create a matrix of ones
32
+ */
33
+ export declare const parallelOnes: TypedFunction;
34
+ /**
35
+ * Create a diagonal matrix
36
+ */
37
+ export declare const parallelDiag: TypedFunction;
38
+ /**
39
+ * Create a random matrix
40
+ */
41
+ export declare const parallelRandom: TypedFunction;
42
+ /**
43
+ * Parallel matrix addition with typed-function dispatch
44
+ */
45
+ export declare const parallelMatrixAdd: TypedFunction;
46
+ /**
47
+ * Parallel matrix subtraction with typed-function dispatch
48
+ */
49
+ export declare const parallelMatrixSubtract: TypedFunction;
50
+ /**
51
+ * Parallel matrix multiplication (matmul) with typed-function dispatch
52
+ */
53
+ export declare const parallelMatrixMultiply: TypedFunction;
54
+ /**
55
+ * Element-wise multiplication (Hadamard product) - parallel execution
56
+ */
57
+ export declare const parallelDotMultiply: TypedFunction;
58
+ /**
59
+ * Parallel matrix division
60
+ */
61
+ export declare const parallelMatrixDivide: TypedFunction;
62
+ /**
63
+ * Matrix negation - parallel execution
64
+ */
65
+ export declare const parallelUnaryMinus: TypedFunction;
66
+ /**
67
+ * Matrix transpose - parallel execution
68
+ */
69
+ export declare const parallelMatrixTranspose: TypedFunction;
70
+ /**
71
+ * Parallel sum of all elements
72
+ */
73
+ export declare const parallelMatrixSum: TypedFunction;
74
+ /**
75
+ * Parallel mean of all elements
76
+ */
77
+ export declare const parallelMatrixMean: TypedFunction;
78
+ /**
79
+ * Parallel minimum element
80
+ */
81
+ export declare const parallelMatrixMin: TypedFunction;
82
+ /**
83
+ * Parallel maximum element
84
+ */
85
+ export declare const parallelMatrixMax: TypedFunction;
86
+ /**
87
+ * Parallel variance computation
88
+ */
89
+ export declare const parallelMatrixVariance: TypedFunction;
90
+ /**
91
+ * Parallel standard deviation
92
+ */
93
+ export declare const parallelMatrixStd: TypedFunction;
94
+ /**
95
+ * Parallel Frobenius norm
96
+ */
97
+ export declare const parallelMatrixNorm: TypedFunction;
98
+ /**
99
+ * Parallel dot product
100
+ */
101
+ export declare const parallelMatrixDot: TypedFunction;
102
+ /**
103
+ * Matrix trace (sum of diagonal elements)
104
+ */
105
+ export declare const parallelMatrixTrace: TypedFunction;
106
+ /**
107
+ * Parallel Euclidean distance
108
+ */
109
+ export declare const parallelMatrixDistance: TypedFunction;
110
+ /**
111
+ * Parallel element-wise absolute value
112
+ */
113
+ export declare const parallelMatrixAbs: TypedFunction;
114
+ /**
115
+ * Parallel element-wise square root
116
+ */
117
+ export declare const parallelMatrixSqrt: TypedFunction;
118
+ /**
119
+ * Parallel element-wise square
120
+ */
121
+ export declare const parallelMatrixSquare: TypedFunction;
122
+ /**
123
+ * Parallel element-wise exponential
124
+ */
125
+ export declare const parallelMatrixExp: TypedFunction;
126
+ /**
127
+ * Parallel element-wise natural logarithm
128
+ */
129
+ export declare const parallelMatrixLog: TypedFunction;
130
+ /**
131
+ * Parallel element-wise sine
132
+ */
133
+ export declare const parallelMatrixSin: TypedFunction;
134
+ /**
135
+ * Parallel element-wise cosine
136
+ */
137
+ export declare const parallelMatrixCos: TypedFunction;
138
+ /**
139
+ * Parallel element-wise tangent
140
+ */
141
+ export declare const parallelMatrixTan: TypedFunction;
142
+ /**
143
+ * Get matrix dimensions
144
+ */
145
+ export declare const parallelMatrixSize: TypedFunction;
146
+ /**
147
+ * Get element at position
148
+ */
149
+ export declare const parallelMatrixSubset: TypedFunction;
150
+ /**
151
+ * Get row from matrix
152
+ */
153
+ export declare const parallelMatrixRow: TypedFunction;
154
+ /**
155
+ * Get column from matrix
156
+ */
157
+ export declare const parallelMatrixColumn: TypedFunction;
158
+ /**
159
+ * Get diagonal from matrix
160
+ */
161
+ export declare const parallelMatrixDiagonal: TypedFunction;
162
+ /**
163
+ * Parallel matrix-vector multiplication
164
+ */
165
+ export declare const parallelMatrixMatvec: TypedFunction;
166
+ /**
167
+ * Parallel outer product
168
+ */
169
+ export declare const parallelMatrixOuter: TypedFunction;
170
+ /**
171
+ * Parallel histogram computation
172
+ */
173
+ export declare const parallelMatrixHistogram: TypedFunction;
174
+ export declare const parallelMatrixOperations: {
175
+ matrix: TypedFunction;
176
+ identity: TypedFunction;
177
+ zeros: TypedFunction;
178
+ ones: TypedFunction;
179
+ diag: TypedFunction;
180
+ random: TypedFunction;
181
+ add: TypedFunction;
182
+ subtract: TypedFunction;
183
+ multiply: TypedFunction;
184
+ dotMultiply: TypedFunction;
185
+ divide: TypedFunction;
186
+ unaryMinus: TypedFunction;
187
+ transpose: TypedFunction;
188
+ sum: TypedFunction;
189
+ mean: TypedFunction;
190
+ min: TypedFunction;
191
+ max: TypedFunction;
192
+ variance: TypedFunction;
193
+ std: TypedFunction;
194
+ norm: TypedFunction;
195
+ dot: TypedFunction;
196
+ trace: TypedFunction;
197
+ distance: TypedFunction;
198
+ abs: TypedFunction;
199
+ sqrt: TypedFunction;
200
+ square: TypedFunction;
201
+ exp: TypedFunction;
202
+ log: TypedFunction;
203
+ sin: TypedFunction;
204
+ cos: TypedFunction;
205
+ tan: TypedFunction;
206
+ size: TypedFunction;
207
+ subset: TypedFunction;
208
+ row: TypedFunction;
209
+ column: TypedFunction;
210
+ diagonal: TypedFunction;
211
+ matvec: TypedFunction;
212
+ outer: TypedFunction;
213
+ histogram: TypedFunction;
214
+ };
215
+ /**
216
+ * Initialize parallel matrix operations
217
+ */
218
+ export declare function initializeParallelMatrix(): Promise<void>;
219
+ /**
220
+ * Terminate parallel matrix operations pool
221
+ */
222
+ export declare function terminateParallelMatrix(): Promise<void>;
223
+ //# sourceMappingURL=parallel-matrix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parallel-matrix.d.ts","sourceRoot":"","sources":["../src/parallel-matrix.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAwOhE;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,aAab,CAAC;AAEjB;;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G;IACH,IAAI;IACJ,GAAG;IACH,KAAK;IACL,QAAQ;IAGR,GAAG;IACH,IAAI;IACJ,MAAM;IACN,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IAGH,IAAI;IACJ,MAAM;IACN,GAAG;IACH,MAAM;IACN,QAAQ;IAGR,MAAM;IACN,KAAK;IACL,SAAS;CACV,CAAC;AAEF;;GAEG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC,CAE9D;AAED;;GAEG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC,CAE7D"}
@@ -1,4 +1,4 @@
1
- import "./chunk-4VMDO6W2.js";
1
+ import "./chunk-PNKVD2UK.js";
2
2
 
3
3
  // src/backends/wasm/resolve.ts
4
4
  import { resolvePackagedWasm, defaultWasmLocation } from "@danielsimonjr/mathts-core/internal";