@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.
- package/dist/backends/Backend.d.ts +146 -0
- package/dist/backends/Backend.d.ts.map +1 -0
- package/dist/backends/BackendManager.d.ts +189 -0
- package/dist/backends/BackendManager.d.ts.map +1 -0
- package/dist/backends/GPUBackend.d.ts +128 -0
- package/dist/backends/GPUBackend.d.ts.map +1 -0
- package/dist/backends/GPUMatrixBackend.d.ts +123 -0
- package/dist/backends/GPUMatrixBackend.d.ts.map +1 -0
- package/dist/backends/JSBackend.d.ts +93 -0
- package/dist/backends/JSBackend.d.ts.map +1 -0
- package/dist/backends/ParallelBackend.d.ts +131 -0
- package/dist/backends/ParallelBackend.d.ts.map +1 -0
- package/dist/backends/WASMBackend.d.ts +156 -0
- package/dist/backends/WASMBackend.d.ts.map +1 -0
- package/dist/backends/WasmLoader.d.ts +326 -0
- package/dist/backends/WasmLoader.d.ts.map +1 -0
- package/dist/backends/gpu/BatchExecutor.d.ts +190 -0
- package/dist/backends/gpu/BatchExecutor.d.ts.map +1 -0
- package/dist/backends/gpu/Sync.d.ts +167 -0
- package/dist/backends/gpu/Sync.d.ts.map +1 -0
- package/dist/backends/gpu/builtin-shaders.d.ts +178 -0
- package/dist/backends/gpu/builtin-shaders.d.ts.map +1 -0
- package/dist/backends/gpu/index.d.ts +13 -0
- package/dist/backends/gpu/index.d.ts.map +1 -0
- package/dist/backends/index.d.ts +18 -0
- package/dist/backends/index.d.ts.map +1 -0
- package/dist/backends/register-backends.d.ts +18 -0
- package/dist/backends/register-backends.d.ts.map +1 -0
- package/dist/backends/wasm/detect.d.ts +58 -0
- package/dist/backends/wasm/detect.d.ts.map +1 -0
- package/dist/backends/wasm/fft-wasm.d.ts +120 -0
- package/dist/backends/wasm/fft-wasm.d.ts.map +1 -0
- package/dist/backends/wasm/index.d.ts +9 -0
- package/dist/backends/wasm/index.d.ts.map +1 -0
- package/dist/backends/wasm/integrity.d.ts +18 -0
- package/dist/backends/wasm/integrity.d.ts.map +1 -0
- package/dist/backends/wasm/resolve.d.ts +12 -0
- package/dist/backends/wasm/resolve.d.ts.map +1 -0
- package/dist/{chunk-4VMDO6W2.js → chunk-PNKVD2UK.js} +2 -7
- package/dist/config.d.ts +145 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/index.d.ts +14 -3037
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -9
- package/dist/{integrity-LIWCCDIJ.js → integrity-IBNQNHXP.js} +1 -1
- package/dist/operations/cholesky.d.ts +24 -0
- package/dist/operations/cholesky.d.ts.map +1 -0
- package/dist/operations/common.d.ts +61 -0
- package/dist/operations/common.d.ts.map +1 -0
- package/dist/operations/condest.d.ts +27 -0
- package/dist/operations/condest.d.ts.map +1 -0
- package/dist/operations/eig-wasm.d.ts +35 -0
- package/dist/operations/eig-wasm.d.ts.map +1 -0
- package/dist/operations/eig.d.ts +75 -0
- package/dist/operations/eig.d.ts.map +1 -0
- package/dist/operations/expm.d.ts +46 -0
- package/dist/operations/expm.d.ts.map +1 -0
- package/dist/operations/index.d.ts +21 -0
- package/dist/operations/index.d.ts.map +1 -0
- package/dist/operations/logm.d.ts +59 -0
- package/dist/operations/logm.d.ts.map +1 -0
- package/dist/operations/lu.d.ts +51 -0
- package/dist/operations/lu.d.ts.map +1 -0
- package/dist/operations/pinv.d.ts +36 -0
- package/dist/operations/pinv.d.ts.map +1 -0
- package/dist/operations/qr-family.d.ts +52 -0
- package/dist/operations/qr-family.d.ts.map +1 -0
- package/dist/operations/qr-pivoted.d.ts +39 -0
- package/dist/operations/qr-pivoted.d.ts.map +1 -0
- package/dist/operations/qr.d.ts +35 -0
- package/dist/operations/qr.d.ts.map +1 -0
- package/dist/operations/schur.d.ts +58 -0
- package/dist/operations/schur.d.ts.map +1 -0
- package/dist/operations/sqrtm.d.ts +76 -0
- package/dist/operations/sqrtm.d.ts.map +1 -0
- package/dist/operations/svd-wasm.d.ts +23 -0
- package/dist/operations/svd-wasm.d.ts.map +1 -0
- package/dist/operations/svd.d.ts +70 -0
- package/dist/operations/svd.d.ts.map +1 -0
- package/dist/parallel-matrix.d.ts +222 -0
- package/dist/parallel-matrix.d.ts.map +1 -0
- package/dist/{resolve-DDCEWHWX.js → resolve-2SX6WJ6R.js} +1 -1
- package/dist/typed-operations.d.ts +161 -0
- package/dist/typed-operations.d.ts.map +1 -0
- package/dist/types/DenseMatrix.d.ts +213 -0
- package/dist/types/DenseMatrix.d.ts.map +1 -0
- package/dist/types/Matrix.d.ts +188 -0
- package/dist/types/Matrix.d.ts.map +1 -0
- package/dist/types/SparseMatrix.d.ts +214 -0
- package/dist/types/SparseMatrix.d.ts.map +1 -0
- package/dist/types/dense/arithmetic.d.ts +8 -0
- package/dist/types/dense/arithmetic.d.ts.map +1 -0
- package/dist/types/dense/reduction.d.ts +8 -0
- package/dist/types/dense/reduction.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/wasm/mathts-as.wasm +0 -0
- package/dist/wasm/wasm-manifest.json +1 -1
- package/package.json +70 -70
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,cAAc,kBAAkB,CAAC;AAGjC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,uBAAuB,CAAC;AAGtC,cAAc,uBAAuB,CAAC;AAItC,cAAc,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
__esm,
|
|
3
3
|
__export,
|
|
4
4
|
__toCommonJS
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-PNKVD2UK.js";
|
|
6
6
|
|
|
7
7
|
// src/types/Matrix.ts
|
|
8
8
|
function isMatrix(value) {
|
|
@@ -2499,7 +2499,7 @@ var WASMBackend = class {
|
|
|
2499
2499
|
*/
|
|
2500
2500
|
async resolveAsWasmPath() {
|
|
2501
2501
|
const isNode = typeof process !== "undefined" && process.versions?.node !== void 0;
|
|
2502
|
-
const { resolvePackagedWasm, defaultWasmLocation } = await import("./resolve-
|
|
2502
|
+
const { resolvePackagedWasm, defaultWasmLocation } = await import("./resolve-2SX6WJ6R.js");
|
|
2503
2503
|
if (isNode) {
|
|
2504
2504
|
const found = await resolvePackagedWasm(import.meta.url, "mathts-as.wasm");
|
|
2505
2505
|
if (found) return found;
|
|
@@ -2525,7 +2525,7 @@ var WASMBackend = class {
|
|
|
2525
2525
|
Date
|
|
2526
2526
|
};
|
|
2527
2527
|
const isNode = typeof process !== "undefined" && process.versions?.node !== void 0;
|
|
2528
|
-
const { loadWasmManifest, verifyWasmIntegrity } = await import("./integrity-
|
|
2528
|
+
const { loadWasmManifest, verifyWasmIntegrity } = await import("./integrity-IBNQNHXP.js");
|
|
2529
2529
|
let instance;
|
|
2530
2530
|
if (isNode) {
|
|
2531
2531
|
const fs = await import("fs");
|
|
@@ -4289,7 +4289,7 @@ var WasmLoader = class _WasmLoader {
|
|
|
4289
4289
|
if (this.compiledModule) return;
|
|
4290
4290
|
const path = wasmPath || await this.getDefaultWasmPath();
|
|
4291
4291
|
const startTime = performance.now();
|
|
4292
|
-
const { loadWasmManifest, verifyWasmIntegrity } = await import("./integrity-
|
|
4292
|
+
const { loadWasmManifest, verifyWasmIntegrity } = await import("./integrity-IBNQNHXP.js");
|
|
4293
4293
|
if (this.isNode) {
|
|
4294
4294
|
const fs = await import("fs");
|
|
4295
4295
|
const { promisify } = await import("util");
|
|
@@ -4350,20 +4350,20 @@ var WasmLoader = class _WasmLoader {
|
|
|
4350
4350
|
async getDefaultWasmPath() {
|
|
4351
4351
|
const wasmFile = "mathts-as.wasm";
|
|
4352
4352
|
if (this.isNode) {
|
|
4353
|
-
const { resolvePackagedWasm } = await import("./resolve-
|
|
4353
|
+
const { resolvePackagedWasm } = await import("./resolve-2SX6WJ6R.js");
|
|
4354
4354
|
const found = await resolvePackagedWasm(import.meta.url, wasmFile);
|
|
4355
4355
|
if (found) return found;
|
|
4356
|
-
const { defaultWasmLocation: defaultWasmLocation2 } = await import("./resolve-
|
|
4356
|
+
const { defaultWasmLocation: defaultWasmLocation2 } = await import("./resolve-2SX6WJ6R.js");
|
|
4357
4357
|
return defaultWasmLocation2(import.meta.url, wasmFile);
|
|
4358
4358
|
}
|
|
4359
|
-
const { defaultWasmLocation } = await import("./resolve-
|
|
4359
|
+
const { defaultWasmLocation } = await import("./resolve-2SX6WJ6R.js");
|
|
4360
4360
|
return defaultWasmLocation(import.meta.url, wasmFile, { browser: true });
|
|
4361
4361
|
}
|
|
4362
4362
|
async loadNodeWasm(path, totalStart) {
|
|
4363
4363
|
const fs = await import("fs");
|
|
4364
4364
|
const { promisify } = await import("util");
|
|
4365
4365
|
const readFile = promisify(fs.readFile);
|
|
4366
|
-
const { verifyWasmIntegrity } = await import("./integrity-
|
|
4366
|
+
const { verifyWasmIntegrity } = await import("./integrity-IBNQNHXP.js");
|
|
4367
4367
|
const readStart = performance.now();
|
|
4368
4368
|
const buffer = await readFile(path);
|
|
4369
4369
|
const readEnd = performance.now();
|
|
@@ -4384,7 +4384,7 @@ var WasmLoader = class _WasmLoader {
|
|
|
4384
4384
|
return instance.exports;
|
|
4385
4385
|
}
|
|
4386
4386
|
async loadBrowserWasm(path, totalStart) {
|
|
4387
|
-
const { loadWasmManifest, verifyWasmIntegrity } = await import("./integrity-
|
|
4387
|
+
const { loadWasmManifest, verifyWasmIntegrity } = await import("./integrity-IBNQNHXP.js");
|
|
4388
4388
|
const manifest = await loadWasmManifest(path);
|
|
4389
4389
|
if (!manifest && typeof WebAssembly.instantiateStreaming === "function") {
|
|
4390
4390
|
const instStart2 = performance.now();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cholesky Decomposition (DenseMatrix primitive)
|
|
3
|
+
*
|
|
4
|
+
* Right-looking algorithm. Factorises a symmetric positive-definite (SPD)
|
|
5
|
+
* matrix A into A = L · Lᵀ where L is lower-triangular.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* const { L } = cholesky(A);
|
|
9
|
+
* // A ≈ L · L^T (to floating-point precision)
|
|
10
|
+
*/
|
|
11
|
+
import { DenseMatrix } from '../types/DenseMatrix.js';
|
|
12
|
+
export interface CholeskyResult {
|
|
13
|
+
/** Lower-triangular Cholesky factor L such that A = L · Lᵀ. */
|
|
14
|
+
L: DenseMatrix;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Compute the Cholesky decomposition of the symmetric positive-definite
|
|
18
|
+
* `DenseMatrix` A such that A = L · Lᵀ.
|
|
19
|
+
*
|
|
20
|
+
* @throws {Error} if `A` is not square.
|
|
21
|
+
* @throws {Error} if `A` is not positive definite (non-positive diagonal pivot).
|
|
22
|
+
*/
|
|
23
|
+
export declare function cholesky(A: DenseMatrix): CholeskyResult;
|
|
24
|
+
//# sourceMappingURL=cholesky.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cholesky.d.ts","sourceRoot":"","sources":["../../src/operations/cholesky.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,MAAM,WAAW,cAAc;IAC7B,+DAA+D;IAC/D,CAAC,EAAE,WAAW,CAAC;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,WAAW,GAAG,cAAc,CA+BvD"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared decomposition helpers (number[][] dense algebra)
|
|
3
|
+
*
|
|
4
|
+
* Canonical home for small matrix utilities that were previously duplicated
|
|
5
|
+
* across the decomposition modules (eig, svd, schur, expm, logm, sqrtm). All
|
|
6
|
+
* functions operate on plain 2-D `number[][]` arrays and are behavior-identical
|
|
7
|
+
* to the per-file copies they replace.
|
|
8
|
+
*
|
|
9
|
+
* NOTE on `householder`: the degenerate "x is a negative multiple of e_1"
|
|
10
|
+
* branch returns a parameterized `beta`. eig/svd use `beta = -2` (the default);
|
|
11
|
+
* schur deliberately uses `beta = 2` (H = I − 2·e_1·e_1ᵀ = diag(−1, 1, …, 1)).
|
|
12
|
+
* This intentional divergence is preserved by passing the desired value.
|
|
13
|
+
*/
|
|
14
|
+
/** Create an n × n identity matrix. */
|
|
15
|
+
export declare function eye(n: number): number[][];
|
|
16
|
+
/** Clone a matrix (deep copy of rows). */
|
|
17
|
+
export declare function cloneMatrix(A: number[][]): number[][];
|
|
18
|
+
/** Transpose a matrix. */
|
|
19
|
+
export declare function transpose(A: number[][]): number[][];
|
|
20
|
+
/**
|
|
21
|
+
* Check if a matrix is symmetric to within tolerance.
|
|
22
|
+
* Returns true for empty matrices; false for non-square matrices.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isSymmetric(matrix: number[][], tolerance?: number): boolean;
|
|
25
|
+
/** Matrix multiply C = A × B. */
|
|
26
|
+
export declare function matMul(A: number[][], B: number[][]): number[][];
|
|
27
|
+
/** Matrix addition A + B (square inputs). */
|
|
28
|
+
export declare function matAdd(A: number[][], B: number[][]): number[][];
|
|
29
|
+
/** Matrix subtraction A − B (square inputs). */
|
|
30
|
+
export declare function matSub(A: number[][], B: number[][]): number[][];
|
|
31
|
+
/** Scalar multiply: c · A. */
|
|
32
|
+
export declare function matScale(A: number[][], c: number): number[][];
|
|
33
|
+
/** Infinity-norm proxy (max absolute entry). */
|
|
34
|
+
export declare function normInf(A: number[][]): number;
|
|
35
|
+
/** 1-norm of a matrix (max column sum of absolute values). */
|
|
36
|
+
export declare function norm1(A: number[][]): number;
|
|
37
|
+
/**
|
|
38
|
+
* Compute the Householder reflection vector for a column.
|
|
39
|
+
*
|
|
40
|
+
* For the degenerate case where `x` is a negative multiple of e_1
|
|
41
|
+
* (`sigma === 0 && x[0] < 0`), the returned `beta` is `degenerateBeta`:
|
|
42
|
+
* - eig / svd use the default `-2`.
|
|
43
|
+
* - schur passes `2` (its deliberate divergence — see module header).
|
|
44
|
+
*/
|
|
45
|
+
export declare function householder(x: number[], degenerateBeta?: number): {
|
|
46
|
+
v: number[];
|
|
47
|
+
beta: number;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Apply Householder reflection from the left: H = I − beta·v·vᵀ, computing
|
|
51
|
+
* H·A in-place over columns [startCol, A[0].length) and rows starting at
|
|
52
|
+
* `startRow` for `v.length` rows.
|
|
53
|
+
*/
|
|
54
|
+
export declare function applyHouseholderLeft(A: number[][], v: number[], beta: number, startRow: number, startCol: number): void;
|
|
55
|
+
/**
|
|
56
|
+
* Apply Householder reflection from the right: H = I − beta·v·vᵀ, computing
|
|
57
|
+
* A·H in-place over rows [startRow, A.length) and columns starting at
|
|
58
|
+
* `startCol` for `v.length` columns.
|
|
59
|
+
*/
|
|
60
|
+
export declare function applyHouseholderRight(A: number[][], v: number[], beta: number, startRow: number, startCol: number): void;
|
|
61
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/operations/common.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH,uCAAuC;AACvC,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CAIzC;AAED,0CAA0C;AAC1C,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAErD;AAED,0BAA0B;AAC1B,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAInD;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,GAAE,MAAc,GAAG,OAAO,CAalF;AAMD,iCAAiC;AACjC,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAa/D;AAED,6CAA6C;AAC7C,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAK/D;AAED,gDAAgD;AAChD,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAK/D;AAED,8BAA8B;AAC9B,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CAE7D;AAED,gDAAgD;AAChD,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,CAI7C;AAED,8DAA8D;AAC9D,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,CAU3C;AAMD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CACzB,CAAC,EAAE,MAAM,EAAE,EACX,cAAc,GAAE,MAAW,GAC1B;IAAE,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CA4B/B;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,CAAC,EAAE,MAAM,EAAE,EAAE,EACb,CAAC,EAAE,MAAM,EAAE,EACX,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,IAAI,CAcN;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,CAAC,EAAE,MAAM,EAAE,EAAE,EACb,CAAC,EAAE,MAAM,EAAE,EACX,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,IAAI,CAcN"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Condition-number ESTIMATE (Hager/Higham 1-norm power-iteration estimator)
|
|
3
|
+
*
|
|
4
|
+
* Estimates `‖A‖₁ · ‖A⁻¹‖₁` without ever forming `A⁻¹` explicitly — Hager's
|
|
5
|
+
* algorithm (Hager 1984; Higham 1988's practical refinement) needs only the
|
|
6
|
+
* ability to apply `A⁻¹` and `A⁻ᵀ` to a vector, which is done here via the
|
|
7
|
+
* existing `lu()` primitive's triangular factors (forward/back substitution,
|
|
8
|
+
* O(n²) per application vs. O(n³) to form `A⁻¹` or run the SVD-based exact
|
|
9
|
+
* `cond()` in `svd.ts`). The result is an ESTIMATE — typically a lower bound
|
|
10
|
+
* on the true `‖A⁻¹‖₁`, usually within a small constant factor — not the
|
|
11
|
+
* exact value.
|
|
12
|
+
*/
|
|
13
|
+
import { DenseMatrix } from '../types/DenseMatrix.js';
|
|
14
|
+
/**
|
|
15
|
+
* Estimate the 1-norm condition number `‖A‖₁ · ‖A⁻¹‖₁` of a square matrix.
|
|
16
|
+
*
|
|
17
|
+
* This is an ESTIMATE (Hager/Higham power iteration), not the exact
|
|
18
|
+
* condition number that `cond()` (in `svd.ts`) computes via a full SVD —
|
|
19
|
+
* `condest` is O(n²)-per-iteration and avoids forming `A⁻¹`, at the cost of
|
|
20
|
+
* being a (typically close) lower-bound estimate rather than an exact value.
|
|
21
|
+
*
|
|
22
|
+
* @param A - Square input matrix.
|
|
23
|
+
* @param p - Only the 1-norm (`p = 1`, the default) is currently implemented.
|
|
24
|
+
* @throws {Error} if `A` is not square, or `p !== 1`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function condest(A: DenseMatrix, p?: number): number;
|
|
27
|
+
//# sourceMappingURL=condest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condest.d.ts","sourceRoot":"","sources":["../../src/operations/condest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAuGtD;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,GAAE,MAAU,GAAG,MAAM,CAuC7D"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `eigWasm` / `eigvalsWasm` / `spectralRadiusWasm` — thin wrappers kept for API
|
|
3
|
+
* compatibility (consumed by `tensor` and `linalg`).
|
|
4
|
+
*
|
|
5
|
+
* The WASM eig path was RETIRED and REMOVED (2026-07-01): the AssemblyScript Jacobi
|
|
6
|
+
* (symmetric) / Hessenberg+Francis (general) kernels were scalar + async and measured
|
|
7
|
+
* 0.2–0.7× of the pure-JS path, worsening with size (~5× slower at 128²) — see
|
|
8
|
+
* `tools/benchmarks/decomp-audit`. Since a genuinely fast version would be a from-scratch
|
|
9
|
+
* SIMD implementation (not the removed scalar code), these now simply delegate to the
|
|
10
|
+
* synchronous JS `eig` / `eigvals` / `powerIteration`. The `async` signature is retained so
|
|
11
|
+
* existing callers (which `await`) are unaffected.
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*/
|
|
15
|
+
import { type EigResult, type EigOptions } from './eig.js';
|
|
16
|
+
/**
|
|
17
|
+
* Eigendecomposition. Delegates to the JS {@link eig} (WASM path retired — see file header).
|
|
18
|
+
*/
|
|
19
|
+
export declare function eigWasm(matrix: number[][], options?: EigOptions): Promise<EigResult>;
|
|
20
|
+
/**
|
|
21
|
+
* Eigenvalues only. Delegates to the JS {@link eigvals} (WASM path retired).
|
|
22
|
+
*/
|
|
23
|
+
export declare function eigvalsWasm(matrix: number[][], options?: Omit<EigOptions, 'computeVectors'>): Promise<Array<{
|
|
24
|
+
re: number;
|
|
25
|
+
im: number;
|
|
26
|
+
}>>;
|
|
27
|
+
/**
|
|
28
|
+
* Spectral radius (|largest eigenvalue|). Delegates to the JS {@link powerIteration}
|
|
29
|
+
* (WASM path retired).
|
|
30
|
+
*/
|
|
31
|
+
export declare function spectralRadiusWasm(matrix: number[][], options?: {
|
|
32
|
+
maxIterations?: number;
|
|
33
|
+
tolerance?: number;
|
|
34
|
+
}): Promise<number>;
|
|
35
|
+
//# sourceMappingURL=eig-wasm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eig-wasm.d.ts","sourceRoot":"","sources":["../../src/operations/eig-wasm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAgC,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAEzF;;GAEG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAW1F;AAED;;GAEG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,EAAE,EAAE,EAClB,OAAO,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,gBAAgB,CAAC,GAC3C,OAAO,CAAC,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAE5C;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EAAE,EAAE,EAClB,OAAO,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GACvD,OAAO,CAAC,MAAM,CAAC,CAGjB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Eigenvalue and Eigenvector Decomposition
|
|
3
|
+
*
|
|
4
|
+
* Implements eigenvalue computation using QR algorithm and
|
|
5
|
+
* eigenvector extraction using inverse iteration.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Result of eigenvalue decomposition
|
|
9
|
+
*/
|
|
10
|
+
export interface EigResult {
|
|
11
|
+
/** Eigenvalues (may be complex for non-symmetric matrices) */
|
|
12
|
+
values: Array<{
|
|
13
|
+
re: number;
|
|
14
|
+
im: number;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Eigenvectors as columns (each column is an eigenvector). For a real
|
|
18
|
+
* eigenvalue this is the full (real) eigenvector, unit-normalised. For a
|
|
19
|
+
* complex-conjugate eigenvalue pair this holds the REAL PART of the
|
|
20
|
+
* corresponding complex eigenvector — see {@link vectorsIm} for the
|
|
21
|
+
* imaginary part.
|
|
22
|
+
*/
|
|
23
|
+
vectors: number[][];
|
|
24
|
+
/**
|
|
25
|
+
* Imaginary parts of the eigenvector columns (same shape as {@link vectors}).
|
|
26
|
+
* All-zero for real eigenvalues. For a complex-conjugate eigenvalue pair at
|
|
27
|
+
* indices `j`/`j+1`, the full complex eigenvectors are
|
|
28
|
+
* `vectors[j] + i*vectorsIm[j]` (for `values[j]`) and
|
|
29
|
+
* `vectors[j+1] - i*vectorsIm[j] === vectors[j+1] + i*vectorsIm[j+1]` (for
|
|
30
|
+
* the conjugate `values[j+1]`), each unit-normalised by the complex 2-norm
|
|
31
|
+
* `sqrt(sum(re_i^2 + im_i^2))`.
|
|
32
|
+
*/
|
|
33
|
+
vectorsIm: number[][];
|
|
34
|
+
/** Whether the matrix was symmetric */
|
|
35
|
+
isSymmetric: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Options for eigenvalue computation
|
|
39
|
+
*/
|
|
40
|
+
export interface EigOptions {
|
|
41
|
+
/** Maximum number of QR iterations */
|
|
42
|
+
maxIterations?: number;
|
|
43
|
+
/** Convergence tolerance */
|
|
44
|
+
tolerance?: number;
|
|
45
|
+
/** Whether to compute eigenvectors */
|
|
46
|
+
computeVectors?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Compute eigenvalues and eigenvectors of a square matrix
|
|
50
|
+
* Uses QR algorithm with implicit shifts
|
|
51
|
+
*
|
|
52
|
+
* @param matrix - Square matrix (n x n)
|
|
53
|
+
* @param options - Computation options
|
|
54
|
+
* @returns Eigenvalues and eigenvectors
|
|
55
|
+
*/
|
|
56
|
+
export declare function eig(matrix: number[][] | Float64Array, options?: EigOptions): EigResult;
|
|
57
|
+
/**
|
|
58
|
+
* Compute only eigenvalues (faster, no eigenvector computation)
|
|
59
|
+
*/
|
|
60
|
+
export declare function eigvals(matrix: number[][] | Float64Array, options?: Omit<EigOptions, 'computeVectors'>): Array<{
|
|
61
|
+
re: number;
|
|
62
|
+
im: number;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Power iteration for dominant eigenvalue
|
|
66
|
+
* Faster than full eigendecomposition when only largest eigenvalue needed
|
|
67
|
+
*/
|
|
68
|
+
export declare function powerIteration(matrix: number[][], options?: {
|
|
69
|
+
maxIterations?: number;
|
|
70
|
+
tolerance?: number;
|
|
71
|
+
}): {
|
|
72
|
+
value: number;
|
|
73
|
+
vector: number[];
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=eig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eig.d.ts","sourceRoot":"","sources":["../../src/operations/eig.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,8DAA8D;IAC9D,MAAM,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1C;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC;IACpB;;;;;;;;OAQG;IACH,SAAS,EAAE,MAAM,EAAE,EAAE,CAAC;IACtB,uCAAuC;IACvC,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,sCAAsC;IACtC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,4BAA4B;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AA+hBD;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,GAAG,YAAY,EAAE,OAAO,GAAE,UAAe,GAAG,SAAS,CAiD1F;AAED;;GAEG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,MAAM,EAAE,EAAE,GAAG,YAAY,EACjC,OAAO,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,gBAAgB,CAAC,GAC3C,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,CAEnC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EAAE,EAAE,EAClB,OAAO,GAAE;IAAE,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAC3D;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAsCrC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matrix Exponential — Scaling-and-Squaring with Padé-13 Approximant
|
|
3
|
+
*
|
|
4
|
+
* Implements Algorithm 10.20 from:
|
|
5
|
+
* Higham, N. J. (2005). "The scaling and squaring method for the matrix
|
|
6
|
+
* exponential revisited." SIAM J. Matrix Anal. Appl., 26(4), 1179–1193.
|
|
7
|
+
*
|
|
8
|
+
* Algorithm:
|
|
9
|
+
* 1. Compute s = max(0, ceil(log2(||A||_1 / θ_13))) where θ_13 ≈ 5.372.
|
|
10
|
+
* 2. Scale: B = A / 2^s.
|
|
11
|
+
* 3. Compute the [13/13] Padé approximant R(B) = (U + V)^{-1} * (-U + V).
|
|
12
|
+
* 4. Square s times: expm(A) = R(B)^(2^s).
|
|
13
|
+
*
|
|
14
|
+
* Works for any real square DenseMatrix. For large ||A||, uses scaling to
|
|
15
|
+
* stay within the Padé approximant's accuracy radius.
|
|
16
|
+
*/
|
|
17
|
+
import { DenseMatrix } from '../types/DenseMatrix.js';
|
|
18
|
+
export interface ExpmOptions {
|
|
19
|
+
/**
|
|
20
|
+
* When true, return the result as a DenseMatrix.
|
|
21
|
+
* When false (default), work directly on the internal number[][] and
|
|
22
|
+
* return as DenseMatrix anyway — this option is reserved for future use.
|
|
23
|
+
*/
|
|
24
|
+
_reserved?: never;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Compute the matrix exponential of a square DenseMatrix.
|
|
28
|
+
*
|
|
29
|
+
* Uses the Padé-13 scaling-and-squaring algorithm (Higham 2005).
|
|
30
|
+
* Accurate to near machine precision for general real matrices.
|
|
31
|
+
*
|
|
32
|
+
* @param A - Square DenseMatrix (n × n).
|
|
33
|
+
* @returns expm(A) as a DenseMatrix (n × n).
|
|
34
|
+
* @throws Error if A is not square.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* // expm(0) = I
|
|
38
|
+
* matrixExpm(DenseMatrix.zeros(3, 3)) // => identity 3×3
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* // expm(t*I) = e^t * I
|
|
42
|
+
* const tI = DenseMatrix.fromArray([[2,0],[0,2]]);
|
|
43
|
+
* matrixExpm(tI) // => [[e^2, 0], [0, e^2]]
|
|
44
|
+
*/
|
|
45
|
+
export declare function matrixExpm(A: DenseMatrix): DenseMatrix;
|
|
46
|
+
//# sourceMappingURL=expm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expm.d.ts","sourceRoot":"","sources":["../../src/operations/expm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAmHtD,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,WAAW,GAAG,WAAW,CA+BtD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matrix Operations
|
|
3
|
+
*
|
|
4
|
+
* Exports all matrix decomposition and computation operations.
|
|
5
|
+
*/
|
|
6
|
+
export { eig, eigvals, powerIteration, type EigResult, type EigOptions } from './eig.js';
|
|
7
|
+
export { svd, singularValues, pinv, lowRankApprox, cond, norm2, normFro, type SVDResult, type SVDOptions, } from './svd.js';
|
|
8
|
+
export { eigWasm, eigvalsWasm, spectralRadiusWasm } from './eig-wasm.js';
|
|
9
|
+
export { svdWasm } from './svd-wasm.js';
|
|
10
|
+
export { pinv as matrixPinv, type PinvOptions } from './pinv.js';
|
|
11
|
+
export { qr, type QRResult, type QROptions } from './qr.js';
|
|
12
|
+
export { lu, luSolve, type LUResult } from './lu.js';
|
|
13
|
+
export { cholesky, type CholeskyResult } from './cholesky.js';
|
|
14
|
+
export { matrixExpm, type ExpmOptions } from './expm.js';
|
|
15
|
+
export { matrixLogm, type LogmOptions } from './logm.js';
|
|
16
|
+
export { matrixSqrtm, type SqrtmOptions } from './sqrtm.js';
|
|
17
|
+
export { matrixSchur, type SchurResult, type SchurOptions } from './schur.js';
|
|
18
|
+
export { qrPivoted, type QRPivotedResult, type QRPivotedOptions } from './qr-pivoted.js';
|
|
19
|
+
export { lq, rq, ql, type LQResult, type RQResult, type QLResult } from './qr-family.js';
|
|
20
|
+
export { condest } from './condest.js';
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/operations/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAGzF,OAAO,EACL,GAAG,EACH,cAAc,EACd,IAAI,EACJ,aAAa,EACb,IAAI,EACJ,KAAK,EACL,OAAO,EACP,KAAK,SAAS,EACd,KAAK,UAAU,GAChB,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGzE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAIxC,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAGjE,OAAO,EAAE,EAAE,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AAG5D,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGrD,OAAO,EAAE,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAG9D,OAAO,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAGzD,OAAO,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAGzD,OAAO,EAAE,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAG5D,OAAO,EAAE,WAAW,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAG9E,OAAO,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGzF,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAGzF,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matrix Logarithm — Schur-Padé inverse scaling-and-squaring (Slices 5.9a + 6.1)
|
|
3
|
+
*
|
|
4
|
+
* Implements the Schur-Padé algorithm based on:
|
|
5
|
+
* Higham (2008) "Functions of Matrices: Theory and Computation," Chapter 11
|
|
6
|
+
* (Algorithm 11.10).
|
|
7
|
+
*
|
|
8
|
+
* Algorithm (general Schur-based path, Slice 6.1):
|
|
9
|
+
* 1. Schur decompose: A = Q · T · Q^T.
|
|
10
|
+
* 2. Repeatedly take matrix square roots of T (Björck recurrence on upper-
|
|
11
|
+
* triangular matrices) until ||T^{1/2^k} - I||_1 < 0.25.
|
|
12
|
+
* 3. Evaluate log(I + X) via 16-point Gauss-Legendre quadrature.
|
|
13
|
+
* 4. Scale back by 2^k; rotate by Q: logm(A) = Q · (2^k · log(T^{1/2^k})) · Q^T.
|
|
14
|
+
*
|
|
15
|
+
* For the eig-based fallback (diagonalisable matrices with positive real
|
|
16
|
+
* eigenvalues): logm(A) = V · diag(log(λ)) · V^{-1}.
|
|
17
|
+
*/
|
|
18
|
+
import { DenseMatrix } from '../types/DenseMatrix.js';
|
|
19
|
+
export interface LogmOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Tolerance for the "near-identity" test.
|
|
22
|
+
* Default: 0.25 (||M - I||_1 < tol triggers Padé path).
|
|
23
|
+
*/
|
|
24
|
+
nearIdentityTol?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Compute the principal matrix logarithm of a square DenseMatrix.
|
|
28
|
+
*
|
|
29
|
+
* Algorithm (Slice 5.9a — inverse scaling-and-squaring + Padé quadrature):
|
|
30
|
+
* 1. Repeatedly take matrix square roots until ||M - I||_1 < nearIdentityTol.
|
|
31
|
+
* 2. Evaluate log(I + X) = X * ∫₀¹ (I + tX)^{-1} dt via 7-pt Gauss-Legendre.
|
|
32
|
+
* 3. Scale back: logm(A) = 2^k * log(A^{1/2^k}).
|
|
33
|
+
*
|
|
34
|
+
* Falls back to eigendecomposition if the square-root sequence diverges
|
|
35
|
+
* (i.e., if the matrix has no non-positive eigenvalues and is diagonalisable).
|
|
36
|
+
*
|
|
37
|
+
* Limitations (deferred to Slice 5.9b):
|
|
38
|
+
* - Matrices with non-positive real eigenvalues: principal log is undefined.
|
|
39
|
+
* - Matrices with complex eigenvalues: throws.
|
|
40
|
+
* - Non-diagonalisable (defective) matrices: eig-fallback also throws.
|
|
41
|
+
* - Full Schur-based inverse-scaling-and-squaring for general non-normal
|
|
42
|
+
* matrices.
|
|
43
|
+
*
|
|
44
|
+
* @param A - Square DenseMatrix with positive real eigenvalues.
|
|
45
|
+
* @returns logm(A) as a DenseMatrix.
|
|
46
|
+
* @throws Error for matrices with non-positive or complex eigenvalues.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* // logm(I) = 0
|
|
50
|
+
* matrixLogm(DenseMatrix.eye(3)) // => zero matrix
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* // Round-trip: expm(logm(A)) ≈ A
|
|
54
|
+
* const A = DenseMatrix.fromArray([[4, 1], [0, 9]]);
|
|
55
|
+
* const logA = matrixLogm(A);
|
|
56
|
+
* // expm(logA) ≈ A (to machine precision for diagonalisable A)
|
|
57
|
+
*/
|
|
58
|
+
export declare function matrixLogm(A: DenseMatrix, opts?: LogmOptions): DenseMatrix;
|
|
59
|
+
//# sourceMappingURL=logm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logm.d.ts","sourceRoot":"","sources":["../../src/operations/logm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAiXtD,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,WAAW,CAyD1E"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LU Decomposition (DenseMatrix primitive)
|
|
3
|
+
*
|
|
4
|
+
* Doolittle's algorithm with partial (row) pivoting. Factorises a square
|
|
5
|
+
* matrix A into P · A = L · U where:
|
|
6
|
+
* - L is unit lower-triangular (1s on the diagonal).
|
|
7
|
+
* - U is upper-triangular.
|
|
8
|
+
* - P is returned as a row-permutation array: P[i] is the original-row
|
|
9
|
+
* index now at position i after pivoting.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* const { L, U, P } = lu(A);
|
|
13
|
+
* // P[i] gives the original row moved to position i, so P · A = L · U.
|
|
14
|
+
*/
|
|
15
|
+
import { DenseMatrix } from '../types/DenseMatrix.js';
|
|
16
|
+
export interface LUResult {
|
|
17
|
+
/** Unit lower-triangular factor L. */
|
|
18
|
+
L: DenseMatrix;
|
|
19
|
+
/** Upper-triangular factor U. */
|
|
20
|
+
U: DenseMatrix;
|
|
21
|
+
/** Row permutation array of length n. P[i] is the original-row index now at position i. */
|
|
22
|
+
P: number[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Perform LU decomposition with partial pivoting on a square `DenseMatrix`.
|
|
26
|
+
*
|
|
27
|
+
* Implements Doolittle's algorithm in compact form: the working array stores
|
|
28
|
+
* L below the diagonal (unit diagonal implicit) and U on and above it.
|
|
29
|
+
*
|
|
30
|
+
* @throws {Error} if `A` is not square.
|
|
31
|
+
* @throws {Error} if `A` is singular (zero pivot encountered).
|
|
32
|
+
*/
|
|
33
|
+
export declare function lu(A: DenseMatrix): LUResult;
|
|
34
|
+
/**
|
|
35
|
+
* Solve the dense linear system `A · x = b` using a precomputed LU factorisation
|
|
36
|
+
* (from {@link lu}), where `P · A = L · U`.
|
|
37
|
+
*
|
|
38
|
+
* Applies the row permutation to `b` (`(P·b)[i] = b[P[i]]`), forward-substitutes
|
|
39
|
+
* the unit-lower-triangular `L`, then back-substitutes the upper-triangular `U`.
|
|
40
|
+
* Each call is O(n²), so factor **once** with `lu()` and call `luSolve` repeatedly
|
|
41
|
+
* to solve many right-hand sides against the same matrix — the pattern the stiff
|
|
42
|
+
* Rosenbrock/RODAS ODE steps use (the iteration matrix is solved against 3–6
|
|
43
|
+
* successive RHS per step).
|
|
44
|
+
*
|
|
45
|
+
* @param fac An `LUResult` produced by {@link lu}.
|
|
46
|
+
* @param b Right-hand side vector of length `n` (`number[]` or `Float64Array`).
|
|
47
|
+
* @returns The solution vector `x` as a `number[]` of length `n`.
|
|
48
|
+
* @throws {Error} if `b.length` does not equal the factor dimension `n`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function luSolve(fac: LUResult, b: ArrayLike<number>): number[];
|
|
51
|
+
//# sourceMappingURL=lu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lu.d.ts","sourceRoot":"","sources":["../../src/operations/lu.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,MAAM,WAAW,QAAQ;IACvB,sCAAsC;IACtC,CAAC,EAAE,WAAW,CAAC;IACf,iCAAiC;IACjC,CAAC,EAAE,WAAW,CAAC;IACf,2FAA2F;IAC3F,CAAC,EAAE,MAAM,EAAE,CAAC;CACb;AAED;;;;;;;;GAQG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,WAAW,GAAG,QAAQ,CAuE3C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CA2BrE"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moore-Penrose Pseudoinverse (DenseMatrix primitive)
|
|
3
|
+
*
|
|
4
|
+
* Computes the pseudoinverse A⁺ of a DenseMatrix A via full SVD with
|
|
5
|
+
* rcond·max(S) singular-value thresholding.
|
|
6
|
+
*
|
|
7
|
+
* Algorithm:
|
|
8
|
+
* 1. Full SVD: A = U · diag(S) · Vᵀ (A is m×n)
|
|
9
|
+
* U: m×m orthogonal, V: n×n orthogonal, S: min(m,n) values (descending).
|
|
10
|
+
* 2. Threshold: s_inv_i = 1/s_i if s_i > rcond·max(S), else 0.
|
|
11
|
+
* 3. Build: A⁺ = V · diag(s_inv) · Uᵀ (shape: n×m).
|
|
12
|
+
*
|
|
13
|
+
* Satisfies all four Moore-Penrose identities within numerical precision:
|
|
14
|
+
* A · A⁺ · A = A
|
|
15
|
+
* A⁺ · A · A⁺ = A⁺
|
|
16
|
+
* (A · A⁺)ᵀ = A · A⁺
|
|
17
|
+
* (A⁺ · A)ᵀ = A⁺ · A
|
|
18
|
+
*/
|
|
19
|
+
import { DenseMatrix } from '../types/DenseMatrix.js';
|
|
20
|
+
export interface PinvOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Relative condition threshold for singular-value truncation.
|
|
23
|
+
* A singular value s_i is treated as zero when s_i ≤ rcond · max(S).
|
|
24
|
+
* Default: 1e-10.
|
|
25
|
+
*/
|
|
26
|
+
rcond?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Compute the Moore-Penrose pseudoinverse of a DenseMatrix.
|
|
30
|
+
*
|
|
31
|
+
* @param A - Input matrix (m × n).
|
|
32
|
+
* @param opts - Optional rcond threshold (default 1e-10).
|
|
33
|
+
* @returns A⁺, the pseudoinverse of A (n × m).
|
|
34
|
+
*/
|
|
35
|
+
export declare function pinv(A: DenseMatrix, opts?: PinvOptions): DenseMatrix;
|
|
36
|
+
//# sourceMappingURL=pinv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pinv.d.ts","sourceRoot":"","sources":["../../src/operations/pinv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,WAAW,CAoCpE"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QR-family decompositions: LQ, RQ, QL
|
|
3
|
+
*
|
|
4
|
+
* Each is derived from the existing Gram-Schmidt `qr()` primitive in this
|
|
5
|
+
* directory via the standard flip/transpose reductions (Golub & Van Loan,
|
|
6
|
+
* *Matrix Computations*, §5.2):
|
|
7
|
+
*
|
|
8
|
+
* - **LQ** (`A = L·Q`, L lower-triangular): `qr(Aᵀ)` transposed — no flips
|
|
9
|
+
* needed. If `Aᵀ = Q₁·R₁` then `A = R₁ᵀ·Q₁ᵀ`, so `L = R₁ᵀ`, `Q = Q₁ᵀ`.
|
|
10
|
+
* - **RQ** (`A = R·Q`, R upper-triangular): reverse `A`'s row order,
|
|
11
|
+
* transpose, run `qr()`, then un-flip the resulting factors.
|
|
12
|
+
* - **QL** (`A = Q·L`, L lower-triangular): reverse `A`'s column order,
|
|
13
|
+
* run `qr()`, then un-flip the resulting factors.
|
|
14
|
+
*
|
|
15
|
+
* All three share `qr()`'s reduced-QR convention: for an m×n input the thin
|
|
16
|
+
* factor pairing is (m×k, k×n) with k = min(m, n).
|
|
17
|
+
*/
|
|
18
|
+
import { DenseMatrix } from '../types/DenseMatrix.js';
|
|
19
|
+
export interface LQResult {
|
|
20
|
+
/** Lower-triangular (trapezoidal) factor. m × k, k = min(m, n). */
|
|
21
|
+
L: DenseMatrix;
|
|
22
|
+
/** Orthonormal-row factor (Q · Qᵀ = I). k × n. */
|
|
23
|
+
Q: DenseMatrix;
|
|
24
|
+
}
|
|
25
|
+
export interface RQResult {
|
|
26
|
+
/** Upper-triangular (trapezoidal) factor. m × k, k = min(m, n). */
|
|
27
|
+
R: DenseMatrix;
|
|
28
|
+
/** Orthonormal-row factor (Q · Qᵀ = I). k × n. */
|
|
29
|
+
Q: DenseMatrix;
|
|
30
|
+
}
|
|
31
|
+
export interface QLResult {
|
|
32
|
+
/** Orthonormal-column factor (Qᵀ · Q = I). m × k, k = min(m, n). */
|
|
33
|
+
Q: DenseMatrix;
|
|
34
|
+
/** Lower-triangular (trapezoidal) factor. k × n. */
|
|
35
|
+
L: DenseMatrix;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* LQ decomposition: `A = L · Q` with `L` lower-triangular and `Q` having
|
|
39
|
+
* orthonormal rows (`Q · Qᵀ = I`).
|
|
40
|
+
*/
|
|
41
|
+
export declare function lq(A: DenseMatrix): LQResult;
|
|
42
|
+
/**
|
|
43
|
+
* RQ decomposition: `A = R · Q` with `R` upper-triangular and `Q` having
|
|
44
|
+
* orthonormal rows (`Q · Qᵀ = I`).
|
|
45
|
+
*/
|
|
46
|
+
export declare function rq(A: DenseMatrix): RQResult;
|
|
47
|
+
/**
|
|
48
|
+
* QL decomposition: `A = Q · L` with `Q` having orthonormal columns
|
|
49
|
+
* (`Qᵀ · Q = I`) and `L` lower-triangular.
|
|
50
|
+
*/
|
|
51
|
+
export declare function ql(A: DenseMatrix): QLResult;
|
|
52
|
+
//# sourceMappingURL=qr-family.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qr-family.d.ts","sourceRoot":"","sources":["../../src/operations/qr-family.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,MAAM,WAAW,QAAQ;IACvB,mEAAmE;IACnE,CAAC,EAAE,WAAW,CAAC;IACf,kDAAkD;IAClD,CAAC,EAAE,WAAW,CAAC;CAChB;AAED,MAAM,WAAW,QAAQ;IACvB,mEAAmE;IACnE,CAAC,EAAE,WAAW,CAAC;IACf,kDAAkD;IAClD,CAAC,EAAE,WAAW,CAAC;CAChB;AAED,MAAM,WAAW,QAAQ;IACvB,oEAAoE;IACpE,CAAC,EAAE,WAAW,CAAC;IACf,oDAAoD;IACpD,CAAC,EAAE,WAAW,CAAC;CAChB;AA8BD;;;GAGG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,WAAW,GAAG,QAAQ,CAG3C;AAED;;;GAGG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,WAAW,GAAG,QAAQ,CAM3C;AAED;;;GAGG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,WAAW,GAAG,QAAQ,CAM3C"}
|