mathjslab
Version:
MathJSLab - An interpreter with language syntax like MATLAB®/Octave, ISBN 978-65-00-82338-7.
200 lines (199 loc) • 6.76 kB
TypeScript
import { ComplexType } from './Complex';
import { MultiArray } from './MultiArray';
import { type NodeReturnList } from './AST';
/**
* `LinearAlgebra` configuration options type.
*/
type LinearAlgebraConfig = {
/**
* LU Waste.
*/
wasteLU: number;
qrPhaseEpsilon: number;
};
export declare const LinearAlgebraConfigKeyTable: (keyof LinearAlgebraConfig)[];
/**
* # LinearAlgebra
*
* LinearAlgebra abstract class. Implements static methods related to linear algebra operations and algorithms.
*
* ## References
*
* * [Linear Algebra at Wolfram MathWorld](https://mathworld.wolfram.com/LinearAlgebra.html)
* * [Fundamental Theorem of Linear Algebra at Wolfram MathWorld](https://mathworld.wolfram.com/FundamentalTheoremofLinearAlgebra.html)
* * [Linear algebra at Wikipedia](https://en.wikipedia.org/wiki/Linear_algebra)
*/
declare abstract class LinearAlgebra {
/**
* `LinearAlgebra` default settings.
*/
static readonly defaultSettings: LinearAlgebraConfig;
/**
* `LinearAlgebra` current settings.
*/
static readonly settings: LinearAlgebraConfig;
/**
* Set configuration options for `LinearAlgebra`.
* @param config Configuration options.
*/
static readonly set: (config: Partial<LinearAlgebraConfig>) => void;
/**
* Identity matrix
* @param args
* * `eye(N)` - create identity N x N
* * `eye(N,M)` - create identity N x M
* * `eye([N,M])` - create identity N x M
* @returns Identity matrix
*/
static readonly eye: (...args: MultiArray[] | ComplexType[]) => MultiArray | ComplexType;
/**
* Sum of diagonal elements.
* @param M Matrix.
* @returns Trace of matrix.
*/
static readonly trace: (M: MultiArray) => ComplexType;
/**
* Transpose and apply function.
* @param M Matrix.
* @returns Transpose matrix with `func` applied to each element.
*/
private static readonly applyTranspose;
/**
* Transpose.
* @param M Matrix.
* @returns Transpose matrix.
*/
static readonly transpose: (M: MultiArray) => MultiArray;
/**
* Complex conjugate transpose.
* @param M Matrix.
* @returns Complex conjugate transpose matrix.
*/
static readonly ctranspose: (M: MultiArray) => MultiArray;
/**
* Matrix power (multiple multiplication).
* @param left
* @param right
* @returns
*/
static readonly power: (left: MultiArray, right: ComplexType) => MultiArray;
/**
* Matrix determinant using LU decomposition with pivot sign correction.
* Uses `LinearAlgebra.luDecomposition`.
* @param M Matrix.
* @returns Matrix determinant.
*/
static readonly det: (M: MultiArray) => ComplexType;
/**
* Computes the LU decomposition with partial pivoting.
* @param M Input square matrix.
* @returns An object { L, U, P, swaps } where:
* - L: lower-triangular with unit diagonal (MultiArray)
* - U: upper-triangular (MultiArray)
* - P: permutation matrix (MultiArray)
* - swaps: number of row swaps performed (integer)
*
* ## References
* * https://www.codeproject.com/Articles/1203224/A-Note-on-PA-equals-LU-in-Javascript
* * https://rosettacode.org/wiki/LU_decomposition#JavaScript
*/
static readonly luDecomposition: (A: MultiArray) => {
L: MultiArray;
U: MultiArray;
P: MultiArray;
swaps: number;
};
/**
* PLU matrix factorization.
* @param M Matrix.
* @returns L, U and P matrices as multiple output.
*/
static readonly lu: (M: MultiArray) => NodeReturnList;
/**
* Returns the inverse of matrix `M`.
* inv(A) wrapper using LAPACK.getrf_blocked + LAPACK.getrs.
* Behavior: MATLAB-like: if factorization reports info !== 0, emit warning and return matrix filled with Inf.
* @param M Matrix.
* @returns Inverted matrix.
*/
static readonly inv: (A: MultiArray) => MultiArray;
/**
* Gaussian elimination algorithm for solving systems of linear equations.
* Adapted from: https://github.com/itsravenous/gaussian-elimination
* ## References
* * https://mathworld.wolfram.com/GaussianElimination.html
* @param M Matrix.
* @param m Vector.
* @returns Solution of linear system.
*/
static readonly gauss: (M: MultiArray, m: MultiArray) => MultiArray;
/**
* High-performance dot product. Fully ND-aware, column-major, no index
* conversions (≈2-3× faster). Computes sum(conj(A).*B, dim) with minimal
* per-element overhead.
* C = dot(A,B) or C = dot(A,B,dim)
* Sums conj(A).*B along the specified dimension (zero-based operateDim). If dim is omitted,
* use the first non-singleton dimension (zero-based).
* @param A First array (MultiArray).
* @param B Second array (MultiArray).
* @param dim (optional) Dimension along which to operate (ComplexType representing integer, 1-based externally).
* @returns Scalar (ComplexType) if result is single value, else a MultiArray.
*/
static readonly dot: (A: MultiArray, B: MultiArray, dim?: ComplexType) => MultiArray | ComplexType;
/**
* Cross product along dimension `dim` (MATLAB semantics).
* A and B must have the same size except along `dim` where size must be 3.
* dim is optional and is 1-based like MATLAB; internally converted to 0-based.
* @param A
* @param B
* @param dim
* @returns
*/
static readonly cross: (A: MultiArray, B: MultiArray, dim?: any) => MultiArray;
/**
*
* @param A
* @param B
* @returns
*/
static readonly kron: (A: MultiArray, B: MultiArray) => MultiArray;
/**
* Normalize phases so that R diagonal becomes real non-negative:
* For k = 0..minmn-1:
* phi = R[k][k] / |R[k][k]|
* R[k, j] := R[k, j] / phi (j = k..n-1)
* Q[i, k] := Q[i, k] * phi (i = 0..m-1)
* @param Q
* @param R
* @param phis
*/
static readonly qrPhaseNormalize: (phis: ComplexType[], R: MultiArray, Q?: MultiArray) => void;
/**
*
* @param A
* @param result
* @returns
*/
static readonly qrDecomposition: (A: MultiArray, result: 1 | 2 | 3) => {
Q?: MultiArray;
R: MultiArray;
P?: MultiArray;
};
/**
*
* @param M
* @returns
*/
static readonly qr: (M: MultiArray) => NodeReturnList;
/**
* LinearAlgebra functions.
*/
static functions: {
[F in keyof LinearAlgebra]: Function;
};
}
export { LinearAlgebra };
declare const _default: {
LinearAlgebra: typeof LinearAlgebra;
};
export default _default;