This template represents NxM matrix. It uses row major order of data.
You can find more information in comments below.
template<class TYPE, size_t ROWS, size_t COLUMNS>
union TMatrix
{
struct ROW // Represents row
{
TYPE Data[COLUMNS]; // Row elements
TYPE operator[](const size_t col) const; // Return element at specified column. Used when matrix is a constant object only
TYPE &operator[](const size_t col); // Return element at specified column
};
ROW Rows[ROWS]; // Array of rows
TYPE Data[ROWS][COLUMNS]; // Array of elements
ROW operator[](const size_t row) const; // Return row at specified position. Used when matrix is a constant object only
ROW &operator[](const size_t row); // Return row at specified position
};
Additionally following operators exists.
template<class TYPE, size_t ROWS, size_t COLUMNS>
bool operator==(const TMatrix<TYPE, ROWS, COLUMNS> &a, const TMatrix<TYPE, ROWS, COLUMNS> &b); // Check whether matrices are equal. Can be used for non-float data types only
template<class TYPE, size_t ROWS, size_t COLUMNS>
bool operator!=(const TMatrix<TYPE, ROWS, COLUMNS> &a, const TMatrix<TYPE, ROWS, COLUMNS> &b); // Check whether matrices aren't equal. Can be used for non-float data types only
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> operator+(const TMatrix<TYPE, ROWS, COLUMNS> &m, const TYPE val); // Add matrix and scalar
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> operator-(const TMatrix<TYPE, ROWS, COLUMNS> &m, const TYPE val); // Subtract matrix and scalar
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> operator*(const TMatrix<TYPE, ROWS, COLUMNS> &m, const TYPE val); // Multiply matrix and scalar
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> operator/(const TMatrix<TYPE, ROWS, COLUMNS> &m, const TYPE val); // Divide matrix and scalar
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> operator+(const TYPE val, const TMatrix<TYPE, ROWS, COLUMNS> &m); // Add scalar and matrix
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> operator-(const TYPE val, const TMatrix<TYPE, ROWS, COLUMNS> &m); // Subtract scalar and matrix
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> operator*(const TYPE val, const TMatrix<TYPE, ROWS, COLUMNS> &m); // Multiply scalar and matrix
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> operator/(const TYPE val, const TMatrix<TYPE, ROWS, COLUMNS> &m); // Divide scalar and matrix
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> &operator+=(TMatrix<TYPE, ROWS, COLUMNS> &m, const TYPE val); // Add scalar to matrix
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> &operator-=(TMatrix<TYPE, ROWS, COLUMNS> &m, const TYPE val); // Subtract scalar from matrix
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> &operator*=(TMatrix<TYPE, ROWS, COLUMNS> &m, const TYPE val); // Multiply matrix by scalar
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> &operator/=(TMatrix<TYPE, ROWS, COLUMNS> &m, const TYPE val); // Divide matrix by scalar
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> operator+(const TMatrix<TYPE, ROWS, COLUMNS> &a, const TMatrix<TYPE, ROWS, COLUMNS> &b); // Add matrices
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> operator-(const TMatrix<TYPE, ROWS, COLUMNS> &a, const TMatrix<TYPE, ROWS, COLUMNS> &b); // Subtract matrices
template<class TYPE, size_t ROWS_A, size_t COLUMNS_A, size_t COLUMNS_B>
TMatrix<TYPE, ROWS_A, COLUMNS_B> operator*(const TMatrix<TYPE, ROWS_A, COLUMNS_A> &a, const TMatrix<TYPE, COLUMNS_A, COLUMNS_B> &b); // Multiply matrices
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> &operator+=(TMatrix<TYPE, ROWS, COLUMNS> &a, const TMatrix<TYPE, ROWS, COLUMNS> &b); // Add matrix to matrix
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> &operator-=(TMatrix<TYPE, ROWS, COLUMNS> &a, const TMatrix<TYPE, ROWS, COLUMNS> &b); // Subtract matrix from matrix
template<class TYPE, size_t ROWS, size_t COLUMNS>
TMatrix<TYPE, ROWS, COLUMNS> &operator*=(TMatrix<TYPE, ROWS, COLUMNS> &a, const TMatrix<TYPE, ROWS, COLUMNS> &b); // Multiply matrix by matrix
Also there are some functions which can be used with TMatrix template. Here they are.
Namespace: | ntl |
Include: | NTL/Core/Matrix.h |