@danielsimonjr/mathts-matrix 0.7.0 → 0.7.2

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 +222 -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 +161 -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,222 @@
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
+ /**
18
+ * Create a matrix from various input types - parallel-first
19
+ */
20
+ export declare const parallelMatrix: import("typed-function").TypedFunction;
21
+ /**
22
+ * Create an identity matrix
23
+ */
24
+ export declare const parallelIdentity: import("typed-function").TypedFunction;
25
+ /**
26
+ * Create a matrix of zeros
27
+ */
28
+ export declare const parallelZeros: import("typed-function").TypedFunction;
29
+ /**
30
+ * Create a matrix of ones
31
+ */
32
+ export declare const parallelOnes: import("typed-function").TypedFunction;
33
+ /**
34
+ * Create a diagonal matrix
35
+ */
36
+ export declare const parallelDiag: import("typed-function").TypedFunction;
37
+ /**
38
+ * Create a random matrix
39
+ */
40
+ export declare const parallelRandom: import("typed-function").TypedFunction;
41
+ /**
42
+ * Parallel matrix addition with typed-function dispatch
43
+ */
44
+ export declare const parallelMatrixAdd: import("typed-function").TypedFunction;
45
+ /**
46
+ * Parallel matrix subtraction with typed-function dispatch
47
+ */
48
+ export declare const parallelMatrixSubtract: import("typed-function").TypedFunction;
49
+ /**
50
+ * Parallel matrix multiplication (matmul) with typed-function dispatch
51
+ */
52
+ export declare const parallelMatrixMultiply: import("typed-function").TypedFunction;
53
+ /**
54
+ * Element-wise multiplication (Hadamard product) - parallel execution
55
+ */
56
+ export declare const parallelDotMultiply: import("typed-function").TypedFunction;
57
+ /**
58
+ * Parallel matrix division
59
+ */
60
+ export declare const parallelMatrixDivide: import("typed-function").TypedFunction;
61
+ /**
62
+ * Matrix negation - parallel execution
63
+ */
64
+ export declare const parallelUnaryMinus: import("typed-function").TypedFunction;
65
+ /**
66
+ * Matrix transpose - parallel execution
67
+ */
68
+ export declare const parallelMatrixTranspose: import("typed-function").TypedFunction;
69
+ /**
70
+ * Parallel sum of all elements
71
+ */
72
+ export declare const parallelMatrixSum: import("typed-function").TypedFunction;
73
+ /**
74
+ * Parallel mean of all elements
75
+ */
76
+ export declare const parallelMatrixMean: import("typed-function").TypedFunction;
77
+ /**
78
+ * Parallel minimum element
79
+ */
80
+ export declare const parallelMatrixMin: import("typed-function").TypedFunction;
81
+ /**
82
+ * Parallel maximum element
83
+ */
84
+ export declare const parallelMatrixMax: import("typed-function").TypedFunction;
85
+ /**
86
+ * Parallel variance computation
87
+ */
88
+ export declare const parallelMatrixVariance: import("typed-function").TypedFunction;
89
+ /**
90
+ * Parallel standard deviation
91
+ */
92
+ export declare const parallelMatrixStd: import("typed-function").TypedFunction;
93
+ /**
94
+ * Parallel Frobenius norm
95
+ */
96
+ export declare const parallelMatrixNorm: import("typed-function").TypedFunction;
97
+ /**
98
+ * Parallel dot product
99
+ */
100
+ export declare const parallelMatrixDot: import("typed-function").TypedFunction;
101
+ /**
102
+ * Matrix trace (sum of diagonal elements)
103
+ */
104
+ export declare const parallelMatrixTrace: import("typed-function").TypedFunction;
105
+ /**
106
+ * Parallel Euclidean distance
107
+ */
108
+ export declare const parallelMatrixDistance: import("typed-function").TypedFunction;
109
+ /**
110
+ * Parallel element-wise absolute value
111
+ */
112
+ export declare const parallelMatrixAbs: import("typed-function").TypedFunction;
113
+ /**
114
+ * Parallel element-wise square root
115
+ */
116
+ export declare const parallelMatrixSqrt: import("typed-function").TypedFunction;
117
+ /**
118
+ * Parallel element-wise square
119
+ */
120
+ export declare const parallelMatrixSquare: import("typed-function").TypedFunction;
121
+ /**
122
+ * Parallel element-wise exponential
123
+ */
124
+ export declare const parallelMatrixExp: import("typed-function").TypedFunction;
125
+ /**
126
+ * Parallel element-wise natural logarithm
127
+ */
128
+ export declare const parallelMatrixLog: import("typed-function").TypedFunction;
129
+ /**
130
+ * Parallel element-wise sine
131
+ */
132
+ export declare const parallelMatrixSin: import("typed-function").TypedFunction;
133
+ /**
134
+ * Parallel element-wise cosine
135
+ */
136
+ export declare const parallelMatrixCos: import("typed-function").TypedFunction;
137
+ /**
138
+ * Parallel element-wise tangent
139
+ */
140
+ export declare const parallelMatrixTan: import("typed-function").TypedFunction;
141
+ /**
142
+ * Get matrix dimensions
143
+ */
144
+ export declare const parallelMatrixSize: import("typed-function").TypedFunction;
145
+ /**
146
+ * Get element at position
147
+ */
148
+ export declare const parallelMatrixSubset: import("typed-function").TypedFunction;
149
+ /**
150
+ * Get row from matrix
151
+ */
152
+ export declare const parallelMatrixRow: import("typed-function").TypedFunction;
153
+ /**
154
+ * Get column from matrix
155
+ */
156
+ export declare const parallelMatrixColumn: import("typed-function").TypedFunction;
157
+ /**
158
+ * Get diagonal from matrix
159
+ */
160
+ export declare const parallelMatrixDiagonal: import("typed-function").TypedFunction;
161
+ /**
162
+ * Parallel matrix-vector multiplication
163
+ */
164
+ export declare const parallelMatrixMatvec: import("typed-function").TypedFunction;
165
+ /**
166
+ * Parallel outer product
167
+ */
168
+ export declare const parallelMatrixOuter: import("typed-function").TypedFunction;
169
+ /**
170
+ * Parallel histogram computation
171
+ */
172
+ export declare const parallelMatrixHistogram: import("typed-function").TypedFunction;
173
+ export declare const parallelMatrixOperations: {
174
+ matrix: import("typed-function").TypedFunction;
175
+ identity: import("typed-function").TypedFunction;
176
+ zeros: import("typed-function").TypedFunction;
177
+ ones: import("typed-function").TypedFunction;
178
+ diag: import("typed-function").TypedFunction;
179
+ random: import("typed-function").TypedFunction;
180
+ add: import("typed-function").TypedFunction;
181
+ subtract: import("typed-function").TypedFunction;
182
+ multiply: import("typed-function").TypedFunction;
183
+ dotMultiply: import("typed-function").TypedFunction;
184
+ divide: import("typed-function").TypedFunction;
185
+ unaryMinus: import("typed-function").TypedFunction;
186
+ transpose: import("typed-function").TypedFunction;
187
+ sum: import("typed-function").TypedFunction;
188
+ mean: import("typed-function").TypedFunction;
189
+ min: import("typed-function").TypedFunction;
190
+ max: import("typed-function").TypedFunction;
191
+ variance: import("typed-function").TypedFunction;
192
+ std: import("typed-function").TypedFunction;
193
+ norm: import("typed-function").TypedFunction;
194
+ dot: import("typed-function").TypedFunction;
195
+ trace: import("typed-function").TypedFunction;
196
+ distance: import("typed-function").TypedFunction;
197
+ abs: import("typed-function").TypedFunction;
198
+ sqrt: import("typed-function").TypedFunction;
199
+ square: import("typed-function").TypedFunction;
200
+ exp: import("typed-function").TypedFunction;
201
+ log: import("typed-function").TypedFunction;
202
+ sin: import("typed-function").TypedFunction;
203
+ cos: import("typed-function").TypedFunction;
204
+ tan: import("typed-function").TypedFunction;
205
+ size: import("typed-function").TypedFunction;
206
+ subset: import("typed-function").TypedFunction;
207
+ row: import("typed-function").TypedFunction;
208
+ column: import("typed-function").TypedFunction;
209
+ diagonal: import("typed-function").TypedFunction;
210
+ matvec: import("typed-function").TypedFunction;
211
+ outer: import("typed-function").TypedFunction;
212
+ histogram: import("typed-function").TypedFunction;
213
+ };
214
+ /**
215
+ * Initialize parallel matrix operations
216
+ */
217
+ export declare function initializeParallelMatrix(): Promise<void>;
218
+ /**
219
+ * Terminate parallel matrix operations pool
220
+ */
221
+ export declare function terminateParallelMatrix(): Promise<void>;
222
+ //# 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":"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"}
@@ -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";