Module matrix

Types

Matrix[N, M] = object
  data*: ref array[N * M, float]
  when true: p
  
  Source Edit

Procs

proc `[]`[N, M: static[int]](m: Matrix[N, M]; i, j: int): float {.
inline
.}
  Source Edit
proc `[]=`[N, M: static[int]](m: var Matrix[N, M]; i, j: int; val: float) {.
inline
.}
  Source Edit
proc eq[N, M: static[int]](m, w: Matrix[N, M]; epsilon: float = Epsilon): bool
Equality up to epsilon precision.   Source Edit
proc `==`[N, M: static[int]](m, w: Matrix[N, M]; epsilon: float = Epsilon): bool {.
inline
.}
ALias for eq   Source Edit
proc `===`[N, M: static[int]](m, w: Matrix[N, M]): bool
Exact equality. Beware floating point errors.   Source Edit
proc `$`[N, M: static[int]](m: Matrix[N, M]): string
  Source Edit
proc toMatrix[K: static[int]](arr: Array[K]; N, M: static[int]): Matrix[N, M]

Shape the arr array into a matrix with N rows and M columns.

If the length of the array is less than N*M, the array elements will be copied in the matrix, leaving excess matrix element to 0.0

The array needs to have N*M or less elements

  Source Edit
proc matrix[N, M: static[int]](arr: BiArray[N, M]): Matrix[N, M]
Create a matrix from a 2-D array of floats.   Source Edit
proc identity(N: static[int]): Matrix[N, N]
Return the identity matrix with dimension NxN   Source Edit
proc dims[N, M: static[int]](m: Matrix[N, M]): tuple[rows: int, cols: int] {.
inline
.}
Return the dimension of a matrix as a tuple of ints (rows,cols)   Source Edit
proc row[N, M: static[int]](m: Matrix[N, M]; r: int): RowVector[M]
Return a copy of row r from the matrix as a rowvector   Source Edit
proc overWriteRow[N, M: static[int]](m: var Matrix[N, M]; r: int; rowv: RowVector[M])
Overwrite row r in the matrix m ( r needs to be a row vector )   Source Edit
proc col[N, M: static[int]](m: Matrix[N, M]; c: int): ColVector[N]
Return a copy of col c from the matrix as a colvector   Source Edit
proc t[N, M: static[int]](m: Matrix[N, M]): Matrix[M, N]
Transpose the matrix.   Source Edit
proc reshape[N, M: static[int]](m: Matrix[N, M]; U, V: static[int]): Matrix[U, V]
Return a new matrix with dims (U,V) from a matrix with dims (N,M)   Source Edit
proc matMul[N, M, V: static[int]](m: Matrix[N, M]; w: Matrix[M, V]): Matrix[N, V]
Matrix-Matrix multiplication. Can use openblas. The nim implementation is a naive double loop, for now.   Source Edit
proc `*`[N, M, V: static[int]](m: Matrix[N, M]; w: Matrix[M, V]): Matrix[N, V] {.
inline
.}
Shorthand for matmul   Source Edit
proc vecMatMul[N, M: static[int]](m: Matrix[N, M]; v: ColVector[M]): ColVector[N]
Matrix-vector multiplication. The vector needs to be a column vector. Return a column vector.   Source Edit
proc vecMatMul[N, M: static[int]](v: RowVector[N]; m: Matrix[N, M]): RowVector[M]
vector-matrix multiplication. Vector needs to be a row vector. Return a row vector.   Source Edit
proc `*`[N, M: static[int]](m: Matrix[N, M]; v: ColVector[M]): ColVector[N] {.
inline
.}
Shorthand for vecmatmul   Source Edit
proc `*`[N, M: static[int]](v: RowVector[N]; m: Matrix[N, M]): RowVector[M] {.
inline
.}
Shorthand for vecmatmul   Source Edit
proc matAdd[N, M: static[int]](m, w: Matrix[N, M]): Matrix[N, M]
Add two matrices with same dimensions.   Source Edit
proc `+`[N, M: static[int]](m: Matrix[N, M]; w: Matrix[N, M]): Matrix[N, M] {.
inline
.}
Shorthand for matadd   Source Edit
proc matSub[N, M: static[int]](m, w: Matrix[N, M]): Matrix[N, M]
Subtract two matrices with same dimensions.   Source Edit
proc `-`[N, M: static[int]](m: Matrix[N, M]; w: Matrix[N, M]): Matrix[N, M] {.
inline
.}
shorthand to matsub   Source Edit
proc elMatMul[N, M: static[int]](val: float; m: Matrix[N, M]): Matrix[N, M]
Multiply every element in matrix by a float.   Source Edit
proc `.*`[N, M: static[int]](val: float; m: Matrix[N, M]): Matrix[N, M] {.
inline
.}
shorthand to elMatMul   Source Edit
proc elMatDiv[N, M: static[int]](m: Matrix[N, M]; val: float): Matrix[N, M]
Divide every element in matrix by a float.   Source Edit
proc `./`[N, M: static[int]](m: Matrix[N, M]; val: float): Matrix[N, M] {.
inline
.}
shorthand to elMatDiv   Source Edit
proc elMatAdd[N, M: static[int]](m: Matrix[N, M]; val: float): Matrix[N, M]
  Source Edit
proc `.+`[N, M: static[int]](m: Matrix[N, M]; val: float): Matrix[N, M] {.
inline
.}
shorthand to elMatAdd   Source Edit
proc elMatSub[N, M: static[int]](m: Matrix[N, M]; val: float): Matrix[N, M]
  Source Edit
proc `.-`[N, M: static[int]](m: Matrix[N, M]; val: float): Matrix[N, M] {.
inline
.}
shorthand to elMatSub   Source Edit
proc subtractVecFromRow[N, M: static[int]](A: var Matrix[N, M]; row: int;
                                        vec: RowVector[M]; times: float = 1.0'f64)
Subtract in place a vector from a matrix row, can also specify how many times to subtract.   Source Edit
proc subtractVecFromCol[N, M: static[int]](A: var Matrix[N, M]; col: int;
                                        vec: ColVector[N]; times: float = 1.0'f64)
Same as subtractVecFromRow, but for cols.   Source Edit
proc divRowBy[N, M: static[int]](A: var Matrix[N, M]; row: int; val: float)
Divide a row in a matrix by a float. Modifies the matrix in place   Source Edit
proc divColBy[N, M: static[int]](A: var Matrix[N, M]; col: int; val: float)
Divide a col in a matrix by a float. Modifies the matrix in place   Source Edit
proc norm[N, M: static[int]](m: Matrix[N, M]): float
  Source Edit
proc row[N, M: static[int]](m: var Matrix[N, M]; r: int;
                         rowv: RowVector[M] | array[M, float] | seq[float])
Overwrite row r in the matrix m ( r needs to be a row vector,array or seq )   Source Edit
proc col[N, M: static[int]](m: var Matrix[N, M]; c: int;
                         colv: ColVector[N] | array[N, float] | seq[float])
Overwrite col c in the matrix m ( c needs to be a col vector, array or seq )   Source Edit

Iterators

iterator rows[N, M: static[int]](m: Matrix[N, M]): RowVector[M] {.
inline
.}
iterates over rows. Each row is a copy   Source Edit
iterator cols[N, M: static[int]](m: Matrix[N, M]): ColVector[M] {.
inline
.}
Iterate over columns. The column is a copy.   Source Edit