No matching definitions.

linalg/mat

src/linalg/mat.tur

dynamic :float matrix type and core operations

defstruct

mat

(defstruct mat [rows : int cols : int data : (Vec float)])

a row-major rows x cols float64 matrix over a heap (Vec float).

defn

mat-new

(mat-new [rows : int cols : int] :)

create a zero-initialized rows x cols matrix.

defn

mat-new-zeroed

(mat-new-zeroed [rows : int cols : int] :)

create a zero-initialized rows x cols matrix.

defn

mat-wrap

(mat-wrap [rows : int cols : int d : (Vec float)] :)

take ownership of a (Vec float) of rows*cols elements as a mat.

defmacro

mat-of

(mat-of [rows cols & xs])

build a rows x cols matrix from row-major float literals.

defn

mat-rows

(mat-rows [^borrow m : mat] :)

shape accessors.

defn

mat-cols

(mat-cols [^borrow m : mat] :)
defn

mat-shape

(mat-shape [^borrow m : mat] :)

(cons rows cols).

defn

mat-get

(mat-get [^borrow m : mat r : int c : int] :)

element at (r, c), row-major. Bounds-checked by the backing Vec.

defn

mat-set!

(mat-set! [^borrow m : mat r : int c : int v : float] :)

set element at (r, c).

defn

mat-free

(mat-free [m : mat] :)

free the matrix and its backing buffer.

defn

mat-identity

(mat-identity [n : int] :)

n x n identity matrix.

defn

mat-diag

(mat-diag [^borrow v : lavec] :)

n x n diagonal matrix from a vector's elements.

defn

mat-copy

(mat-copy [^borrow m : mat] :)

deep copy.

defn

mat-row

(mat-row [^borrow m : mat r : int] :)

copy of row r as a vector.

defn

mat-col

(mat-col [^borrow m : mat c : int] :)

copy of column c as a vector.

defn

mat-submat

(mat-submat [^borrow m : mat r0 : int c0 : int r1 : int c1 : int] :)

copy of submatrix [r0,r1) x [c0,c1).

defn

mat-add

(mat-add [^borrow a : mat ^borrow b : mat] :)

element-wise addition (dimensions must match).

defn

mat-sub

(mat-sub [^borrow a : mat ^borrow b : mat] :)

element-wise subtraction.

defn

mat-scale

(mat-scale [^borrow m : mat s : float] :)

scalar multiplication.

defn

mat-mul

(mat-mul [^borrow a : mat ^borrow b : mat] :)

matrix multiplication: (m x n) * (n x p) -> (m x p).

defn

mat-mul-vec

(mat-mul-vec [^borrow m : mat ^borrow v : lavec] :)

matrix-vector multiplication: (m x n) * n-vec -> m-vec.

defn

mat-transpose

(mat-transpose [^borrow m : mat] :)

transpose: (m x n) -> (n x m).

defn

mat-trace

(mat-trace [^borrow m : mat] :)

sum of diagonal elements (square matrices).

defn

mat-norm-fro

(mat-norm-fro [^borrow m : mat] :)

Frobenius norm.

defn

mat-norm-max

(mat-norm-max [^borrow m : mat] :)

maximum absolute element.

defn

mat-square?

(mat-square? [^borrow m : mat] :)

1 if rows == cols else 0.

defn

mat-approx-eq?

(mat-approx-eq? [^borrow a : mat ^borrow b : mat tol : float] :)

1 if all elements within tol and shapes match, else 0.

defn

la-vec-outer

(la-vec-outer [^borrow a : lavec ^borrow b : lavec] :)

outer product of two vectors: a (len m) (x) b (len n)

Internal definitions
__mzeros-- Private: build a zero-filled (Vec float) of length n.
__mat-zipwith-add-- arithmetic