mathjslab
Version:
MathJSLab - An interpreter with language syntax like MATLAB®/Octave, ISBN 978-65-00-82338-7.
204 lines (203 loc) • 8.48 kB
TypeScript
import { ComplexType } from './Complex';
import { type ElementType, MultiArray } from './MultiArray';
type BLASConfig = {
/**
* Minimal value for block multiplication version. Tune as needed.
*/
blockThreshold: number;
/**
* Block size.
*/
blockSize: number;
};
export declare const BLASConfigKeyTable: (keyof BLASConfig)[];
/**
* # BLAS (Basic Linear Algebra Subprograms)
*
* ## References
* - https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms
* - https://www.netlib.org/blas/
*/
declare abstract class BLAS {
/**
* `BLAS` default settings.
*/
static readonly defaultSettings: BLASConfig;
/**
* `BLAS` current settings.
*/
static readonly settings: BLASConfig;
/**
* Set configuration options for `BLAS`.
* @param config Configuration options.
*/
static readonly set: (config: Partial<BLASConfig>) => void;
/**
*
* @param x `ComplexType[]` vetor (`m`)
* @param y `ComplexType[]` vetor (`n`)
* @param C `C` `MultiArray` [`m x n`] (complex)
*/
static readonly geru: (x: ComplexType[], y: ComplexType[], C: MultiArray) => void;
/**
* Complex rank-1 update with conjugation on `x`
* > > `C := C + x * y^H`
* @param x `ComplexType[]` vetor (`m`)
* @param y `ComplexType[]` vetor (`n`)
* @param C `MultiArray` [`m x n`] (complex)
*/
static readonly gerc: (x: ComplexType[], y: ComplexType[], C: MultiArray) => void;
/**
* Complex rank-1 update with conjugation on `x`
* > > `C := C + conj(x) * y^H`
* Notes:
* - `x` and `y` can be 1D MultiArrays with arbitrary strides
* - Result is stored in `C`
* @param x `MultiArray` (vector)
* @param y `MultiArray` (vector)
* @param C `MultiArray` [`m x n`]
*/
static readonly gerc_nd: (x: MultiArray, y: MultiArray, C: MultiArray) => void;
/**
* ND-aware, direct:
* > > `C := C + conj(x) * y^H`
* Notes:
* - No flattening/copying; uses MultiArray linear <-> row/col conversion
* - `x` and `y` can be slices from higher-dim MultiArrays
* @param x 1D `MultiArray` (vector)
* @param y 1D `MultiArray` (vector)
* @param C 2D `MultiArray` [`m x n`]
*/
static readonly gerc_nd_direct: (x: MultiArray, y: MultiArray, C: MultiArray) => void;
/**
* Complex general matrix-vector multiplication.
*
* Computes:
* > > `y := alpha * A * x + beta * y`
*
* Only internal buffers are used: matrix `A` is `ComplexType[][]`, vectors `x`
* and `y` are `ComplexType[]`.
* This function is optimized for row-major storage and internal BLAS use.
* Offsets allow operating on submatrices and subvectors (as in LAPACK).
*
* @param A Matrix (row-major), size at least (`rowA + m`) x (`colA + n`)
* @param m Number of rows of submatrix `A`
* @param n Number of columns of submatrix `A`
* @param rowA Starting row offset inside `A`
* @param colA Starting column offset inside `A`
* @param x Input vector (`length >= rowX + n`)
* @param rowX Offset into vector `x`
* @param y Vector updated in-place (`length >= rowY + m`)
* @param rowY Offset into vector `y`
* @param alpha Scalar
* @param beta Scalar
*/
static readonly gemv: (A: ComplexType[][], m: number, n: number, rowA: number, colA: number, x: ComplexType[], rowX: number, y: ComplexType[], rowY: number, alpha: ComplexType, beta: ComplexType) => void;
/**
* Rank-1 update `A := A + alpha * x * y^H`
* For complex-case conjugate on second vector (gerc style).
* A: m x n as ComplexType[][], x length m, y length n
*
* @param A MultiArray contendo matriz base
* @param startRow linha inicial do bloco `A` a ser atualizado
* @param colStart coluna inicial do bloco `A` a ser atualizado
* @param m Comprimento do vetor `x`
* @param n comprimento do vetor `y`
* @param alpha
* @param xA MultiArray contendo o vetor `x` (parte real)
* @param xRow linha inicial do vetor `x`
* @param xCol coluna inicial do vetor `x`
* @param yA MultiArray contendo o vetor `y` (parte imaginária)
* @param yRow linha inicial do vetor `y`
* @param yCol coluna inicial do vetor `y`
*/
static readonly ger: (A: ComplexType[][], startRow: number, colStart: number, m: number, n: number, alpha: ComplexType, xA: ComplexType[][], xRow: number, xCol: number, yA: ComplexType[][], yRow: number, yCol: number) => void;
/**
* Blocked multiplication kernel for complex matrices.
* Multiply a sub-block of `A` and `B` and accumulate into `R`.
*
* Computes the block:
* `R[ii:iMax-1][jj:jMax-1] += A[ii:iMax-1, kk:kMax-1] * B[kk:kMax-1, jj:jMax-1]`
*
* @param A left matrix (`m x k`)
* @param B right matrix (`k x n`)
* @param R result matrix (`m x n`), updated in-place
* @param ii..iMax row range in `A` and `R` (`i`)
* @param jj..jMax col range in `B` and `R` / resulting columns (`j`)
* @param kk..kMax inner dimension range (columns of `A` / rows of `B`)
*/
static readonly gemm_kernel: (A: ComplexType[][], B: ComplexType[][], R: ComplexType[][], ii: number, iMax: number, jj: number, jMax: number, kk: number, kMax: number) => void;
/**
* Complex general matrix-matrix multiplication. Hybrid
* implementation: simple for small matrices, blocked for large ones. Uses
* `ComplexType` elements with fully preallocated rows.
*
* Computes:
* > > `C := alpha * A * B + beta * C`
*
* Uses blocked multiplication for large matrices and simple triple loop for small ones.
*
* A: `m x k`, B: `k x n`, C: `m x n` - all raw `ComplexType[][]`
* Uses blocking on k dimension and on i/j using `BLAS.settings.blockSize`.
*
* @param alpha scalar multiplier for `A*B`
* @param A left matrix (`m x k`)
* @param m number of rows of `A`
* @param k number of columns of `A` (and rows of `B`)
* @param B right matrix (`k x n`)
* @param n number of columns of `B`
* @param beta scalar multiplier for `C`
* @param C result matrix (`m x n`), updated in-place
*/
static readonly gemm: (alpha: ComplexType, A: ComplexType[][], m: number, k: number, B: ComplexType[][], n: number, beta: ComplexType, C: ComplexType[][]) => void;
/**
*
* @param alpha
* @param A
* @param startRow
* @param endRow
* @param col
* @returns
*/
static readonly scal: (alpha: ComplexType, A: MultiArray, startRow: number, endRow: number, col: number) => void;
/**
* Computes the Hermitian dot product of the tail of a column of A with itself.
*
* This function evaluates:
* sigma = sum_{i = startRow+1}^{m-1} conj(A[i, col]) * A[i, col]
*
* It is equivalent to the BLAS operation ZDOTC applied to the subvector
* A[startRow+1 : m-1, col], and is typically used in the construction of
* complex Householder reflectors (e.g., in LAPACK's xLARFG).
* @param A MultiArray representing the matrix.
* @param col Column index to operate on.
* @param startRow Row index whose tail (startRow+1 .. end) is used.
* @returns The Hermitian dot product as a Complex value.
*/
static readonly dotc_col: (A: MultiArray, col: number, startRow: number) => ComplexType;
/**
* Computes the Hermitian dot product of the tail of a row of A with itself.
*
* This function evaluates:
* sigma = sum_{j = startCol+1}^{n-1} conj(A[row, j]) * A[row, j]
*
* It is equivalent to the BLAS operation ZDOTC applied to the subvector
* A[row, startCol+1 : n-1], and is typically used in the construction of
* complex Householder reflectors for right-side operations (e.g., LAPACK's xLARFG).
*
* @param A MultiArray representing the matrix.
* @param row Row index to operate on.
* @param startCol Column index whose tail (startCol+1 .. end) is used.
* @returns The Hermitian dot product as a Complex value.
*/
static readonly dotc_row: (A: MultiArray, row: number, startCol: number) => ComplexType;
static functions: {
[F in keyof BLAS]: Function;
};
}
export type { ElementType };
export { BLAS };
declare const _default: {
BLAS: typeof BLAS;
};
export default _default;