Linear Algebra
Core operations for vector and matrix calculations via SciMathJS. High-performance implementations utilize BLAS-like routines optimized for WASM.
Usage
import { SciMathJS } from '@velo-sci/sci-math-wasm';
const a = new Float64Array([1, 2, 3]);
const b = new Float64Array([4, 5, 6]);
const dot = SciMathJS.dotProduct(a, b);API Reference
dotProduct
Calculates the dot product of two equal-length vectors.
Background: The dot product represents the projection of one vector onto another. In WASM, this is implemented using SIMD instructions (FMA - Fused Multiply-Add) for maximum throughput.
Formula:
Signature:
function dotProduct(a: Float64Array | number[], b: Float64Array | number[]): numbernormalize
Normalizes a vector to unit length (L2 norm).
Formula:
Where
Signature:
function normalize(data: Float64Array | number[]): Float64ArraymatrixMultiply
Multiplies two matrices represented as flat arrays.
Algorithm: Uses a Cache-Oblivious Tiled Matrix Multiplication algorithm. This reduces cache misses by breaking the matrices into smaller blocks that fit into the L1/L2 cache. For large matrices, it utilizes multi-threaded execution via Rayon.
Formula:
Signature:
function matrixMultiply(
a: Float64Array | number[], rowsA: number, colsA: number,
b: Float64Array | number[], rowsB: number, colsB: number
): Float64Arraytranspose
Transposes a matrix (flips it over its diagonal).
Signature:
function transpose(data: Float64Array | number[], rows: number, cols: number): Float64ArraysolveLinearSystem
Solves a linear system .
Algorithm: Uses Gaussian elimination with partial pivoting to ensure numerical stability.
- Decomposition: Matrix is converted to upper triangular form.
- Back-substitution: Variable is solved first, then and so on.
Signature:
function solveLinearSystem(a: Float64Array | number[], b: Float64Array | number[], n: number): Float64Arrayinvert2x2 / invert3x3
Inverts small matrices directly for high performance using Cramer's rule.
Signature:
function invert2x2(m: Float64Array | number[]): Float64Array
function invert3x3(m: Float64Array | number[]): Float64Arraytrace
Calculates the trace of a square matrix (sum of diagonal elements).
Signature:
function trace(matrix: Float64Array | number[], n: number): numberdetLU
Calculates the determinant of a square matrix using LU decomposition.
Algorithm: Performs Lower-Upper (LU) decomposition such that . The determinant is then:
where is the number of row swaps.
Signature:
function detLU(matrix: Float64Array | number[], n: number): number