GitHub
deepbox/linalg

Properties & Matrix Functions

Matrix inverses, norms, rank and determinant helpers, and special matrix constructors.
Matrix functions
inv
export declare function inv(a: Tensor): Tensor;

Compute the inverse of a matrix.

pinv
export declare function pinv(a: Tensor, rcond?: number): Tensor;

Compute the Moore-Penrose pseudo-inverse.

block_diag
export declare function block_diag(...matrices: Tensor[]): Tensor;

Construct a block-diagonal matrix from provided square matrices.

circulant
export declare function circulant(c: number[]): Tensor;

Create a circulant matrix from a vector.

companion
export declare function companion(c: number[]): Tensor;

Create a companion matrix from polynomial coefficients.

expm
export declare function expm(A: Tensor): Tensor;

Compute the matrix exponential exp(A).

hadamard
export declare function hadamard(n: number): Tensor;

Create a Hadamard matrix of order n.

hankel
export declare function hankel(c: number[], r?: number[]): Tensor;

Create a Hankel matrix from first column and optional last row.

hilbert
export declare function hilbert(n: number): Tensor;

Create a Hilbert matrix of size n.

kron
export declare function kron(A: Tensor, B: Tensor): Tensor;

Compute the Kronecker product of two matrices.

logm
export declare function logm(A: Tensor): Tensor;

Compute the matrix logarithm log(A).

matrix_power
export declare function matrix_power(A: Tensor, n: number): Tensor;

Raise a square matrix to an integer power.

sqrtm
export declare function sqrtm(A: Tensor): Tensor;

Compute the matrix square root sqrt(A).

toeplitz
export declare function toeplitz(c: number[], r?: number[]): Tensor;

Create a Toeplitz matrix from first column and optional first row.

vandermonde
export declare function vandermonde(x: number[], N?: number, increasing?: boolean): Tensor;

Create a Vandermonde matrix.

cond
export declare function cond(a: Tensor, _p?: number | "fro"): number;

Condition number of a matrix.

norm
export declare function norm(x: Tensor, ord?: number | "fro" | "nuc", axis?: Axis | Axis[], keepdims?: boolean): Tensor | number;

norm is exported by deepbox/linalg.

det
export declare function det(a: Tensor): number;

Compute the determinant of a matrix.

matrixRank
export declare function matrixRank(a: Tensor, tol?: number): number;

Compute the rank of a matrix.

slogdet
export declare function slogdet(a: Tensor): [Tensor, Tensor];

Compute sign and natural logarithm of the determinant.

trace
export declare function trace(a: Tensor, offset?: number, axis1?: Axis, axis2?: Axis): Tensor;

Compute the trace of a matrix.

linalg-properties.ts
import { cond, expm, hadamard, inv, matrix_power, norm, trace } from "deepbox/linalg";import { tensor } from "deepbox/ndarray";const a = tensor([[2, 0], [0, 3]]);console.log(inv(a).toString());console.log(norm(a));console.log(trace(a));console.log(cond(a));console.log(matrix_power(a, 3).toString());console.log(expm(a).toString());console.log(hadamard(4).toString());