mathjslab
Version:
MathJSLab - An interpreter with language syntax like MATLAB®/Octave, ISBN 978-65-00-82338-7.
1,002 lines (1,001 loc) • 40.8 kB
TypeScript
import { ComplexType, NumLikeType } from './Complex';
import { type ElementType, MultiArray } from './MultiArray';
type Jacobi2x2Result = {
c: number;
s: ComplexType;
};
type LAPACKConfig = {
/**
* Maximum iteration factor.
*/
maxIterationFactor: number;
};
export declare const LAPACKConfigKeyTable: (keyof LAPACKConfig)[];
/**
* # LAPACK (Linear Algebra PACKage)
*
* ## References
* - https://en.wikipedia.org/wiki/LAPACK
* - https://www.netlib.org/lapack/
* - https://github.com/Reference-LAPACK/lapack
*/
declare abstract class LAPACKunused {
/**
* `LAPACK` default settings.
*/
static readonly defaultSettings: LAPACKConfig;
/**
* `LAPACK` current settings.
*/
static readonly settings: LAPACKConfig;
/**
* Set configuration options for `LAPACK`.
* @param config Configuration options.
*/
static readonly set: (config: Partial<LAPACKConfig>) => void;
/**
* Apply a sequence of row interchanges to a MultiArray.
* LAPACK-like signature: laswp(A, k1, k2, ipiv, incx, colStart = 0, colEnd = numCols-1)
* @param A Multidimensional matrix.
* @param k1 1-based start index of rows to process (inclusive).
* @param k2 1-based end index of rows to process (inclusive).
* @param ipiv Integer array of pivot indices (LAPACK convention: 1-based). The routine will auto-detect if ipiv looks 0-based and adapt.
* @param incx Increment (typically +1 or -1). When incx > 0 loop i=k1..k2 step incx; when incx<0 loop i=k1..k2 step incx.
* @param colStart Optional 0-based column start to which the swaps are applied (inclusive).
* @param colEnd Optional 0-based column end to which the swaps are applied (inclusive).
* @returns
*/
static readonly laswp: (A: MultiArray, k1: number, k2: number, ipiv: number[], incx: number, colStart?: number, colEnd?: number) => void;
/**
* Swap two rows of an N-dimensional MultiArray across all pages in place.
* It is `LAPACK.laswp` for a single pivot applied across slices). `row1`,
* `row2` are 0-based indices within the first dimension.
* @param M Matrix.
* @param row1 First row index to swap.
* @param row2 Second row index to swap.
*/
static readonly laswp_rows: (M: MultiArray, row1: number, row2: number) => void;
/**
* Swap two columns of an N-dimensional MultiArray across all pages in
* place. There is no direct equivalent to LAPACK, but it is symmetrical
* to `laswp_rows`.
* @param M Matrix.
* @param col1 First column index to swap.
* @param col2 Second column index to swap.
*/
static readonly laswp_cols: (M: MultiArray, col1: number, col2: number) => void;
/**
* Returns a 2D or ND-aware identity matrix (`ComplexType[][]`), row-major.
* Optimized for internal `BLAS`/`LAPACK` operations.
* Supports arbitrary number of dimensions.
*
* Usage:
* `LAPACK.eye(2,3,5,4)` -> MultiArray with dims [2,3,5,4]
* `LAPACK.eye([2,3,5,4])` -> same as above
*
* Diagonal filled with `1` (`Complex.one()`), rest zeros.
* Each 2-D page `[m,n]` in `ND` array gets its own identity.
* @param dims `number[] | ...number`
*/
static readonly eye: (...dims: any[]) => ComplexType[][];
/**
* Returns a 2D or ND-aware null matrix (`ComplexType[][]`), row-major.
* Optimized for internal `BLAS`/`LAPACK` operations.
* Supports arbitrary number of dimensions.
*
* Usage:
* `LAPACK.zeros(2,3,5,4)` -> MultiArray with dims [2,3,5,4]
* `LAPACK.zeros([2,3,5,4])` -> same as above
*
* All elements filled with `0` (`Complex.zero()`).
* @param dims `number[] | ...number`
* @returns
*/
static readonly zeros: (...dims: any[]) => ComplexType[][];
static readonly lassq: (A: MultiArray) => {
scale: ComplexType;
sumsq: ComplexType;
};
static readonly lange: (norm: "F" | "M", A: MultiArray) => ComplexType;
/**
* Zero the lower triangular part (i > j), keeping only the upper triangle. LAPACK-like TRIU operation.
* @param M
*/
static readonly triu_inplace: (M: MultiArray) => void;
/**
* Zero the upper triangular part (j > i), keeping only the lower triangle. LAPACK-like TRIL operation.
* @param M
*/
static readonly tril_inplace: (M: MultiArray) => void;
/**
* Solve for X in U * X = B where U is upper triangular k x k stored at
* A[kblock]. We implement in-place update of Bblock (A12 region). Block
* target at rows k..k+kb-1, cols k+kb..n-1
* @param A full MultiArray; U is at rows k..k+kb-1, cols k..k+kb-1
* @param k
* @param kb
*/
static readonly trsm_left_upper_block: (A: MultiArray, k: number, kb: number) => void;
/**
*
* @param jpvt
* @returns
*/
static readonly lapmt_matrix: (jpvt: number[]) => MultiArray;
/**
* Generate a Householder reflector for a vector x (length m).
* Produces tau, v (with v[0] = 1) and alpha (the value to write at x[0]).
*
* This is the vector-version of larfg. It does NOT read or write a matrix:
* it only uses the vector x (ComplexType[]) and returns the reflector data.
*
* Conventions match LAPACK ZLARFG: alpha = -phi * ||x||, tau = (alpha - x0)/alpha,
* v[0] = 1, v[i] = x[i] / (x0 - alpha) for i>=1. If sigma == 0 then tau = 0.
*/
static readonly larfg_vector: (x: ComplexType[]) => {
tau: ComplexType;
v: ComplexType[];
phi: ComplexType;
alpha: ComplexType;
};
/**
* Generate Householder vector and apply it immediately to A.
* LAPACK-style: side-aware (left/right), complex.
* @param side 'L' for left, 'R' for right
* @param A Matrix to transform (modified in place)
* @param k Index for the reflector (row/column start)
*/
/**
*
* @param side
* @param A
* @param k
* @returns Object { tau, v, alpha }
*/
static readonly larfg_apply: (side: "L" | "R", A: MultiArray, k: number) => {
tau: ComplexType;
v: ComplexType[];
alpha: ComplexType;
};
/**
*
* @param A
* @param k
* @returns Object { tau, v, alpha }
*/
static readonly larfg_left_nd: (A: MultiArray, k: number) => {
tau: ComplexType;
v: ComplexType[];
alpha: ComplexType;
};
/**
*
* @param A
* @param k
* @returns Object { tau, v, alpha }
*/
static readonly larfg_right_nd: (A: MultiArray, k: number) => {
tau: ComplexType;
v: ComplexType[];
alpha: ComplexType;
};
/**
*
* @param side
* @param A
* @param k
* @returns
*/
static readonly larfg_nd: (side: "L" | "R", A: MultiArray, k: number) => {
tau: ComplexType;
v: ComplexType[];
alpha: ComplexType;
};
/**
* Apply an elementary reflector H = I - tau * v * vᴴ to A from the left,
* but restricted to columns colStart .. colEnd-1.
*
* A: MultiArray (row-major)
* v: ComplexType[] (v[0] == 1, length = m - rowStart)
* tau: ComplexType
* rowStart: starting row index of the reflector (k)
* colStart: first column to update (usually k+1)
* colEnd: (optional) one-past-last column to update (default = A.dimension[1])
*/
static readonly larf_left_block_anterior: (A: MultiArray, v: ComplexType[], tau: ComplexType, rowStart: number, colStart: number, colEnd?: number) => void;
/**
* Apply Householder reflector H = I - tau * v * vᴴ to A from the left,
* in a blocked fashion:
*
* A[rowStart..m-1, colStart..n-1] := H * A[rowStart..m-1, colStart..n-1]
*
* v is ComplexType[] of length = m - rowStart (v[0] == 1).
*
* Uses temporary block buffers and BLAS.gemm_block to compute
* S = vᴴ * A_block and then A_block -= tau * v * S
*/
static readonly larf_left_block: (A: MultiArray, v: ComplexType[], tau: ComplexType, rowStart: number, colStart: number, blockSize?: number) => void;
/**
* Blocked version of applying Hᴴ = I - conj(tau) * v * vᴴ from the RIGHT:
*
* A[rowStart..m-1, colStart..colStart+vlen-1] := A[rowStart..m-1, colStart..colStart+vlen-1] * Hᴴ
*
* v length = number of columns in the block (vlen).
*
* Uses temporary buffers and BLAS.gemm_block where appropriate.
*/
static readonly larf_right_conj_block: (A: MultiArray, v: ComplexType[], tau: ComplexType, rowStart: number, colStart: number, blockSize?: number) => void;
/**
* Apply the conjugate-right Householder reflector Hᴴ = I - conj(tau) * v * vᴴ to A from the right.
* Equivalent to A := A * Hᴴ for rows i = rowStart..m-1 and columns j = colStart..colStart+v.length-1.
*
* This is the companion routine for larf_left when you need to perform
* A := H * A * Hᴴ (first call larf_left(A, v, tau, rowStart, colStartLeft)
* then call larf_right_conj(A, v, tau, rowStart, colStartRight)).
*
* @param A MultiArray to modify in-place.
* @param v Householder vector (ComplexType[]), v[0] == 1, length = block width.
* @param tau Householder scalar (ComplexType).
* @param rowStart first row of the block (usually 0 or k).
* @param colStart first column of the block (where v aligns horizontally).
*/
static readonly larf_right_conj: (A: MultiArray, v: ComplexType[], tau: ComplexType, rowStart: number, colStart: number) => void;
/**
* Same operation as larf_right_conj — but returns new matrix instead of modifying A.
*
* Compute:
* A_new = A * Hᴴ
* where Hᴴ = I - conj(tau) * v * vᴴ
*
* Input:
* A original matrix (not modified)
* v Householder vector, v[0] == 1
* tau Householder scalar
* rowStart first affected row
* colStart first affected column
*
* Output:
* MultiArray A_new = A * Hᴴ
*/
static readonly larf_right_conj_return: (A: MultiArray, v: ComplexType[], tau: ComplexType, rowStart: number, colStart: number) => MultiArray;
/**
*
* @param A
* @param v
* @param tau
* @param rowStart
* @param colStart
* @returns
*/
static readonly larf_left_nd: (A: MultiArray, v: ComplexType[], tau: ComplexType, rowStart: number, colStart: number) => void;
/**
*
* @param A
* @param v
* @param tau
* @param rowStart
* @param colStart
* @returns
*/
static readonly larf_right_nd: (A: MultiArray, v: ComplexType[], tau: ComplexType, rowStart: number, colStart: number) => void;
static readonly larf_nd: (side: "L" | "R", A: MultiArray, v: ComplexType[], tau: ComplexType, rowStart: number, colStart: number) => void;
/**
* Unblocked LU factorization (panel) - modifies A in place.
* A is m x n stored as MultiArray (row-major physical layout).
* Performs LU on A[k..m-1, k..n-1] and writes pivots into piv starting at offset k.
* Returns number of pivots performed (panel width) or info.
*
* This is analogous to LAPACK's xGETF2 applied to the submatrix.
*
* This routine will update A in-place (compact LU) and fill piv[k..k+panelWidth-1].
*
* @param A MultiArray (m x n)
* @param k starting column/row index for panel
* @param panelWidth number of columns to factor (<= min(m-k, n-k))
* @param piv global pivot array (zero-based), length >= min(m,n)
*/
static readonly getf2: (A: MultiArray, k: number, panelWidth: number, piv: number[]) => void;
/**
* Blocked GETRF for complex matrices (LU with partial pivoting).
* This routine will modify A in-place, writing LU (L below diag, U on and above diag).
* @param A
* @returns { LU: MultiArray (same reference as input A, modified), piv: number[], swaps: number }
*/
static readonly getrf: (A: MultiArray, blockSize?: number) => {
LU: MultiArray;
piv: number[];
swaps: number;
};
/**
* Compute A22 := A22 - A21 * A12 (standard update in GETRF).
* All indices are absolute within A.array.
* A21: rows (k+kb .. m-1) x cols (k .. k+kb-1)
* A12: rows (k .. k+kb-1) x cols (k+kb .. n-1)
* A22: rows (k+kb .. m-1) x cols (k+kb .. n-1)
* @param A
* @param k
* @param kb
* @param blockSizeInner
*/
static readonly gemm_blocked: (A: MultiArray, k: number, kb: number, blockSizeInner?: number) => void;
/**
* Blocked LU factorization that calls getf2 for panel factorization,
* then solves and updates the trailing submatrix.
* @param A
* @returns Object { LU: A, piv, info, swaps }
*/
static readonly getrf_blocked: (A: MultiArray, blockSize?: number) => {
LU: MultiArray;
piv: number[];
info: number;
swaps: number;
};
/**
* Solve systems A X = B given LU factorization in-place and pivots.
* This follows LAPACK GETRS semantics (no transpose).
* @param LU MultiArray containing LU as returned by getrf
* @param piv pivot vector (zero-based) length = min(m,n)
* @param B MultiArray of size m x nrhs (modified in place)
* @returns new MultiArray (`B`) with solution
*/
static readonly getrs: (LU: MultiArray, piv: number[], B: MultiArray) => MultiArray;
/**
* Reduce a Hermitian matrix A (n × n) to real tridiagonal form T using
* Householder reflectors.
*
* This routine performs a similarity transformation:
*
* A = Q * T * Qᴴ
*
* where:
* - A is the original Hermitian matrix,
* - T is a real symmetric tridiagonal matrix,
* - Q is a unitary matrix formed as a product of Householder reflectors.
*
* The reduction is carried out implicitly as:
*
* A ← H₀ᴴ H₁ᴴ ... Hₙ₋₂ᴴ · A · Hₙ₋₂ ... H₁ H₀
*
* with:
*
* Q = H₀ H₁ ... Hₙ₋₂
*
* Each Householder reflector has the form:
*
* H_k = I - tau_k · v_k · v_kᴴ
*
* where v_k is a Householder vector with the convention v_k[0] = 1.
*
* ---
* Storage conventions (LAPACK-compatible):
*
* This routine overwrites the input matrix A in-place. After completion:
*
* - diag[k] contains the diagonal entry T[k, k]
* - offdiag[k] contains the sub/super-diagonal entry T[k+1, k]
* - taus[k] contains the scalar factor tau_k for reflector H_k
*
* - The Householder vector v_k is stored in:
*
* A[k+1:n-1, k]
*
* with:
*
* v_k[0] = 1
* v_k[i] = A[k+1+i, k], i = 1 .. n-k-2
*
* The strictly upper triangle of A is not referenced after the reduction.
*
* ---
* Algorithmic structure:
*
* For each k = 0 .. n-2:
* 1) A Householder reflector H_k is generated from column k
* 2) The trailing (n-k-1) × (n-k-1) submatrix is updated via a
* Hermitian rank-2 update
*
* The concrete implementation of the reflector application is injected
* via the `larf` parameter, allowing different backends:
*
* - real symmetric reduction → larf_left
* - complex Hermitian reduction → her2_zhtrd_update
*
* This mirrors the separation of concerns used in LAPACK (e.g. `zhetrd`)
* and simplifies validation and reuse.
*
* ---
* Dependencies:
*
* - LAPACK.larfg_vector(x): generates Householder vector v and scalar tau
* - larf(A, v, tau, rowStart, colStart): applies reflector to trailing block
*
* All numeric arrays are represented as ComplexType[] to conform to the
* MathJSLab Complex facade, even though the resulting tridiagonal matrix T
* is real-valued.
*
* @param A
* Hermitian square MultiArray (n × n). Modified in-place.
*
* @param larf
* Function responsible for applying the Householder reflector to the
* trailing submatrix. Its exact behavior depends on whether the reduction
* is real symmetric or complex Hermitian.
*
* @returns
* An object containing:
* - diag : diagonal entries of T
* - offdiag : sub/super-diagonal entries of T
* - taus : scalar Householder factors tau_k
*/
/**
* Reduce a Hermitian matrix A to real symmetric tridiagonal form T:
*
* A = Q · T · Qᴴ
*
* using Householder reflectors, following exactly the LAPACK ZHETRD
* unblocked algorithm (lower triangle variant).
*
* On exit:
* - diag[k] = T[k,k]
* - offdiag[k] = T[k+1,k] (real in exact arithmetic)
* - taus[k] = Householder scalar τₖ
*
* Storage convention (LAPACK-compatible):
* - The Householder vector vₖ is stored in A[k+1:n-1, k]
* - vₖ[0] = 1 is implicit (not stored)
*
* @param A Hermitian matrix (n×n), modified in-place
* @param hetrd_update Function that applies a reflector from the left (Hermitian-aware)
*/
static readonly sytrd: (A: MultiArray, hetrd_update: (A: MultiArray, v: ComplexType[], tau: ComplexType, rowStart: number, colStart: number) => void) => {
diag: ComplexType[];
offdiag: ComplexType[];
taus: ComplexType[];
};
/**
* Generate the unitary matrix Q from a Hermitian tridiagonal reduction.
*
* This routine reconstructs the unitary matrix Q from the Householder
* reflectors produced by `sytrd` (Hermitian reduction to tridiagonal form).
* It is the complex/Hermitian analogue of LAPACK's `ungtr`.
*
* The reduction performed by `sytrd` satisfies:
*
* A = Q * T * Qᴴ
*
* where:
* - A is the original Hermitian matrix,
* - T is the real tridiagonal matrix returned by `sytrd`,
* - Q is a unitary matrix defined as the product of Householder reflectors.
*
* After a call to `sytrd(A, larf)`, the input matrix `A` contains the data
* needed to reconstruct Q:
*
* - For each k = 0 .. n-2, the Householder vector v_k is stored in
* A[k+1:n-1, k], with the convention:
*
* v_k[0] = 1
* v_k[i] = A[k+1+i, k], i = 1 .. n-k-2
*
* - The scalar factor tau_k associated with each reflector H_k is stored
* in TAU[k].
*
* Each Householder reflector is defined as:
*
* H_k = I - tau_k * v_k * v_kᴴ
*
* and the unitary matrix Q is given by:
*
* Q = H_0 * H_1 * ... * H_{n-2}
*
* This routine builds Q explicitly by applying the reflectors in reverse
* order:
*
* Q = H_{n-2} * ... * H_1 * H_0 * I
*
* Notes:
* - The input matrix `A` is NOT modified by this routine.
* - This function assumes that `sytrd` stored the Householder vectors
* exactly according to the LAPACK convention (v[0] = 1).
* - No attempt is made to symmetrize or normalize the reflectors here;
* correctness depends on a consistent `sytrd` implementation.
*
* @param A
* Square MultiArray (n × n) that was previously reduced by `sytrd`.
* The strictly lower triangular part of A contains the Householder
* vectors v_k.
*
* @param TAU
* Array of length n containing the scalar factors tau_k returned by
* `sytrd`. Only entries TAU[0 .. n-2] are used.
*
* @returns
* A new MultiArray (n × n) containing the unitary matrix Q such that
* A_original = Q * T * Qᴴ.
*/
static readonly ungtr0: (A: MultiArray, TAU: ComplexType[]) => MultiArray;
/**
* Generate the unitary matrix Q from a Hermitian tridiagonal reduction.
*
* This routine reconstructs
*
* Q = H₀ H₁ ... Hₙ₋₂
*
* where each Householder reflector is
*
* Hₖ = I − τₖ vₖ vₖᴴ
*
* The reflectors {vₖ, τₖ} are assumed to be stored exactly as produced by
* sytrd / zhetrd:
*
* - vₖ is stored in A[k+1:n-1, k]
* - vₖ[0] = 1 is implicit (not stored)
* - τₖ is stored in TAU[k]
*
* This implementation is semantically equivalent to LAPACK ZUNGTR
* (internally using the same logic as ZUNMTR applied to the identity).
*
* On exit, Q satisfies:
*
* A ≈ Q · T · Qᴴ
*
* provided sytrd was correct.
*
* @param A Matrix containing Householder vectors (modified sytrd output)
* @param TAU Householder scalar factors
* @returns Unitary matrix Q
*/
static readonly ungtr: (A: MultiArray, TAU: ComplexType[]) => MultiArray;
/**
* Versão estendida de depuração da sytrd()
* Reconstrói Q, T e imprime o processo completo de tridiagonalização.
*/
static readonly sytrd_debug: (A: MultiArray) => {
diag: import("./ComplexInterface").ComplexInterface<import("./Complex").RealType, number, unknown>[];
offdiag: import("./ComplexInterface").ComplexInterface<import("./Complex").RealType, number, unknown>[];
taus: import("./ComplexInterface").ComplexInterface<import("./Complex").RealType, number, unknown>[];
Q: MultiArray<import("./ComplexInterface").ComplexInterface<import("./Complex").RealType, number, unknown> | import("./CharString").CharString | import("./Structure").Structure | import("./FunctionHandle").FunctionHandle>;
T: MultiArray<import("./ComplexInterface").ComplexInterface<import("./Complex").RealType, number, unknown> | import("./CharString").CharString | import("./Structure").Structure | import("./FunctionHandle").FunctionHandle>;
QtA: import("./MathOperation").MathObject;
};
/**
* Blocked reduction of a Hermitian matrix A to tridiagonal form.
*
* This is a blocked variant of sytrd that uses larf_left_block and
* larf_right_conj_block to apply reflectors in blocks and BLAS.gemm_block
* for inter-block multiplications. It preserves the storage convention:
* - Householder vectors v are stored in A[k+1:n-1, k] with v[0] at A[k+1,k]
* - taus[k] stores the scalar for the k-th reflector
*
* @param A Hermitian MultiArray (n x n). Modified in-place.
* @param blockSize block size (in columns) used for panel processing; default 32
* @returns { diag, offdiag, taus } as ComplexType[] arrays
*/
static readonly sytrd_blocked: (A: MultiArray, blockSize?: number) => {
diag: ComplexType[];
offdiag: ComplexType[];
taus: ComplexType[];
};
/**
* Blocked reduction of a Hermitian matrix A to tridiagonal form
* using LAPACK-style panel accumulation with matrix W.
*
* Householder vectors are stored in the lower triangle of A (v[0] at A[k+1,k])
* taus[k] stores the scalar for the k-th reflector.
*
* @param A Hermitian MultiArray (n x n), modified in-place
* @param blockSize block size (panel width)
* @returns { diag, offdiag, taus }
*/
static readonly sytrd_blocked_w: (A: MultiArray, blockSize?: number) => {
diag: ComplexType[];
offdiag: ComplexType[];
taus: ComplexType[];
};
/**
* Compute eigenvalues of a symmetric tridiagonal matrix T given by
* diag[] and offdiag[].
*
* This is the QR algorithm with Wilkinson shifts - simplified version
* that returns only eigenvalues. Next step will include eigenvectors.
*
* @param diag ComplexType[] - diagonal elements of T
* @param offdiag ComplexType[] - sub/super diagonal (e1...e[n-1])
* @param maxIter optional - default 1000*n
*/
/**
* Compute eigenvalues only (returns MultiArray column [n x 1]).
* This wrapper currently reuses steqr_vectors internally for correctness.
* Signature:
* steqr_values(diag, offdiag, maxIter?) -> MultiArray [n x 1]
*/
static readonly steqr_values: (diag: ComplexType[], offdiag: ComplexType[], maxIter?: number) => ComplexType[];
/**
* Compute eigenvalues AND eigenvectors of a symmetric tridiagonal matrix T
* using the implicit QR algorithm with Wilkinson shifts.
*
* The matrix is represented by:
* diag[i] = diagonal entries (length n)
* offdiag[i]= sub/super diagonal (length n-1)
*
* Returns:
* { D, V }
* D : eigenvalues (ComplexType[n])
* V : eigenvectors (ComplexType[n][n]) -- V[:,i] is eigenvector of D[i]
*/
/**
* Compute eigenvalues AND eigenvectors of a symmetric tridiagonal matrix T
* using the implicit QR algorithm with Wilkinson shifts.
*
* Input:
* - diag: ComplexType[] length n (diagonal of T)
* - offdiag: ComplexType[] length n-1 (sub/super diagonal)
*
* Returns:
* { D: MultiArray, V: MultiArray }
* - D : MultiArray [n x 1] (eigenvalues)
* - V : MultiArray [n x n] (eigenvectors as columns)
*/
static readonly steqr_vectors_1: (diag: ComplexType[], offdiag: ComplexType[], maxIter?: number) => {
D: MultiArray;
V: MultiArray;
};
/**
* Stable steqr_vectors: compute eigenvalues and eigenvectors of symmetric tridiagonal T
* Inputs:
* - diag: ComplexType[] (length n)
* - offdiag: ComplexType[] (length n-1, last may be unused)
* Returns:
* { D: MultiArray (n x 1), V: MultiArray (n x n) }
*
* Numeric improvements:
* - compute r using Math.hypot of magnitudes to avoid overflow
* - deflation test for tiny subdiagonals
* - reasonable max iterations and early exit
*/
/**
* steqr_vectors (numeric-real kernel)
* - diag: ComplexType[] (length n) -- assumed real values
* - offdiag: ComplexType[] (length n-1)
* Returns { D: MultiArray (n x 1), V: MultiArray (n x n) }
*
* Numeric kernel works in JS numbers for D/E and uses Complex only to update V.
*/
static readonly steqr_vectors_0: (diag: ComplexType[], offdiag: ComplexType[], maxIteration?: number) => {
D: MultiArray;
V: MultiArray;
};
static readonly steqr_vectors_2: (diag: ComplexType[], offdiag: ComplexType[], maxIteration?: number) => {
D: MultiArray;
V: MultiArray;
};
static readonly numeric_jacobi_symmetric_dense: (Dnum_in: number[], Enum_in: number[], maxItsLocal: number) => {
Dnum: number[];
Vnum: ComplexType[][];
};
/**
* Build dense Hermitian matrix from tridiagonal representation
*
* @param diag diagonal entries
* @param offdiag sub/superdiagonal entries (length n-1)
* @returns dense Hermitian matrix
*/
static readonly tridiag_her_to_dense: (diag: ComplexType[], offdiag: ComplexType[]) => ComplexType[][];
/**
* Compute Frobenius norm of residual || T * V - V * diag(evals) ||_F using real-numeric aggregation.
* @param T ComplexType[][] dense Hermitian
* @param V MultiArray (ComplexType entries)
* @param evalsNum number[] (real eigenvalues)
* @returns numeric Frobenius norm (number)
*/
static readonly compute_residual_numeric: (T: ComplexType[][], V: MultiArray, evalsNum: number[]) => number;
/**
* Compute Frobenius norm of residual R = A * V - V * diag(evals),
* @param A
* @param V
* @param evals `evals` is `ComplexType[]` or `number[]`.
* @returns A `number` (real Frobenius norm).
*/
static readonly compute_residual_complex: (T: ComplexType[][], V: MultiArray, evals: ComplexType[] | number[]) => number;
/**
* Find the element with the highest magnitude in the column (pivot).
* @param array Row-major order bidimensional MultiArray structure.
* @param column Column to find the pivot.
* @param rowStart Row start (to deal with multidimensional operations and functions). Default is `0`.
* @param rowEnd Row end (to deal with multidimensional operations and functions). Default is `array.length`.
* @returns An object containing:
* - pivotRow - Row index of pivot element (relative to rowStart).
* - pivotAbs - Absolute value of pivot.
* - pivotIsZero - `true` if pivot element is zero (improbable null column.).
*/
static readonly column_pivot: (array: ComplexType[][], column: number, rowStart?: number, rowEnd?: number) => {
pivotRow: number;
pivotAbs: ComplexType;
pivotIsZero: boolean;
};
/**
* Normalize eigenvector phases so that pivot element in each column becomes real positive.
* Modifies V in-place (ComplexType[][]).
* @param V
* @param pivotPositive
*/
static readonly normalize_eigenvector_phases: (V: ComplexType[][], pivotPositive?: boolean) => void;
/**
*
* @param V
* @returns
*/
static readonly test_orthonormality: (V: MultiArray) => {
maxOffDiag: number;
maxDiagDeviation: number;
};
/**
*
* @param A
* @param V
* @param Dcol
* @returns
*/
static readonly test_residual: (A: ComplexType[][], V: MultiArray, Dcol: MultiArray) => number;
/**
* Diagnóstico por autovetor:
* Para cada coluna j:
* - lambda = Dcol[j,0]
* - rq = (vᴴ * A * v) / (vᴴ * v) (Rayleigh quotient)
* - res_j = || A*v - lambda*v ||_2 (norma euclidiana do residual)
*
* Imprime uma tabela (j, lambda, Re(rq), Im(rq), |lambda - rq|, res_j )
*/
/**
*
* @param A
* @param V
* @param Dcol
* @returns
*/
static readonly diag_eigenpairs: (A: ComplexType[][], V: MultiArray, Dcol: MultiArray) => any[];
/**
* Compara listas: ordena autovalores fornecidos e compara com Rayleighs - procura permutações.
* Retorna um mapeamento aproximado index->index por menor diferença absoluta.
*
* Inputs:
* - evals: ComplexType[] (autovalores retornados)
* - rqs: ComplexType[] (rayleighs calculados para cada coluna v_j)
*
* Imprime o pareamento escolhido e as diferenças.
*/
/**
*
* @param evals
* @param rqs
* @returns
*/
static readonly match_evals_to_rayleighs: (evals: ComplexType[], rqs: ComplexType[]) => {
evalIndex: number;
rqIndex: number;
diff: number;
}[];
static readonly steqr_vectors_original: (diag: ComplexType[], offdiag: ComplexType[], maxIter?: number) => {
D: MultiArray;
V: MultiArray;
complex: boolean;
};
static readonly steqr_vectors: (diag: ComplexType[], offdiag: ComplexType[], maxIter?: number) => {
D: ComplexType[];
V: ComplexType[][];
complex: boolean;
};
/**
* Reconstruct Q from the output of sytrd_blocked_w (Hermitian to tridiagonal reduction)
* using LAPACK-style blocked panel accumulation with matrix W.
*
* @param A MultiArray containing Householder vectors in lower triangle
* @param taus ComplexType[] scalars for each reflector (from sytrd_blocked_w)
* @param blockSize block size (panel width, same as sytrd_blocked_w)
* @returns Q unitary MultiArray (n x n)
*/
static readonly orgtr_blocked_w: (A: MultiArray, taus: ComplexType[], blockSize?: number) => MultiArray;
static readonly eig_symmetric: (A: MultiArray, computeVectors?: boolean) => {
D: MultiArray;
V?: MultiArray;
};
static readonly eig_symmetric0: (A: MultiArray, computeVectors?: boolean, maxIter?: number) => {
D: MultiArray;
V?: MultiArray;
};
static readonly eig_symmetric1: (A: MultiArray, computeVectors?: boolean, maxIter?: number) => {
D: number[];
V: MultiArray;
};
static readonly eig_symmetric2: (A: MultiArray, computeVectors?: boolean, maxIter?: number) => {
D: MultiArray;
V?: MultiArray;
};
/**
* eig_symmetric - eigenvalues + eigenvectors for Hermitian/symmetric matrix A.
*
* @param A MultiArray (n x n)
* @param order 'none' | 'asc' | 'desc' (default = 'asc')
*
* @returns { V, D, evals } where
* V = MultiArray n x n (eigenvectors column-wise)
* D = MultiArray n x n diagonal eigenvalue matrix
* evals = ComplexType[] eigenvalues (sorted according to `order`)
*/
static readonly eig_symmetric3: (A: MultiArray, order?: "none" | "asc" | "desc") => {
V: MultiArray;
D: MultiArray;
evals: ComplexType[];
};
static readonly eig_symmetric4: (A: MultiArray, computeVectors?: boolean, maxIter?: number) => {
D: MultiArray;
V?: MultiArray;
};
static readonly eig_symmetric5: (A: MultiArray, computeVectors?: boolean, maxIter?: number) => {
D: MultiArray;
V?: MultiArray;
};
/**
* eig_symmetric_blocked - blocked eigen-decomposition for Hermitian/symmetric A
*
* @param A MultiArray (n x n) Hermitian / real symmetric (not modified)
* @param order 'asc' | 'desc' | 'none' (default = 'asc')
* @param blockSize block size (default 32)
*
* @returns { D: ComplexType[], V: MultiArray } (D = eigenvalues, V columns = eigenvectors)
*/
static readonly eig_symmetric_blocked: (A: MultiArray, order?: "asc" | "desc" | "none", blockSize?: number) => {
D: ComplexType[];
V: MultiArray;
};
/**
* ===================================================================================
* =================================== 2th round =====================================
* ===================================================================================
*/
static readonly jacobi_complex_hermitian_dense_1: (T: ComplexType[][], maxSweeps?: NumLikeType, tol?: NumLikeType) => {
D: ComplexType[];
V: ComplexType[][];
};
/**
* Jacobi rotation for a 2×2 Hermitian complex block:
*
* [ a b ]
* [ b* d ]
*
* Returns c (real) and s (complex) such that:
*
* Jᴴ A J is diagonal
*
* with:
*
* J = [ c s ]
* [ -conj(s) c ]
*/
static readonly jacobi_hermitian_2x2: (a: ComplexType, b: ComplexType, d: ComplexType) => {
c: ComplexType;
s: ComplexType;
};
static readonly jacobi_complex_hermitian_dense: (A: ComplexType[][], maxSweeps?: NumLikeType, tol?: NumLikeType) => {
D: ComplexType[];
V: ComplexType[][];
};
/**
* Jacobi cyclic for Hermitian matrices. `T` is mutated in-place during the algorithm.
* @param T
* @param maxSweeps
* @param tol
* @returns
*/
static readonly jacobi_symmetric_hermitian: (T: ComplexType[][], maxSweeps?: number, tol?: number) => {
D: ComplexType[];
V: ComplexType[][];
};
static readonly jacobi_real_symmetric_structured_2n: (T: ComplexType[][], maxSweeps?: number, tol?: number) => {
D: ComplexType[];
V: ComplexType[][];
};
static readonly jacobi_hermitian_real2n: (T: ComplexType[][], maxSweeps?: number, tol?: number) => {
D: ComplexType[];
V: ComplexType[][];
};
static readonly jacobi_hermitian_real2n_direct: (diag: ComplexType[], offdiag: ComplexType[], maxSweeps?: number, tol?: number) => {
D: ComplexType[];
V: ComplexType[][];
};
static readonly numeric_jacobi_hermitian_via_real2n_final: (T: MultiArray, maxSweeps?: number, tol?: number) => {
D: ComplexType[];
Z: MultiArray;
};
static readonly jacobi_hermitian_dense: (T: MultiArray, tol: number, maxSweeps: number) => {
A: MultiArray;
Z: MultiArray;
};
static readonly numeric_jacobi_hermitian_direct: (D: ComplexType[], E: ComplexType[], maxSweeps?: number, tol?: number) => {
D_work: ComplexType[];
Z: MultiArray;
};
static readonly jacobi_hermitian_full: (T: MultiArray, maxSweeps?: number, tol?: number) => MultiArray;
static readonly numeric_jacobi_hermitian_direct_02: (D: ComplexType[], E: ComplexType[], maxSweeps?: number, tol?: number) => {
D_work: ComplexType[];
Z: MultiArray;
};
static readonly numeric_jacobi_hermitian_direct_03: (D: ComplexType[], E: ComplexType[], maxSweeps?: number, tol?: number) => {
D_work: ComplexType[];
Z: MultiArray;
};
/**
* Rotação de Jacobi para um bloco hermitiano 2×2
*
* [ a b ]
* [ b* d ]
*/
static readonly jacobiHermitian2x2: (a: number, d: number, b: ComplexType, tol?: number) => Jacobi2x2Result;
static readonly jacobi_hermitian_rotation: (T: MultiArray, Z: MultiArray, p: number, q: number) => void;
static readonly jacobi_rotate_hermitian: (A: MultiArray, Z: MultiArray, p: number, q: number) => void;
/**
* Atualiza a matriz acumuladora Z no estilo LAPACK:
*
* Z ← Z · G
*
* onde G é a rotação de Givens complexa no plano (k, k+1):
*
* [ c s ]
* [ -s* c ]
*
* c é real, s é complexo.
*/
static readonly apply_givens_right_Z: (Z: ComplexType[][], k: number, c: ComplexType, s: ComplexType) => void;
static readonly apply_givens_left_tridiagonal: (D: ComplexType[], E: ComplexType[], k: number, c: ComplexType, s: ComplexType) => void;
static readonly apply_givens_tridiagonal_hermitian: (D: ComplexType[], E: ComplexType[], k: number, c: ComplexType, s: ComplexType) => void;
static readonly apply_givens_right_tridiagonal: (D: ComplexType[], E: ComplexType[], k: number, c: ComplexType, s: ComplexType) => void;
static readonly compute_complex_givens: (x: ComplexType, z: ComplexType) => {
c: ComplexType;
s: ComplexType;
r: ComplexType;
};
static readonly complexGivens: (x: ComplexType, y: ComplexType) => {
c: ComplexType;
s: ComplexType;
r: ComplexType;
};
static readonly applyGivensToZ: (Z: MultiArray, k: number, c: ComplexType, s: ComplexType) => void;
static readonly applyGivensTridiagonal: (D: ComplexType[], E: ComplexType[], k: number, c: ComplexType, s: ComplexType) => void;
static readonly complex_gram_schmidt: (Z: MultiArray) => void;
static readonly implicitQRStepTridiagonalHermitian: (D: ComplexType[], E: ComplexType[], l: number, m: number, Z?: ComplexType[][]) => void;
/**
* One implicit-shift QR sweep on a Hermitian tridiagonal block [l..m+1].
* Literal extraction from steqr_vectors_tridiagonal (no changes).
*/
static readonly numeric_qr_sweep_tridiagonal_hermitian: (D: ComplexType[], E: ComplexType[], l: number, m: number, Z?: ComplexType[][]) => void;
static readonly numeric_qr_bulge_chasing_hermitian_1: (D: ComplexType[], E: ComplexType[], maxIts?: number) => {
D: ComplexType[];
V: ComplexType[][];
};
static readonly numeric_qr_bulge_chasing_hermitian: (D: ComplexType[], E: ComplexType[], maxSweeps?: number) => ComplexType[][];
static readonly numeric_steqr_tridiagonal_bulge: (D: ComplexType[], E: ComplexType[], maxIts?: number) => {
D: ComplexType[];
V: ComplexType[][];
};
static readonly numeric_qr_bulge_chasing_hermitian_refined: (D: ComplexType[], E: ComplexType[], maxSweeps?: number, tol?: number) => ComplexType[][];
static readonly numeric_qr_hermitian_tridiagonal: (D: ComplexType[], E: ComplexType[], maxSweeps?: number, tol?: number) => ComplexType[][];
static readonly qr_step_tridiagonal_hermitian: (D: ComplexType[], E: ComplexType[], Z: ComplexType[][]) => void;
static readonly qr_hermitian_tridiagonal: (D: ComplexType[], E: ComplexType[], tol: number, maxSweeps: number) => ComplexType[][];
static readonly numeric_tridiagonal_hermitian_bulge_chasing: (D: ComplexType[], // diagonal da matriz
E: ComplexType[], // subdiagonal (size n-1)
maxSweeps?: number) => {
D: ComplexType[];
E: ComplexType[];
Z: MultiArray;
};
static readonly zsteqr: (D: ComplexType[], E: ComplexType[], Z?: ComplexType[][], tol?: NumLikeType, maxIts?: NumLikeType) => {
D: ComplexType[];
Z?: ComplexType[][];
};
}
export type { ElementType };
export { LAPACKunused };
declare const _default: {
LAPACKunused: typeof LAPACKunused;
};
export default _default;