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_mat = {
type t
type~ mat [n] [m]
val zero: (n: i64) -> (m: i64) -> mat [n] [m]
val eye: (n: i64) -> (m: i64) -> mat [n] [m]
val trapezoidal [n] [m]: [n][m]t -> mat [n] [m]
val dense [n] [m]: mat [n] [m] -> [n][m]t
val idx [n] [m]: (i64, i64) -> mat [n] [m] -> t
val scale [n] [m]: t -> mat [n] [m] -> mat [n] [m]
val + [n] [m]: mat [n] [m] -> mat [n] [m] -> mat [n] [m]
val - [n] [m]: mat [n] [m] -> mat [n] [m] -> mat [n] [m]
val map [n] [m]: (t -> t) -> mat [n] [m] -> mat [n] [m]
val nnz [n] [m]: mat [n] [m] -> i64
val smm [n] [m] [k]: mat [n] [m] -> mat [m] [k] -> mat [n] [k]
}
val row : (i: i64) -> i64
val row_lower : (n: i64) -> (m: i64) -> (i: i64) -> i64
val col_lower : (n: i64) -> (m: i64) -> (i: i64) -> i64
module rank_lower: {
val rank: (i64, i64) -> (i64, i64) -> i64
val unrank: (i64, i64) -> (p: i64) -> (i64, i64)
val zero: (i64, i64) -> bool
val datasz: (i64, i64) -> i64
}
module type trapezoidal = {
type t
type~ lower [n] [m]
type~ upper [n] [m]
module lower: {
include trapezoidal_mat with t = t with mat [n] [m] = lower [n] [m]
val transpose [n] [m]: lower [n] [m] -> upper [m] [n]
}
module upper: {
include trapezoidal_mat with t = t with mat [n] [m] = upper [n] [m]
val transpose [n] [m]: upper [n] [m] -> lower [m] [n]
}
}
module mk_trapezoidal: (T: field) -> trapezoidal with t = T.t

Description

module type trapezoidal_mat

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 times m trapezoidal matrices.

val zero: (n: i64) -> (m: i64) -> mat [n] [m]

The zero matrix. Given n and m, the function returns an n times m empty sparse matrix (zeros everywhere).

val eye: (n: i64) -> (m: i64) -> mat [n] [m]

The eye. Given n and m, the function returns an n times m 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 matrix a.

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 by v.

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.

val row: (i: i64) -> i64
val row_lower: (n: i64) -> (m: i64) -> (i: i64) -> i64
val col_lower: (n: i64) -> (m: i64) -> (i: i64) -> i64
module type trapezoidal

The type of modules implementing trapezoidal matrices, with distinct submodules and types for lower and upper trapezoidal matrices.

type t

Matrix element type.

type~ lower [n] [m]

A lower trapezoidal matrix.

type~ upper [n] [m]

An upper trapezoidal matrix.

module lower

Operations on lower trapezoidal matrices.

include trapezoidal_mat with t = t with mat [n] [m] = lower [n] [m]
val transpose [n] [m]: lower [n] [m] -> upper [m] [n]

Transpose lower trapezoidal matrix, producing upper trapezoidal matrix. O(1).

module upper

Operations on upper trapezoidal matrices.

include trapezoidal_mat with t = t with mat [n] [m] = upper [n] [m]
val transpose [n] [m]: upper [n] [m] -> lower [m] [n]

Transpose upper trapezoidal matrix, producing lower trapezoidal matrix. O(1).

module mk_trapezoidal

Create a module implementing the trapezoidal module type. Usage: module m = mk_trapezoidal f64.