Abstract

Small library of simple linear algebra-ish operations.

Synopsis

local module type linalg = {
type t
val dotprod [n]: [n]t -> [n]t -> t
val outer [n] [m]: [n]t -> [m]t -> [n][m]t
val cross: [3]t -> [3]t -> [3]t
val matvecmul_row [n] [m]: [n][m]t -> [m]t -> [n]t
val matvecmul_col [n] [m]: [n][m]t -> [n]t -> [n][n]t
val matmul [n] [p] [m]: [n][p]t -> [p][m]t -> [n][m]t
val kronecker [n] [m] [p] [q]: [m][n]t -> [p][q]t -> [][]t
val kronecker' [m] [n] [p] [q]: [m][n]t -> [p][q]t -> [m][n][p][q]t
val inv [n]: [n][n]t -> [n][n]t
val ols [n] [m]: [n][m]t -> [n]t -> [m]t
}
module type field = {
type t
val +: t -> t -> t
val -: t -> t -> t
val *: t -> t -> t
val /: t -> t -> t
val negate: t -> t
val <: t -> t -> bool
val i32: i32 -> t
val abs: t -> t
val fma: t -> t -> t -> t
}
module mk_linalg: (T: field) -> linalg with t = T.t

Description

local module type linalg
type t

The scalar type.

val dotprod [n]: [n]t -> [n]t -> t

Dot product.

val outer [n] [m]: [n]t -> [m]t -> [n][m]t

Outer product.

val cross: [3]t -> [3]t -> [3]t

Cross product (only for three-element vectors).

val matvecmul_row [n] [m]: [n][m]t -> [m]t -> [n]t

Multiply a matrix with a row vector.

val matvecmul_col [n] [m]: [n][m]t -> [n]t -> [n][n]t

Multiply a matrix with a column vector.

val matmul [n] [p] [m]: [n][p]t -> [p][m]t -> [n][m]t

Multiply two matrices.

val kronecker [n] [m] [p] [q]: [m][n]t -> [p][q]t -> [][]t

Kronecker product of two matrices.

val kronecker' [m] [n] [p] [q]: [m][n]t -> [p][q]t -> [m][n][p][q]t

Kronecker product of two matrices, but preserving the blocked structure in the result.

val inv [n]: [n][n]t -> [n][n]t

Compute the inverse of a matrix.

val ols [n] [m]: [n][m]t -> [n]t -> [m]t

Solve linear system.

module type field
type t
val +: t -> t -> t
val -: t -> t -> t
val *: t -> t -> t
val /: t -> t -> t
val negate: t -> t
val <: t -> t -> bool
val i32: i32 -> t
val abs: t -> t
val fma: t -> t -> t -> t
module mk_linalg

Given some numeric type, produce a linalg module.