struct

Matrix(T, M, N)

Inherits Indexable < Enumerable < Iterable < Struct < Value < Object

Generic, type-safe abstract matrix structure.

This structure provides an M x N rectangular array of any field T. That is, T must define operations for addition, subtraction, multiplication and division.

Where possible, all matrix operations provide validation at the type level.

Constructors

new

Creates Matrix, yielding the linear index for each element to provide an initial value.

Source

Class methods

build

Creates a Matrix, invoking initialiser with each pair of indices.

Source
from(list : StaticArray(T, A))

Creates a Matrix from elements contained within a StaticArray.

The matrix will be filled rows first, such that an array of

[1, 2, 3, 4]

becomes

| 1 2 | | 3 4 |

Source
identity(id = T.zero + 1)

Build the idenity matrix for the instanced type and dimensions.

id may be used to specify an identity element for the type. If unspecifed a numeric identity will be assumed.

Source
of(value : T)

Creates a Matrix with each element initialized as value.

Source
zero

Build a zero matrix (all elements populated with zero value of the type isntance).

Source

Instance methods

*(other : Matrix(_, A, B))

Performs a matrix multiplication with other.

Source
*(other)

Performs a scalar multiplication with other.

Source
+(other : Matrix)

Returns a new Matrix that is the result of performing a matrix addition with other

Source
-(other : Matrix)

Returns a new Matrix that is the result of performing a matrix subtraction with other

Source
==(other : Matrix(U, A, B)) forall U

Equality. Returns true if each element in self is equal to each corresponding element in other.

Source
==(other)

Equality with another object, or differently sized matrix. Always false.

Source
[](i : Int, j : Int) : T

Retrieves the value of the element at i,j.

Indicies are zero-based. Negative values may be passed for i and j to enable reverse indexing such that self[-1, -1] == self[M - 1, N - 1] (same behaviour as arrays).

Source
[]=(i : Int, j : Int, value : T)

Sets the value of the element at i,j.

Source
col(j : Int)

Gets the cotents of column j.

Source
cols

Count of columns.

Source
dimensions

Returns the dimensions of self as a tuple of {rows, cols}.

Source
map

Apply a morphism to all elements, returning a new Matrix with the result.

Source
map!

Apply an endomorphism to self, mutating all elements in place.

Source
map_with_index

ditto

Source
map_with_indices

ditto

Source
merge(other : Matrix(U, A, B), &block : T, U -> _) forall U

Merge with another similarly dimensions matrix, apply the passed block to each elemenet pair.

Source
row(i : Int)

Gets the contents of row i.

Source
rows

Count of rows.

Source
size

Gets the capacity (total number of elements) of self.

Source
transpose

Creates a new matrix that is the result of inverting the rows and columns of self.

Source
update(i, j, &block : T -> T)

Yields the current element at i,j and updates the value with the block's return value.

Source