package gg

  1. Overview
  2. Docs

Module Gg.M2Source

2D square matrices.

Sourcetype t = m2

The type for 2D square matrices.

Sourceval dim : int

dim is the dimension of rows and columns.

Sourcetype v = v2

The type for rows and columns as vectors.

Constructors, accessors and constants

Sourceval v : float -> float -> float -> float -> m2

v e00 e01 e10 e11 is a matrix whose components are specified in row-major order

Sourceval of_rows : v2 -> v2 -> m2

of_rows r0 r1 is the matrix whose rows are r0 and r1.

Sourceval of_cols : v2 -> v2 -> m2

of_cols c0 c1 is the matrix whose columns are c0 and c1.

Sourceval el : int -> int -> m2 -> float

el i j a is the element aij. See also the direct element accessors.

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

Sourceval row : int -> m2 -> v2

row i a is the ith row of a.

Raises Invalid_argument if i is not in [0;dim[.

Sourceval col : int -> m2 -> v2

col j a is the jth column of a.

Raises Invalid_argument if j is not in [0;dim[.

Sourceval zero : m2

zero is the neutral element for add.

Sourceval id : m2

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

Sourceval of_m3 : m3 -> m2

of_m3 m extracts the 2D linear part (top-left 2x2 matrix) of m.

Sourceval of_m4 : m4 -> m2

of_m4 m extracts the 2D linear part (top-left 2x2 matrix) of m.

Functions

Sourceval neg : m2 -> m2

neg a is the negated matrix -a.

Sourceval add : m2 -> m2 -> m2

add a b is the matrix addition a + b.

Sourceval sub : m2 -> m2 -> m2

sub a b is the matrix subtraction a - b.

Sourceval mul : m2 -> m2 -> m2

mul a b is the matrix multiplication a * b.

Sourceval emul : m2 -> m2 -> m2

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

Sourceval ediv : m2 -> m2 -> m2

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

Sourceval smul : float -> m2 -> m2

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

Sourceval transpose : m2 -> m2

transpose a is the transpose aT.

Sourceval trace : m2 -> float

trace a is the matrix trace trace(a).

Sourceval det : m2 -> float

det a is the determinant |a|.

Sourceval inv : m2 -> m2

inv a is the inverse matrix a-1.

2D space transformations

Sourceval rot2 : float -> m2

rot2 theta rotates 2D space around the origin by theta radians.

Sourceval scale2 : v2 -> m2

scale2 s scales 2D space in the x and y dimensions according to s.

Traversal

Sourceval map : (float -> float) -> m2 -> m2

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

Sourceval mapi : (int -> int -> float -> float) -> m2 -> m2

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

Sourceval fold : ('a -> float -> 'a) -> 'a -> m2 -> 'a

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

Sourceval foldi : ('a -> int -> int -> float -> 'a) -> 'a -> m2 -> 'a

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

Sourceval iter : (float -> unit) -> m2 -> unit

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

Sourceval iteri : (int -> int -> float -> unit) -> m2 -> unit

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

Predicates and comparisons

Sourceval for_all : (float -> bool) -> m2 -> bool

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

Sourceval exists : (float -> bool) -> m2 -> bool

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

Sourceval equal : m2 -> m2 -> bool

equal a b is a = b.

Sourceval equal_f : (float -> float -> bool) -> m2 -> m2 -> bool

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

Sourceval compare : m2 -> m2 -> int

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

Sourceval compare_f : (float -> float -> int) -> m2 -> m2 -> int

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

Formatters

Sourceval pp : Format.formatter -> m2 -> unit

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

Sourceval pp_f : (Format.formatter -> float -> unit) -> Format.formatter -> m2 -> unit

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

Element accessors

Sourceval e00 : m2 -> float
Sourceval e01 : m2 -> float
Sourceval e10 : m2 -> float
Sourceval e11 : m2 -> float