Module type Gg.M

Implemented by all (square) matrix types.

type t

The type for matrices.

val dim : int

dim is the dimension of rows and columns.

type v

The type for rows and columns as vectors.

Constructors, accessors and constants

val el : int -> int -> t -> float

el i j a is the element aij.

  • raises Invalid_argument

    if i or j is not in [0;dim[.

val row : int -> t -> v

row i a is the ith row of a.

  • raises Invalid_argument

    if i is not in [0;dim[.

val col : int -> t -> v

col j a is the jth column of a.

  • raises Invalid_argument

    if j is not in [0;dim[.

val zero : t

zero is the neutral element for add.

val id : t

id is the identity matrix, the neutral element for mul.

Functions

val neg : t -> t

neg a is the negated matrix -a.

val add : t -> t -> t

add a b is the matrix addition a + b.

val sub : t -> t -> t

sub a b is the matrix subtraction a - b.

val mul : t -> t -> t

mul a b is the matrix multiplication a * b.

val emul : t -> t -> t

emul a b is the element wise multiplication of a and b.

val ediv : t -> t -> t

ediv a b is the element wise division of a and b.

val smul : float -> t -> t

smul s a is a's elements multiplied by the scalar s.

val transpose : t -> t

transpose a is the transpose aT.

val trace : t -> float

trace a is the matrix trace trace(a).

val det : t -> float

det a is the determinant |a|.

val inv : t -> t

inv a is the inverse matrix a-1.

Traversal

val map : (float -> float) -> t -> t

map f a is the element wise application of f to a.

val mapi : (int -> int -> float -> float) -> t -> t

mapi f a is like map but the element indices are also given.

val fold : ('a -> float -> 'a) -> 'a -> t -> 'a

fold f acc a is f (...(f (f acc a00) a10)...).

val foldi : ('a -> int -> int -> float -> 'a) -> 'a -> t -> 'a

foldi f acc a is f (...(f (f acc 0 0 a00) 1 0 a10)...).

val iter : (float -> unit) -> t -> unit

iter f a is f a00; f a10; ...

val iteri : (int -> int -> float -> unit) -> t -> unit

iteri f a is f 0 0 a00; f 1 0 a10; ...

Predicates and comparisons

val for_all : (float -> bool) -> t -> bool

for_all p a is p a00 && p a10 && ...

val exists : (float -> bool) -> t -> bool

exists p a is p a00 || p a10 || ...

val equal : t -> t -> bool

equal a b is a = b.

val equal_f : (float -> float -> bool) -> t -> t -> bool

equal_f eq a b tests a and b like equal but uses eq to test floating point values.

val compare : t -> t -> int

compare a b is Pervasives.compare a b. That is lexicographic comparison in column-major order.

val compare_f : (float -> float -> int) -> t -> t -> int

compare_f cmp a b compares a and b like compare but uses cmp to compare floating point values.

Printers

val pp : Format.formatter -> t -> unit

pp ppf a prints a textual representation of a on ppf.

val pp_f : (Format.formatter -> float -> unit) -> Format.formatter -> t -> unit

pp_f pp_e ppf a prints a like pp but uses pp_e to print floating point values.