Static Matrix#

template<typename ElemType, int NRows, int NCols>
class StaticMatrix : public mocca::MatrixBase<StaticMatrix<ElemType, NRows, NCols>>#

Object representing a matrix with a fixed size at compile time. It is based on the std::array class from the STL.

See Static Matrix in Basic Datatypes for more information.

Template Parameters:

  • ElemType - Numeric type of the elements in the matrix (i.e., any integral, floating-point or std::complex types).

  • NRows - Number of rows.

  • NCols - Number of columns.

Note

This object will behave like a vector if one of the dimensions are set to 1. For convenience, fixed-size row vector can be referred as StaticRowVector and column vector, as StaticVector.

Constructors

constexpr StaticMatrix()#

Default Constructor. Complexity: Constant

constexpr StaticMatrix(ElemType val)#

Creates a StaticMatrix and fills with copies of val.

Parameters:
  • cols[in] number of columns

  • rows[in] number of rows

  • val[in] value to initialize the matrix with Complexity: Linear in cols * rows

template<typename T>
constexpr StaticMatrix(const StaticMatrix<T, NRows, NCols> &other)#

Copy construct. Creates a StaticMatrix and then copy the content from an other matrix.

Parameters:

other[in] another StaticMatrix to use as data source Complexity: Linear in other.size()

constexpr StaticMatrix(const StaticMatrix &other)#

Copy construct. Creates a StaticMatrix and then copy the content from an other matrix.

Parameters:

other[in] another StaticMatrix to use as data source Complexity: Linear in other.size()

constexpr StaticMatrix(StaticMatrix &&other)#

Copy construct. Creates a StaticMatrix and then copy the content from an other matrix.

Parameters:

other[in] another StaticMatrix to use as data source Complexity: Linear in other.size()

template<typename T>
constexpr StaticMatrix(std::initializer_list<T> ilist)#

Creates a StaticMatrix from a initializer list.

Parameters:

ilist[in] initializer list to use as data source Complexity: Linear in ilist size

template<typename E>
constexpr StaticMatrix(const MatrixBase<E> &expr)#

Creates a StaticMatrix from an expression.

Parameters:

expr[in] an expression

Throws:

std::length_error – if the dimensions of the operands in``expr`` do not match. Complexity: Linear in this->size()

Assignment

template<typename T>
constexpr StaticMatrix &operator=(const StaticMatrix<T, NRows, NCols> &other)#

Copy Assignment Operator. Replaces StaticMatrix content with the contents of other matrix.

Parameters:

other[in] another StaticMatrix to use as data source

Returns:

*this Complexity: Linear in other.size()

constexpr StaticMatrix &operator=(const StaticMatrix &other)#

Copy Assignment Operator. Replaces StaticMatrix content with the contents of other matrix.

Parameters:

other[in] another StaticMatrix to use as data source

Returns:

*this Complexity: Linear in other.size()

template<typename T>
constexpr StaticMatrix &operator=(std::initializer_list<T> ilist)#

Replaces the StaticMatrix content with the values defined in the initializer list.

Parameters:

ilist[in] initializer list to use as data source

Returns:

*this Complexity: Linear in ilist.size()

template<typename E>
constexpr StaticMatrix &operator=(const MatrixBase<E> &expr)#

Evaluates the expression and assign the result to the StaticMatrix.

Parameters:

expr[in] a matrix or vector expression

Throws:

std::length_error – if the dimensions of the operands in``expr`` do not match and cannot be broadcasted. Complexity: Linear in expr.size()

Returns:

*this

constexpr void fill(ElemType val)#

Fills the StaticMatrix with copies of val.

Parameters:

val[in] value to replace the matrix content with Complexity: Linear in this->size()

Element Access

constexpr ElemType *data() noexcept#

Complexity: Constant

Note

If empty() = true, data() returns a nullptr.

Returns:

Raw pointer to the internal memory allocation

constexpr const ElemType *data() const noexcept#

Complexity: Constant

Note

If empty() = true, data() returns a nullptr.

Returns:

Raw pointer to the internal memory allocation

constexpr ElemType &front()#

Complexity: Constant

Returns:

a reference to the first element of the container

constexpr ElemType &front() const#

Complexity: Constant

Returns:

a const reference to the first element of the container

constexpr ElemType &back()#

Complexity: Constant

Returns:

a reference to the last element of the container

constexpr ElemType &back() const#

Complexity: Constant

Returns:

a const reference to the last element of the container

constexpr ElemType &operator[](index_t idx)#

Accesses element at idx position.

Complexity: Constant

Parameters:

idx[in] position of the element to return

Returns:

a reference to the requested element

constexpr ElemType operator[](index_t idx) const#

Accesses element at idx position.

Complexity: Constant

Parameters:

idx[in] position of the element to return

Returns:

the requested element

constexpr ElemType &operator()(index_t row, index_t col)#

Accesses the matrix element at (row, col).

Parameters:
  • row[in] row of the requested element

  • col[in] column of the requested element

Returns:

the reference to requested element Complexity: Constant

constexpr ElemType operator()(index_t row, index_t col) const#

Accesses the matrix element at (row, col).

Parameters:
  • row[in] row of the requested element

  • col[in] column of the requested element

Returns:

the requested element Complexity: Constant

Capacity

constexpr index_t rows() const noexcept#
Returns:

the number of rows in the StaticMatrix Complexity: Constant

constexpr index_t cols() const noexcept#
Returns:

the number of columns in the StaticMatrix Complexity: Constant

constexpr index_t size() const noexcept#
Returns:

the number of entries in the StaticMatrix Complexity: Constant

Iterators

constexpr iterator begin() noexcept#

Complexity: Constant

Returns:

an iterator to the beginning of the container

constexpr iterator end() noexcept#

Complexity: Constant

Returns:

an iterator to past-the-end element of the container

constexpr const_iterator cbegin() const noexcept#

Complexity: Constant

Returns:

a const_iterator to the beginning of the container

constexpr const_iterator cend() const noexcept#

Complexity: Constant

Returns:

a const_iterator to the past-the-end element of the container

Modifiers

constexpr void clear()#

Clear the content from the StaticMatrix. Complexity: Constant

constexpr void swap(StaticMatrix &other) noexcept#

Swaps the StaticMatrix content with the other StaticMatrix, including any memory allocation.

Parameters:

other[in] another matrix to exchange content with Complexity: Constant

Matrix Block

MatrixView1D<StaticMatrix<ElemType, NRows, NCols>, internal::kRowMajor> row(index_t r)#
Parameters:

r[in] the index of the desired row Complexity: Constant

Returns:

the row r of the matrix

MatrixView1D<const StaticMatrix<ElemType, NRows, NCols>, internal::kRowMajor> row(index_t r) const#
Parameters:

r[in] the index of the desired row Complexity: Constant

Returns:

the row r of the matrix

MatrixView1D<StaticMatrix<ElemType, NRows, NCols>, internal::kColMajor> col(index_t c)#
Parameters:

c[in] the index of the desired column Complexity: Constant

Returns:

the column c of the matrix

MatrixView1D<const StaticMatrix<ElemType, NRows, NCols>, internal::kColMajor> col(index_t c) const#
Parameters:

c[in] the index of the desired column Complexity: Constant

Returns:

the column c of the matrix

Friends

template<typename T, int N, int M>
friend constexpr std::ostream &operator<<(std::ostream &stream, const StaticMatrix<T, N, M> &mat)#

Stream Operator. Writes the content of the StaticMatrix on a given stream.

Complexity: Linear in this->size()

Parameters:
  • stream[in] output stream (e.g., std::cout)

  • expr[in] StaticMatrix

Returns:

stream