@danielsimonjr/mathts-matrix 0.6.3 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2278,6 +2278,23 @@ interface LUResult {
2278
2278
  * @throws {Error} if `A` is singular (zero pivot encountered).
2279
2279
  */
2280
2280
  declare function lu(A: DenseMatrix): LUResult;
2281
+ /**
2282
+ * Solve the dense linear system `A · x = b` using a precomputed LU factorisation
2283
+ * (from {@link lu}), where `P · A = L · U`.
2284
+ *
2285
+ * Applies the row permutation to `b` (`(P·b)[i] = b[P[i]]`), forward-substitutes
2286
+ * the unit-lower-triangular `L`, then back-substitutes the upper-triangular `U`.
2287
+ * Each call is O(n²), so factor **once** with `lu()` and call `luSolve` repeatedly
2288
+ * to solve many right-hand sides against the same matrix — the pattern the stiff
2289
+ * Rosenbrock/RODAS ODE steps use (the iteration matrix is solved against 3–6
2290
+ * successive RHS per step).
2291
+ *
2292
+ * @param fac An `LUResult` produced by {@link lu}.
2293
+ * @param b Right-hand side vector of length `n` (`number[]` or `Float64Array`).
2294
+ * @returns The solution vector `x` as a `number[]` of length `n`.
2295
+ * @throws {Error} if `b.length` does not equal the factor dimension `n`.
2296
+ */
2297
+ declare function luSolve(fac: LUResult, b: ArrayLike<number>): number[];
2281
2298
 
2282
2299
  /**
2283
2300
  * Cholesky Decomposition (DenseMatrix primitive)
@@ -3024,4 +3041,4 @@ declare function initializeParallelMatrix(): Promise<void>;
3024
3041
  */
3025
3042
  declare function terminateParallelMatrix(): Promise<void>;
3026
3043
 
3027
- export { BUILTIN_SHADERS, type BackendHints, BackendManager, BackendRegistry, type BackendType, BatchExecutor, type CholeskyResult, DEFAULT_BACKEND_HINTS, DEFAULT_EXTENDED_HINTS, DenseMatrix, type EigOptions, type EigResult, type ExpmOptions, type ExtendedBackendHints, GPUBackend, type GPUBackendOptions, type GPUBackendStatus, GPUMatrixBackend, type GPUMatrixBackendConfig, JSBackend, type LQResult, type LUResult, type LogmOptions, Matrix, type MatrixBackend, type MatrixEntry, type MatrixIndex, type MatrixType, type OperationType, ParallelBackend, type ParallelBackendConfig, type PinvOptions, type QLResult, type QROptions, type QRPivotedOptions, type QRPivotedResult, type QRResult, type RQResult, type SVDOptions, type SVDResult, type SchurOptions, type SchurResult, type SliceSpec, SparseMatrix, type SqrtmOptions, type SyncConfig, SyncManager, type SyncStrategy, WASMBackend, type WASMBackendConfig, type WasmFeatures, abs, add, backendManager, backendRegistry, cholesky, clearFeatureCache, column, cond, condest, createBackendManager, createGPUMatrixBackend, createParallelBackend, createSyncManager, createWASMBackend, destroyGlobalGPUBackend, detectWasmFeatures, diag, diagonal, divide, dotMultiply, eig, eigWasm, eigvals, eigvalsWasm, exp, getCachedFeatures, getGlobalGPUBackend, gpuMatrixBackend, identity, initializeGlobalGPUBackend, initializeParallelMatrix, isAtomicsAvailable, isDenseMatrix, isMatrix, isSharedMemoryAvailable, isSparseMatrix, isWasmAvailable, jsBackend, log, lowRankApprox, lq, lu, matrix, matrixExpm, matrixLogm, pinv as matrixPinv, matrixSchur, matrixSqrtm, max, mean, min, multiply, norm, norm2, normFro, ones, parallelBackend, parallelDiag, parallelDotMultiply, parallelIdentity, parallelMatrix, parallelMatrixAbs, parallelMatrixAdd, parallelMatrixColumn, parallelMatrixCos, parallelMatrixDiagonal, parallelMatrixDistance, parallelMatrixDivide, parallelMatrixDot, parallelMatrixExp, parallelMatrixHistogram, parallelMatrixLog, parallelMatrixMatvec, parallelMatrixMax, parallelMatrixMean, parallelMatrixMin, parallelMatrixMultiply, parallelMatrixNorm, parallelMatrixOperations, parallelMatrixOuter, parallelMatrixRow, parallelMatrixSin, parallelMatrixSize, parallelMatrixSqrt, parallelMatrixSquare, parallelMatrixStd, parallelMatrixSubset, parallelMatrixSubtract, parallelMatrixSum, parallelMatrixTan, parallelMatrixTrace, parallelMatrixTranspose, parallelMatrixVariance, parallelOnes, parallelRandom, parallelUnaryMinus, parallelZeros, pinv$1 as pinv, pow, powerIteration, ql, qr, qrPivoted, random, row, rq, singularValues, size, spectralRadiusWasm, sqrt, square, subset, subtract, sum, svd, svdWasm, terminateParallelMatrix, trace, transpose, typedMatrixOperations, unaryMinus, wasmBackend, zeros };
3044
+ export { BUILTIN_SHADERS, type BackendHints, BackendManager, BackendRegistry, type BackendType, BatchExecutor, type CholeskyResult, DEFAULT_BACKEND_HINTS, DEFAULT_EXTENDED_HINTS, DenseMatrix, type EigOptions, type EigResult, type ExpmOptions, type ExtendedBackendHints, GPUBackend, type GPUBackendOptions, type GPUBackendStatus, GPUMatrixBackend, type GPUMatrixBackendConfig, JSBackend, type LQResult, type LUResult, type LogmOptions, Matrix, type MatrixBackend, type MatrixEntry, type MatrixIndex, type MatrixType, type OperationType, ParallelBackend, type ParallelBackendConfig, type PinvOptions, type QLResult, type QROptions, type QRPivotedOptions, type QRPivotedResult, type QRResult, type RQResult, type SVDOptions, type SVDResult, type SchurOptions, type SchurResult, type SliceSpec, SparseMatrix, type SqrtmOptions, type SyncConfig, SyncManager, type SyncStrategy, WASMBackend, type WASMBackendConfig, type WasmFeatures, abs, add, backendManager, backendRegistry, cholesky, clearFeatureCache, column, cond, condest, createBackendManager, createGPUMatrixBackend, createParallelBackend, createSyncManager, createWASMBackend, destroyGlobalGPUBackend, detectWasmFeatures, diag, diagonal, divide, dotMultiply, eig, eigWasm, eigvals, eigvalsWasm, exp, getCachedFeatures, getGlobalGPUBackend, gpuMatrixBackend, identity, initializeGlobalGPUBackend, initializeParallelMatrix, isAtomicsAvailable, isDenseMatrix, isMatrix, isSharedMemoryAvailable, isSparseMatrix, isWasmAvailable, jsBackend, log, lowRankApprox, lq, lu, luSolve, matrix, matrixExpm, matrixLogm, pinv as matrixPinv, matrixSchur, matrixSqrtm, max, mean, min, multiply, norm, norm2, normFro, ones, parallelBackend, parallelDiag, parallelDotMultiply, parallelIdentity, parallelMatrix, parallelMatrixAbs, parallelMatrixAdd, parallelMatrixColumn, parallelMatrixCos, parallelMatrixDiagonal, parallelMatrixDistance, parallelMatrixDivide, parallelMatrixDot, parallelMatrixExp, parallelMatrixHistogram, parallelMatrixLog, parallelMatrixMatvec, parallelMatrixMax, parallelMatrixMean, parallelMatrixMin, parallelMatrixMultiply, parallelMatrixNorm, parallelMatrixOperations, parallelMatrixOuter, parallelMatrixRow, parallelMatrixSin, parallelMatrixSize, parallelMatrixSqrt, parallelMatrixSquare, parallelMatrixStd, parallelMatrixSubset, parallelMatrixSubtract, parallelMatrixSum, parallelMatrixTan, parallelMatrixTrace, parallelMatrixTranspose, parallelMatrixVariance, parallelOnes, parallelRandom, parallelUnaryMinus, parallelZeros, pinv$1 as pinv, pow, powerIteration, ql, qr, qrPivoted, random, row, rq, singularValues, size, spectralRadiusWasm, sqrt, square, subset, subtract, sum, svd, svdWasm, terminateParallelMatrix, trace, transpose, typedMatrixOperations, unaryMinus, wasmBackend, zeros };
package/dist/index.js CHANGED
@@ -6492,6 +6492,30 @@ function lu(A) {
6492
6492
  P: perm
6493
6493
  };
6494
6494
  }
6495
+ function luSolve(fac, b) {
6496
+ const n = fac.P.length;
6497
+ if (b.length !== n) {
6498
+ throw new Error(
6499
+ `luSolve: right-hand side length ${b.length} does not match factor dimension ${n}`
6500
+ );
6501
+ }
6502
+ const L = fac.L.toFloat64Array();
6503
+ const U = fac.U.toFloat64Array();
6504
+ const P = fac.P;
6505
+ const y = new Array(n);
6506
+ for (let i = 0; i < n; i++) {
6507
+ let s = b[P[i]];
6508
+ for (let k = 0; k < i; k++) s -= L[i * n + k] * y[k];
6509
+ y[i] = s;
6510
+ }
6511
+ const x = new Array(n);
6512
+ for (let i = n - 1; i >= 0; i--) {
6513
+ let s = y[i];
6514
+ for (let k = i + 1; k < n; k++) s -= U[i * n + k] * x[k];
6515
+ x[i] = s / U[i * n + i];
6516
+ }
6517
+ return x;
6518
+ }
6495
6519
 
6496
6520
  // src/operations/cholesky.ts
6497
6521
  init_DenseMatrix();
@@ -7556,7 +7580,7 @@ function ql(A) {
7556
7580
  }
7557
7581
 
7558
7582
  // src/operations/condest.ts
7559
- function luSolve(L, U, perm, n, b) {
7583
+ function luSolve2(L, U, perm, n, b) {
7560
7584
  const pb = new Array(n);
7561
7585
  for (let i = 0; i < n; i++) pb[i] = b[perm[i]];
7562
7586
  const y = new Array(n);
@@ -7646,7 +7670,7 @@ function condest(A, p = 1) {
7646
7670
  return Infinity;
7647
7671
  }
7648
7672
  const norm1Inv = hagerNormEstimate(
7649
- (v) => luSolve(L, U, perm, n, v),
7673
+ (v) => luSolve2(L, U, perm, n, v),
7650
7674
  (v) => luSolveTranspose(L, U, perm, n, v),
7651
7675
  n
7652
7676
  );
@@ -8544,6 +8568,7 @@ export {
8544
8568
  lowRankApprox,
8545
8569
  lq,
8546
8570
  lu,
8571
+ luSolve,
8547
8572
  matrix,
8548
8573
  matrixExpm,
8549
8574
  matrixLogm,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielsimonjr/mathts-matrix",
3
- "version": "0.6.3",
3
+ "version": "0.7.0",
4
4
  "description": "Matrix operations for MathTS with WASM/WebGPU backend support",
5
5
  "author": "Daniel Simon Jr.",
6
6
  "license": "MIT",