template<std::size_t cols, std::size_t rows, class T>
Magnum::Math::RectangularMatrix class

Rectangular matrix.

Template parameters
cols Column count
rows Row count
T Underlying data type

See Operations with matrices and vectors for brief introduction. See also Matrix (square) and Vector.

The data are stored in column-major order, to reflect that, all indices in math formulas are in reverse order (i.e. $ \boldsymbol A_{ji} $ instead of $ \boldsymbol A_{ij} $ ).

Public types

enum (anonymous): std::size_t { Cols = cols, Rows = rows, DiagonalSize = (cols < rows ? cols : rows) }
using Type = T
Underlying data type.

Public static functions

static auto from(T* data) -> RectangularMatrix<cols, rows, T>&
Matrix from array.
static auto from(const T* data) -> const RectangularMatrix<cols, rows, T>&
static auto fromVector(const Vector<cols*rows, T>& vector) -> RectangularMatrix<cols, rows, T>
Construct matrix from vector.
static auto fromDiagonal(const Vector<DiagonalSize, T>& diagonal) -> RectangularMatrix<cols, rows, T> constexpr noexcept
Construct diagonal matrix.

Constructors, destructors, conversion operators

RectangularMatrix(ZeroInitT = ZeroInit) constexpr noexcept
Construct zero-filled matrix.
RectangularMatrix(NoInitT) explicit noexcept
Construct matrix without initializing the contents.
template<class ... U>
RectangularMatrix(const Vector<rows, T>& first, const U&... next) constexpr noexcept
Construct matrix from column vectors.
RectangularMatrix(T value) explicit constexpr noexcept
Construct matrix with one value for all components.
template<class U>
RectangularMatrix(const RectangularMatrix<cols, rows, U>& other) explicit constexpr noexcept
Construct matrix from another of different type.
template<class U, class V = decltype(Implementation::RectangularMatrixConverter<cols, rows, T, U>::from(std::declval<U>()))>
RectangularMatrix(const U& other) explicit constexpr
Construct matrix from external representation.
RectangularMatrix(const RectangularMatrix<cols, rows, T>&) noexcept defaulted constexpr
Copy constructor.
template<class U, class V = decltype(Implementation::RectangularMatrixConverter<cols, rows, T, U>::to(std::declval<RectangularMatrix<cols, rows, T>>()))>
operator U() const explicit constexpr
Convert matrix to external representation.

Public functions

auto data() -> T*
Raw data.
auto data() const -> const T* constexpr
auto operator[](std::size_t col) -> Vector<rows, T>&
Matrix column.
auto operator[](std::size_t col) const -> const Vector<rows, T>& constexpr
auto row(std::size_t row) const -> Vector<cols, T>
Matrix row.
void setRow(std::size_t row, const Vector<cols, T>& data)
Set matrix row.
auto operator==(const RectangularMatrix<cols, rows, T>& other) const -> bool
Equality comparison.
auto operator!=(const RectangularMatrix<cols, rows, T>& other) const -> bool
Non-equality operator.
auto operator<(const RectangularMatrix<cols, rows, T>& other) const -> BoolVector<cols*rows>
Component-wise less than.
auto operator<=(const RectangularMatrix<cols, rows, T>& other) const -> BoolVector<cols*rows>
Component-wise less than or equal.
auto operator>=(const RectangularMatrix<cols, rows, T>& other) const -> BoolVector<cols*rows>
Component-wise greater than or equal.
auto operator>(const RectangularMatrix<cols, rows, T>& other) const -> BoolVector<cols*rows>
Component-wise greater than.
auto operator-() const -> RectangularMatrix<cols, rows, T>
Negated matrix.
auto operator+=(const RectangularMatrix<cols, rows, T>& other) -> RectangularMatrix<cols, rows, T>&
Add and assign matrix.
auto operator+(const RectangularMatrix<cols, rows, T>& other) const -> RectangularMatrix<cols, rows, T>
Add matrix.
auto operator-=(const RectangularMatrix<cols, rows, T>& other) -> RectangularMatrix<cols, rows, T>&
Subtract and assign matrix.
auto operator-(const RectangularMatrix<cols, rows, T>& other) const -> RectangularMatrix<cols, rows, T>
Subtract matrix.
auto operator*=(T number) -> RectangularMatrix<cols, rows, T>&
Multiply matrix with number and assign.
auto operator*(T number) const -> RectangularMatrix<cols, rows, T>
Multiply matrix with number.
auto operator/=(T number) -> RectangularMatrix<cols, rows, T>&
Divide matrix with number and assign.
auto operator/(T number) const -> RectangularMatrix<cols, rows, T>
Divide matrix with number.
template<std::size_t size>
auto operator*(const RectangularMatrix<size, cols, T>& other) const -> RectangularMatrix<size, rows, T>
Multiply matrix.
auto operator*(const Vector<cols, T>& other) const -> Vector<rows, T>
Multiply vector.
auto transposed() const -> RectangularMatrix<rows, cols, T>
Transposed matrix.
auto flippedCols() const -> RectangularMatrix<cols, rows, T> constexpr
Matrix with flipped cols.
auto flippedRows() const -> RectangularMatrix<cols, rows, T> constexpr
Matrix with flipped rows.
auto diagonal() const -> Vector<DiagonalSize, T> constexpr
Values on diagonal.
auto toVector() const -> Vector<rows*cols, T>
Convert matrix to vector.

Enum documentation

template<std::size_t cols, std::size_t rows, class T>
enum Magnum::Math::RectangularMatrix<cols, rows, T>::(anonymous): std::size_t

Enumerators
Cols

Matrix column count

Rows

Matrix row count

DiagonalSize

Size of matrix diagonal

Function documentation

template<std::size_t cols, std::size_t rows, class T>
static RectangularMatrix<cols, rows, T>& Magnum::Math::RectangularMatrix<cols, rows, T>::from(T* data)

Matrix from array.

Returns Reference to the data as if it was matrix, thus doesn't perform any copying.

template<std::size_t cols, std::size_t rows, class T>
static const RectangularMatrix<cols, rows, T>& Magnum::Math::RectangularMatrix<cols, rows, T>::from(const T* data)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<std::size_t cols, std::size_t rows, class T>
static RectangularMatrix<cols, rows, T> Magnum::Math::RectangularMatrix<cols, rows, T>::fromVector(const Vector<cols*rows, T>& vector)

Construct matrix from vector.

Rolls the vector into matrix, i.e. first rows elements of the vector will make first column of resulting matrix.

template<std::size_t cols, std::size_t rows, class T>
static RectangularMatrix<cols, rows, T> Magnum::Math::RectangularMatrix<cols, rows, T>::fromDiagonal(const Vector<DiagonalSize, T>& diagonal) constexpr noexcept

Construct diagonal matrix.

template<std::size_t cols, std::size_t rows, class T> template<class U>
Magnum::Math::RectangularMatrix<cols, rows, T>::RectangularMatrix(const RectangularMatrix<cols, rows, U>& other) explicit constexpr noexcept

Construct matrix from another of different type.

Performs only default casting on the values, no rounding or anything else. Example usage:

RectangularMatrix<4, 1, Float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f);
RectangularMatrix<4, 1, Byte> integral(floatingPoint);
// integral == {1, 2, -15, 7}

template<std::size_t cols, std::size_t rows, class T>
T* Magnum::Math::RectangularMatrix<cols, rows, T>::data()

Raw data.

Returns One-dimensional array of cols*rows length in column-major order.

template<std::size_t cols, std::size_t rows, class T>
const T* Magnum::Math::RectangularMatrix<cols, rows, T>::data() const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<std::size_t cols, std::size_t rows, class T>
Vector<rows, T>& Magnum::Math::RectangularMatrix<cols, rows, T>::operator[](std::size_t col)

Matrix column.

Particular elements can be accessed using Vector::operator[](), e.g.:

RectangularMatrix<4, 3, Float> m;
Float a = m[2][1];

template<std::size_t cols, std::size_t rows, class T>
const Vector<rows, T>& Magnum::Math::RectangularMatrix<cols, rows, T>::operator[](std::size_t col) const constexpr

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<std::size_t cols, std::size_t rows, class T>
Vector<cols, T> Magnum::Math::RectangularMatrix<cols, rows, T>::row(std::size_t row) const

Matrix row.

Consider using transposed() when accessing rows frequently, as this is slower than accessing columns due to the way the matrix is stored.

template<std::size_t cols, std::size_t rows, class T>
void Magnum::Math::RectangularMatrix<cols, rows, T>::setRow(std::size_t row, const Vector<cols, T>& data)

Set matrix row.

Consider using transposed() when accessing rows frequently, as this is slower than accessing columns due to the way the matrix is stored.

template<std::size_t cols, std::size_t rows, class T>
bool Magnum::Math::RectangularMatrix<cols, rows, T>::operator!=(const RectangularMatrix<cols, rows, T>& other) const

Non-equality operator.

template<std::size_t cols, std::size_t rows, class T>
BoolVector<cols*rows> Magnum::Math::RectangularMatrix<cols, rows, T>::operator<(const RectangularMatrix<cols, rows, T>& other) const

Component-wise less than.

Calls Vector::operator<() on toVector().

template<std::size_t cols, std::size_t rows, class T>
BoolVector<cols*rows> Magnum::Math::RectangularMatrix<cols, rows, T>::operator<=(const RectangularMatrix<cols, rows, T>& other) const

Component-wise less than or equal.

Calls Vector::operator<=() on toVector().

template<std::size_t cols, std::size_t rows, class T>
BoolVector<cols*rows> Magnum::Math::RectangularMatrix<cols, rows, T>::operator>=(const RectangularMatrix<cols, rows, T>& other) const

Component-wise greater than or equal.

Calls Vector::operator>=() on toVector().

template<std::size_t cols, std::size_t rows, class T>
BoolVector<cols*rows> Magnum::Math::RectangularMatrix<cols, rows, T>::operator>(const RectangularMatrix<cols, rows, T>& other) const

Component-wise greater than.

Calls Vector::operator>() on toVector().

template<std::size_t cols, std::size_t rows, class T>
RectangularMatrix<cols, rows, T> Magnum::Math::RectangularMatrix<cols, rows, T>::operator-() const

Negated matrix.

The computation is done column-wise.

\[ \boldsymbol B_j = -\boldsymbol A_j \]

template<std::size_t cols, std::size_t rows, class T>
RectangularMatrix<cols, rows, T>& Magnum::Math::RectangularMatrix<cols, rows, T>::operator+=(const RectangularMatrix<cols, rows, T>& other)

Add and assign matrix.

The computation is done column-wise in-place.

\[ \boldsymbol A_j = \boldsymbol A_j + \boldsymbol B_j \]

template<std::size_t cols, std::size_t rows, class T>
RectangularMatrix<cols, rows, T> Magnum::Math::RectangularMatrix<cols, rows, T>::operator+(const RectangularMatrix<cols, rows, T>& other) const

Add matrix.

template<std::size_t cols, std::size_t rows, class T>
RectangularMatrix<cols, rows, T>& Magnum::Math::RectangularMatrix<cols, rows, T>::operator-=(const RectangularMatrix<cols, rows, T>& other)

Subtract and assign matrix.

The computation is done column-wise in-place.

\[ \boldsymbol A_j = \boldsymbol A_j - \boldsymbol B_j \]

template<std::size_t cols, std::size_t rows, class T>
RectangularMatrix<cols, rows, T> Magnum::Math::RectangularMatrix<cols, rows, T>::operator-(const RectangularMatrix<cols, rows, T>& other) const

Subtract matrix.

template<std::size_t cols, std::size_t rows, class T>
RectangularMatrix<cols, rows, T>& Magnum::Math::RectangularMatrix<cols, rows, T>::operator*=(T number)

Multiply matrix with number and assign.

The computation is done column-wise in-place.

\[ \boldsymbol A_j = a \boldsymbol A_j \]

template<std::size_t cols, std::size_t rows, class T>
RectangularMatrix<cols, rows, T> Magnum::Math::RectangularMatrix<cols, rows, T>::operator*(T number) const

Multiply matrix with number.

template<std::size_t cols, std::size_t rows, class T>
RectangularMatrix<cols, rows, T>& Magnum::Math::RectangularMatrix<cols, rows, T>::operator/=(T number)

Divide matrix with number and assign.

The computation is done column-wise in-place.

\[ \boldsymbol A_j = \frac{\boldsymbol A_j} a \]

template<std::size_t cols, std::size_t rows, class T>
RectangularMatrix<cols, rows, T> Magnum::Math::RectangularMatrix<cols, rows, T>::operator/(T number) const

Divide matrix with number.

template<std::size_t cols, std::size_t rows, class T> template<std::size_t size>
RectangularMatrix<size, rows, T> Magnum::Math::RectangularMatrix<cols, rows, T>::operator*(const RectangularMatrix<size, cols, T>& other) const

Multiply matrix.

\[ (\boldsymbol {AB})_{ji} = \sum_{k=0}^{m-1} \boldsymbol A_{ki} \boldsymbol B_{jk} \]

template<std::size_t cols, std::size_t rows, class T>
Vector<rows, T> Magnum::Math::RectangularMatrix<cols, rows, T>::operator*(const Vector<cols, T>& other) const

Multiply vector.

Internally the same as multiplying with one-column matrix, but returns vector.

\[ (\boldsymbol {Aa})_i = \sum_{k=0}^{m-1} \boldsymbol A_{ki} \boldsymbol a_k \]

template<std::size_t cols, std::size_t rows, class T>
RectangularMatrix<rows, cols, T> Magnum::Math::RectangularMatrix<cols, rows, T>::transposed() const

Transposed matrix.

\[ \boldsymbol{A}^T_ij = \boldsymbol{A}_ji \]

template<std::size_t cols, std::size_t rows, class T>
RectangularMatrix<cols, rows, T> Magnum::Math::RectangularMatrix<cols, rows, T>::flippedCols() const constexpr

Matrix with flipped cols.

The order of columns is reversed.

template<std::size_t cols, std::size_t rows, class T>
RectangularMatrix<cols, rows, T> Magnum::Math::RectangularMatrix<cols, rows, T>::flippedRows() const constexpr

Matrix with flipped rows.

The order of rows is reversed.

template<std::size_t cols, std::size_t rows, class T>
Vector<DiagonalSize, T> Magnum::Math::RectangularMatrix<cols, rows, T>::diagonal() const constexpr

Values on diagonal.

template<std::size_t cols, std::size_t rows, class T>
Vector<rows*cols, T> Magnum::Math::RectangularMatrix<cols, rows, T>::toVector() const

Convert matrix to vector.

Returns the matrix unrolled into one large vector, i.e. first column of the matrix will make first rows elements of resulting vector. Useful for performing vector operations with the matrix (e.g. summing the elements etc.).

template<std::size_t cols, std::size_t rows, class T> template<std::size_t cols, std::size_t rows, class T>
RectangularMatrix<cols, rows, T> operator*(T number, const RectangularMatrix<cols, rows, T>& matrix)

Multiply number with matrix.

Same as RectangularMatrix::operator*(T) const.

template<std::size_t cols, std::size_t rows, class T> template<std::size_t cols, std::size_t rows, class T>
RectangularMatrix<cols, rows, T> operator/(T number, const RectangularMatrix<cols, rows, T>& matrix)

Divide matrix with number and invert.

The computation is done column-wise.

\[ \boldsymbol B_j = \frac a {\boldsymbol A_j} \]

template<std::size_t cols, std::size_t rows, class T> template<std::size_t size, std::size_t cols, class T>
RectangularMatrix<cols, size, T> operator*(const Vector<size, T>& vector, const RectangularMatrix<cols, 1, T>& matrix)

Multiply vector with rectangular matrix.

Internally the same as multiplying one-column matrix with one-row matrix.

\[ (\boldsymbol {aA})_{ji} = \boldsymbol a_i \boldsymbol A_j \]

template<std::size_t cols, std::size_t rows, class T> template<std::size_t cols, std::size_t rows, class T>
Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug& debug, const Magnum::Math::RectangularMatrix<cols, rows, T>& value)

Debug output operator.