Abstract
Sparse trapezoidal matrices.
A trapezoidal matrix is an n
times m
matrix where all elements
above or below the diagonal are zero, called respectively upper
and lower trapezoidal matrixes. While we can always represent an
n
times m
trapezoidal matrix as an ordinary n
times m
matrix where we store the zeroes, a less wasteful representation is
possible. Instead, we can use a representation where we store only
the possibly nonzero elements. This library supports both upper
and lower trapezoidal matrices using the same interface, but
different concrete types. Notice that trapezoidal matrices, in
contrast to triangular matrices, are not required to be square.
Synopsis
module type trapezoidal_matrix = {
| |||||||||||||||||||||||||||||||||||||||||
module type trapezoidal = {
| |||||||||||||||||||||||||||||||||||||||||
module mk_trapezoidal | : | (T: field) -> trapezoidal with t = T.t |
Description
- ↑module type trapezoidal_matrix
The module type of a trapezoidal matrix. This module type leaves it unstated whether it is an upper or lower trapezoidal matrix, but specific instantiations make it clear.
- ↑type t
The scalar type.
- ↑type~ mat [n] [m]
The type of
n
timesm
trapezoidal matrices.- ↑val zero: (n: i64) -> (m: i64) -> mat [n] [m]
The zero matrix. Given
n
andm
, the function returns ann
timesm
empty sparse matrix (zeros everywhere).- ↑val eye: (n: i64) -> (m: i64) -> mat [n] [m]
The eye. Given
n
andm
, the function returns ann
timesm
sparse matrix with ones in the diagonal and zeros elsewhere.- ↑val trapezoidal [n] [m]: [n][m]t -> mat [n] [m]
- ↑val dense [n] [m]: mat [n] [m] -> [n][m]t
Convert to dense format. Given a sparse matrix, the function returns a dense representation of the matrix.
- ↑val idx [n] [m]: (i64, i64) -> mat [n] [m] -> t
idx (i,j) a
produces the element at logical position(i,j)
in the trapezoidal matrixa
.- ↑val scale [n] [m]: t -> mat [n] [m] -> mat [n] [m]
Scale elements. Given a matrix and a scale value
v
, the function returns a new matrix with the elements scaled byv
.- ↑val + [n] [m]: mat [n] [m] -> mat [n] [m] -> mat [n] [m]
Element-wise addition.
- ↑val - [n] [m]: mat [n] [m] -> mat [n] [m] -> mat [n] [m]
Element-wise subtraction.
- ↑val map [n] [m]: (t -> t) -> mat [n] [m] -> mat [n] [m]
Map a function across the elements of the matrix.
- ↑val nnz [n] [m]: mat [n] [m] -> i64
Number of non-zero elements.
- ↑val smm [n] [m] [k]: mat [n] [m] -> mat [m] [k] -> mat [n] [k]
Matrix multiplication.
- ↑module type trapezoidal
The type of modules implementing trapezoidal matrices, with distinct submodules and types for lower and upper trapezoidal matrices.
- ↑module mk_trapezoidal
Create a module implementing the
trapezoidal
module type. Usage:module m = mk_trapezoidal f64
.