Mat

Matrix type for linear algebra

pure @safe nothrow
struct Mat (
T
size_t R
size_t C
) {}

Constructors

this
this(Args args)

Build a matrix from its elements. To be provided row major.

this
this(Args args)

Build a matrix from the provided rows. Each row must be an array (static or dynamic) and have the correct number of elements.

Members

Aliases

Column
alias Column = Vec!(T, rowLength)

The matrix columns type.

CompSeq
alias CompSeq = Repeat!(rowLength * columnLength, T)

Alias to a type sequence holding all components

Component
alias Component = T

The type of the componetypeof(rt.expand)nts.

Row
alias Row = Vec!(T, columnLength)

The matrix rows type.

RowSeq
alias RowSeq = Repeat!(rowLength, Row)

Alias to a type sequence holding all rows

Functions

column
Column column(size_t c)

Index a matrix column.

comp
T comp(size_t r, size_t c)

Index a matrix component

ct
void ct(Component comp)

Assign a compile time indexed component

ct
void ct(Row row)

Assign a row indexed at compile time

ctCol
void ctCol(Column col)

Assign a column indexed at compile time

opBinary
auto opBinary(Mat!(U, rowLength, UC) mat)

Build an augmented matrix (add oth to the right of this matrix)

opBinary
auto opBinary(Mat!(U, rowLength, columnLength) oth)

Add/Subtract by a matrix to its right.

opBinary
auto opBinary(Mat!(U, UR, UC) oth)

Multiply by a matrix to its right.

opBinary
auto opBinary(Vec!(U, N) vec)

Multiply a matrix by a vector to its right.

opBinary
auto opBinary(U val)

Operation of a matrix with a scalar on its right.

opBinaryRight
auto opBinaryRight(Vec!(U, N) vec)

Multiply a matrix by a vector to its left.

opBinaryRight
auto opBinaryRight(U val)

Operation of a matrix with a scalar on its left.

opCast
Mat!(U, rowLength, columnLength) opCast()

Cast a matrix to another type

opDollar
size_t opDollar()

Number of components per direction.

opIndex
T opIndex(size_t r, size_t c)

Index a matrix component.

opIndex
Row opIndex(size_t r)

Index a matrix row

opIndexAssign
void opIndexAssign(T val, size_t r, size_t c)

Assign a matrix component.

opIndexAssign
void opIndexAssign(Row row, size_t r)

Assign a row

opIndexOpAssign
void opIndexOpAssign(T val, size_t r, size_t c)

Apply op on a matrix component.

opOpAssign
auto opOpAssign(U val)

Assign operation of a matrix with a scalar on its right.

opOpAssign
auto opOpAssign(M mat)

Assign operation of a matrix with a matrix on its right.

row
Row row(size_t r)

Index a matrix row.

toString
string toString()
Undocumented in source. Be warned that the author may not have intended to support it.

Manifest constants

columnLength
enum columnLength;

The number of columns in the matrix.

compLength
enum compLength;

The number of components in the matrix;

identity
enum identity;

The identity matrix.

length
enum length;

row major container: length is the number of rows

rowLength
enum rowLength;

The number of rows in the matrix.

Properties

compTup
Tuple!CompSeq compTup [@property getter]

All components in a tuple

ct
Component ct [@property getter]

Index a component at compile time

ct
Row ct [@property getter]

Index a row at compile time

ctCol
Column ctCol [@property getter]

Index a column at compile time

data
inout(Component)[] data [@property getter]

Direct access to underlying data. Reminder: row major order!

rowTup
Tuple!RowSeq rowTup [@property getter]

All rows in a tuple

slice
Mat!(T, RE - RS, CE - CS) slice [@property getter]

Return a slice of the matrix

slice
Mat!(U, UR, UC) slice [@property setter]

Assign a slice of this matrix e.g:

mat.slice!(0, 2) = otherMat;

Examples

import gfx.math.approx : approxUlp;

assert(approxUlp(FMat2x2.identity, FMat2x2(
    1, 0,
    0, 1
)));
import gfx.math.approx : approxUlp;

immutable ml = Mat!(float, 2, 3)(
    1, 2, 3,
    4, 5, 6,
);
immutable mr = Mat!(float, 3, 2)(
    1, 2,
    3, 4,
    5, 6,
);
immutable exp = Mat!(float, 2, 2)(
    1+6+15,  2+8+18,
    4+15+30, 8+20+36
);
assert(approxUlp(ml * mr, exp));

Meta