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