Template Class TinyMatrix

Class Documentation

template<class ValueType, unsigned M, unsigned N = M, unsigned align = alignof(ValueType)>
class qhipster::TinyMatrix

A small matrix with dimensions fixed at compile time.

The matrix is stored intenally as a two-dimensional C array, and thus in row-major ordering.

Public Types

using value_type = ValueType

the the of elements stored in the matrix

using pointer = ValueType*

a pointer to elements of the matrix

using const_pointer = ValueType const*

a pointer o elements of a const matrix

using reference = ValueType&

a reference to elements of the matrix

using size_type = unsigned

an integral type large enought to store the size of the matrix

using RowType = ValueType[N]

the type for a row of the matrix

Public Functions

TinyMatrix()

default-initizlize all matrix elements

template<class U>
TinyMatrix(U init[M][N])

initialize from a C-style array of the same dimensions

template<class U>
TinyMatrix(std::initializer_list<std::initializer_list<U>> const &init)

initialize from an initializer list, i.e. a compile time given matrix

template<class U, unsigned alignrhs>
TinyMatrix(TinyMatrix<U, M, N, alignrhs> const &rhs)

copy from a matrix with a potentially different type and alignment

TinyMatrix(TinyMatrix const&) = default

the defaiult copy constructor

TinyMatrix &operator=(TinyMatrix const&) = default

the default assignment

template<class U, unsigned alignrhs>
TinyMatrix &operator=(TinyMatrix<U, M, N, alignrhs> const &rhs)

assign from a matrix with a potentially different type and alignment

template<class U>
TinyMatrix &operator=(U const (&rhs)[M][N])

assign from a C-style array

constexpr size_type numRows() const

the number of matrix rows

constexpr size_type numCols() const

the number of matrix columns

constexpr size_type size() const

the size of the matrix, i.e. the number of matrix elements. This is the same as number of rows times number of columns

value_type operator()(unsigned i, unsigned j) const

access a matrix element of a const matrix

Pre

i<numRows() & j<numCols()

Parameters
  • i: the row index

  • j: the column index

reference operator()(unsigned i, unsigned j)

access a matrix element

Pre

i<numRows() & j<numCols()

Parameters
  • i: the row index

  • j: the column index

template<class U, unsigned alignrhs>
bool operator==(TinyMatrix<U, M, N, alignrhs> const &rhs) const

compare two matrices element-wise for equality

template<class U, unsigned alignrhs>
bool operator!=(TinyMatrix<U, M, N, alignrhs> const &rhs) const

compare two matrices element-wise for inequality

template<class U>
bool operator==(U const (&rhs)[M][N])

compare two matrices element-wise for equality

template<class U>
bool operator!=(U const (&rhs)[M][N])

compare two matrices element-wise for inequality

const_pointer getPtr() const

obtain a pointer to the first element of the matrix

RowType &operator[](unsigned i)

C-style array subscript

the TinyMatrix can be indexed both using the mat(i,j) syntax or the C-style mat[i][j] syntax

RowType const &operator[](unsigned i) const

C-style array subscript for a const matrix

the TinyMatrix can be indexed both using the mat(i,j) syntax or the C-style mat[i][j] syntax

template<unsigned MSub, unsigned NSub = MSub>
TinyMatrix<ValueType, MSub, NSub, align> getSubMatrix(unsigned i_start = 0, unsigned j_start = 0, unsigned i_stride = 1, unsigned j_stride = 1) const

Get submatrices

Returns the submatrix starting at i_start, j_start of size MSub, NSub using stride i_stride, j_stride

Pre

Strides are strictly positive

Pre

Parameters actually represent a submatrix (no index out of bounds)

Parameters
  • i_start: The starting row index \þaram j_start The starting column index

  • i_stride: The row stride to use for accessing elements

  • j_stride: The column stride to use for accessing elements

Template Parameters
  • MSub: The number of rows of the submatrix

  • NSub: The number of columns of the submatrix

void print(std::string name)
std::string tostr() const

Public Members

std::string name