Class template for fixed-size matrices.
More...
#include <Matrix.h>
|
| Matrix () |
| The default constructor. More...
|
|
| Matrix (int m, int n) |
| For fixed-size matrices, the arguments m and n are ignored, and instead the dimensions of the matrix are determined from the template parameters rowsAtCompileTime and colsAtCompileTime . More...
|
|
| Matrix (const Matrix &m) |
| Copy constructor. Creates a deep copy of the Matrix object passed. More...
|
|
| Matrix (std::initializer_list< std::initializer_list< scalarType >>) |
| Allocates and initializes a matrix using the curly brace initializer list. More...
|
|
int | rows () const |
| Getter method for the number of rows of the matrix. More...
|
|
int | cols () const |
| Getter method for the number of columns of the matrix. More...
|
|
int | size () const |
| Getter method for the size (the total number of elements) of the matrix. More...
|
|
scalarType | operator() (const int i, const int j) const |
| Coefficient accessor. This routine overloads the parentheses operator () . A(i,j) is used the retrieve the element \(a_{ij}\) belonging to the matrix \(A\). This is const-version of the method, that works on const Matrix objects. More...
|
|
scalarType & | operator() (const int i, const int j) |
| Coefficient accessor. This routine retrieves the element in the (i,j) place of the matrix. This works on non-const Matrix objects. More...
|
|
Matrix | operator+ (const Matrix &m) const |
| Matrix addition. This routine overloads the binary addition operator + and is used to add two matrices. More...
|
|
Matrix | operator- (const Matrix &m) const |
| Matrix subtraction. This routine overloads the binary subtraction operator - and is used to subtract two matrices. More...
|
|
Matrix & | operator<< (const scalarType x) |
| Overload the << operator to initialize a matrix. More...
|
|
Matrix & | operator, (const scalarType x) |
| Overload the , operator to initialize a matrix. More...
|
|
Matrix & | operator= (const Matrix &right_hand_side) |
| Copy assignment operator. More...
|
|
bool | operator== (const Matrix &right_hand_side) |
| Boolean comparision operator. Compares if \(A = B\). More...
|
|
Matrix & | operator+= (const Matrix &m) |
|
Matrix & | operator-= (const Matrix &m) |
|
|
std::array< scalarType, rowsAtCompileTime *colsAtCompileTime > | A |
|
int | _rows |
|
int | _cols |
|
int | _size |
|
std::array< scalarType, rowsAtCompileTime *colsAtCompileTime >::iterator | currentPosition |
|
template<typename scalarType, int rowsAtCompileTime, int colsAtCompileTime>
class Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >
Class template for fixed-size matrices.
- Template Parameters
-
scalarType | Scalar type of the elements in the matrix |
rowsAtCompileTime | Number of rows |
colsAtCompileTime | Number of columns |
◆ Matrix() [1/4]
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::Matrix |
|
inline |
The default constructor.
- Template Parameters
-
109 :
_rows{ rowsAtCompileTime },
_cols{ colsAtCompileTime },
_size{ rowsAtCompileTime * colsAtCompileTime }
◆ Matrix() [2/4]
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::Matrix |
( |
int |
m, |
|
|
int |
n |
|
) |
| |
|
inline |
For fixed-size matrices, the arguments m
and n
are ignored, and instead the dimensions of the matrix are determined from the template parameters rowsAtCompileTime
and colsAtCompileTime
.
- Template Parameters
-
- Parameters
-
◆ Matrix() [3/4]
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::Matrix |
( |
const Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime > & |
m | ) |
|
|
inline |
Copy constructor. Creates a deep copy of the Matrix object passed.
- Template Parameters
-
- Parameters
-
◆ Matrix() [4/4]
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::Matrix |
( |
std::initializer_list< std::initializer_list< scalarType >> |
list | ) |
|
Allocates and initializes a matrix using the curly brace initializer list.
- Template Parameters
-
- Parameters
-
148 typename std::array<scalarType, rowsAtCompileTime* colsAtCompileTime>::iterator A_it{
A.begin() };
149 typename std::initializer_list<std::initializer_list<scalarType>>::iterator i{};
151 for (i = list.begin(); i < list.end(); ++i)
153 typename std::initializer_list<scalarType>::iterator j{};
154 for (j = (*i).begin(); j < (*i).end(); ++j)
◆ cols()
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
int Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::cols |
|
inline |
Getter method for the number of columns of the matrix.
- Template Parameters
-
- Returns
◆ operator()() [1/2]
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
scalarType & Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::operator() |
( |
const int |
i, |
|
|
const int |
j |
|
) |
| |
|
inline |
Coefficient accessor. This routine retrieves the element in the (i,j) place of the matrix. This works on non-const Matrix objects.
- Template Parameters
-
- Parameters
-
- Returns
228 typename std::array<scalarType, rowsAtCompileTime* colsAtCompileTime>::iterator it{
A.begin() };
229 it = it + (i *
_cols) + j;
233 throw std::out_of_range(
"\nError accessing an element beyond matrix bounds");
◆ operator()() [2/2]
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
scalarType Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::operator() |
( |
const int |
i, |
|
|
const int |
j |
|
) |
| const |
|
inline |
Coefficient accessor. This routine overloads the parentheses operator ()
. A(i,j)
is used the retrieve the element \(a_{ij}\) belonging to the matrix \(A\). This is const-version of the method, that works on const Matrix objects.
- Template Parameters
-
- Parameters
-
- Returns
208 typename std::array<scalarType, rowsAtCompileTime* colsAtCompileTime>::const_iterator it{
A.begin() };
209 it = it + (i *
_cols) + j;
213 throw std::out_of_range(
"\nError accessing an element beyond matrix bounds");
◆ operator+()
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
Matrix< typename scalarType, rowsAtCompileTime, colsAtCompileTime > Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::operator+ |
( |
const Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime > & |
m | ) |
const |
|
inline |
Matrix addition. This routine overloads the binary addition operator +
and is used to add two matrices.
- Template Parameters
-
- Parameters
-
- Returns
248 if (this->
rows() == m.
rows() && this->cols() == m.
cols())
250 for (
int i{}; i <
A.size(); ++i)
251 result.
A[i] =
A[i] + m.
A[i];
256 throw std::logic_error(
"Matrices have different dimensions; therefore cannot be added!");
◆ operator+=()
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
Matrix& Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::operator+= |
( |
const Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime > & |
m | ) |
|
◆ operator,()
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
Matrix< typename scalarType, rowsAtCompileTime, colsAtCompileTime > & Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::operator, |
( |
const scalarType |
x | ) |
|
|
inline |
Overload the ,
operator to initialize a matrix.
- Template Parameters
-
- Parameters
-
- Returns
321 throw std::logic_error(
"Error: Attempting to set values beyond matrix bounds!");
◆ operator-()
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
Matrix< typename scalarType, rowsAtCompileTime, colsAtCompileTime > Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::operator- |
( |
const Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime > & |
m | ) |
const |
|
inline |
Matrix subtraction. This routine overloads the binary subtraction operator -
and is used to subtract two matrices.
- Template Parameters
-
- Parameters
-
- Returns
272 if (this->
rows() == m.
rows() && this->cols() == m.
cols())
274 for (
int i{}; i <
A.size(); ++i)
275 result.
A[i] =
A[i] - m.
A[i];
280 throw std::logic_error(
"Matrices have different dimensions; therefore cannot be added!");
◆ operator-=()
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
Matrix& Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::operator-= |
( |
const Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime > & |
m | ) |
|
◆ operator<<()
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
Matrix< typename scalarType, rowsAtCompileTime, colsAtCompileTime > & Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::operator<< |
( |
const scalarType |
x | ) |
|
|
inline |
Overload the <<
operator to initialize a matrix.
- Template Parameters
-
- Parameters
-
- Returns
300 throw std::logic_error(
"Error: Attempting to set values beyond matrix bounds!");
◆ operator=()
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
Matrix< typename scalarType, rowsAtCompileTime, colsAtCompileTime > & Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::operator= |
( |
const Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime > & |
right_hand_side | ) |
|
|
inline |
Copy assignment operator.
- Template Parameters
-
- Parameters
-
- Returns
335 if (this->
rows() != right_hand_side.
rows() || this->cols() != right_hand_side.
cols())
336 throw std::logic_error(
"Assignment failed, matrices have different dimensions");
338 if (
this == &right_hand_side)
341 this->
A = right_hand_side.
A;
◆ operator==()
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
bool Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::operator== |
( |
const Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime > & |
right_hand_side | ) |
|
|
inline |
Boolean comparision operator. Compares if \(A = B\).
- Template Parameters
-
- Parameters
-
- Returns
437 return (this->
A == right_hand_side.
A);
◆ rows()
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
int Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::rows |
|
inline |
Getter method for the number of rows of the matrix.
- Template Parameters
-
- Returns
◆ size()
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
int Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::size |
|
inline |
Getter method for the size (the total number of elements) of the matrix.
- Template Parameters
-
- Returns
◆ _cols
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
int Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::_cols |
|
private |
◆ _rows
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
int Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::_rows |
|
private |
◆ _size
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
int Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::_size |
|
private |
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
std::array<scalarType, rowsAtCompileTime* colsAtCompileTime> Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::A |
|
private |
◆ currentPosition
template<typename scalarType , int rowsAtCompileTime, int colsAtCompileTime>
std::array<scalarType, rowsAtCompileTime* colsAtCompileTime>::iterator Matrix< scalarType, rowsAtCompileTime, colsAtCompileTime >::currentPosition |
|
private |
The documentation for this class was generated from the following file: