HLR  0.0.1
Public Member Functions | Static Public Member Functions | List of all members
HLR::Kinematics::Matrix< T, m, n > Class Template Reference

Create a matrix with numerical values. More...

#include <Matrix.hpp>

Inheritance diagram for HLR::Kinematics::Matrix< T, m, n >:
Collaboration diagram for HLR::Kinematics::Matrix< T, m, n >:

Public Member Functions

 Matrix ()=default
 Create matrix with all elements set to 0.
 
 ~Matrix ()=default
 Default destructor.
 
 Matrix (const Matrix< T, m, n > &mat)=default
 Default copy constructor. More...
 
 Matrix (Matrix< T, m, n > &&mat)=default
 Default move constructor. More...
 
Matrix< T, m, n > & operator= (const Matrix< T, m, n > &mat)=default
 Default assignment operator. More...
 
Matrix< T, m, n > & operator= (Matrix< T, m, n > &&mat)=default
 Default move assignment operator. More...
 
constexpr Matrix (std::initializer_list< std::initializer_list< T >> matrix_data)
 Create matrix. Throws invalid argument if passed data doesn't match with amount of rows or columns. More...
 
constexpr std::size_t get_m () const noexcept
 Get the amount of rows of the matrix. More...
 
constexpr std::size_t get_n () const noexcept
 Get the amount of cols of the matrix. More...
 
constexpr std::array< T, n > & operator[] (std::size_t pos) noexcept
 Get row of matrix at pos. No bounds checkin. More...
 
constexpr const std::array< T, n > & operator[] (std::size_t pos) const noexcept
 Get row of matrix at pos. No bounds checkin. More...
 
constexpr std::array< T, n > & at (std::size_t pos)
 Get row of matrix at pos. Throw out of range exception if out of range. More...
 
constexpr const std::array< T, n > & at (std::size_t pos) const
 Get row of matrix at pos. Throw out of range exception if out of range. More...
 
constexpr bool fuzzy_equal (const Matrix< T, m, n > &mat, T fuzz) const noexcept
 Fuzzy compare 2 matrices. More...
 
constexpr bool operator== (const Matrix< T, m, n > &mat) const noexcept
 Compare two matrices. More...
 
constexpr bool operator!= (const Matrix< T, m, n > &mat) const noexcept
 Compare two matrices. More...
 
constexpr void operator+= (T scalar) noexcept
 Add a scalar from every element of the matrix. More...
 
constexpr void operator-= (T scalar) noexcept
 Subtract a scalar from every element of the matrix. More...
 
constexpr void operator*= (T scalar) noexcept
 Multiply every element of the matrix with a scalar. More...
 
constexpr void operator/= (T scalar) noexcept
 Divide every element of the matrix with a scalar. More...
 
constexpr void operator+= (const Matrix< T, m, n > &mat) noexcept
 Add a matrix to another matrix. More...
 
constexpr void operator-= (const Matrix< T, m, n > &mat) noexcept
 Subtract a matrix to another matrix. More...
 
constexpr Matrix< T, m, n > operator+ (const Matrix< T, m, n > &mat) const noexcept
 Add a matrix to another matrix. Returns a new matrix. More...
 
constexpr Matrix< T, m, n > operator- (const Matrix< T, m, n > &mat) const noexcept
 Subtract a matrix from another matrix. Returns a new matrix. More...
 
template<std::size_t p>
constexpr Matrix< T, m, p > operator* (const Matrix< T, n, p > &mat) const noexcept
 Multiply a matrix with the current matrix. More...
 
template<std::size_t p>
constexpr Matrix< T, m, n+p > horizontal_augment (const Matrix< T, m, p > &mat) const noexcept
 Right augment the current matrix with the provided matrix. More...
 
template<std::size_t p>
constexpr Matrix< T, m+p, n > vertical_augment (const Matrix< T, p, n > &mat) const noexcept
 Bottom augment the current matrix with the provided matrix. More...
 
template<std::size_t y, std::size_t x, std::size_t p, std::size_t q>
constexpr Matrix< T, p, q > slice () const noexcept
 Create a new matrix from the current one where some columns and rows are sliced of. More...
 
constexpr Matrix< T, n, m > transpose () const noexcept
 Transpose the matrix. More...
 
constexpr std::optional< Matrix< T, m, n > > inverse () const noexcept
 Get the inverse of the matrix, implemented by using gauss-jordan. This operation is only available for square matrices/. More...
 
constexpr T get_magnitude () const noexcept
 Get the magnitude of the matrix. This is equivalent to the euclidean distance. More...
 
std::string str () const
 Get a string representation. More...
 

Static Public Member Functions

static constexpr Matrix< T, m, n > get_identity () noexcept
 Get identity matrix. More...
 

Detailed Description

template<typename T, std::size_t m, std::size_t n>
class HLR::Kinematics::Matrix< T, m, n >

Create a matrix with numerical values.

Template Parameters
TThe numerical type to elements have.
mAmount of rows
nAmount of columns

Constructor & Destructor Documentation

template<typename T, std::size_t m, std::size_t n>
HLR::Kinematics::Matrix< T, m, n >::Matrix ( const Matrix< T, m, n > &  mat)
default

Default copy constructor.

Parameters
matThe matrix to copy.
template<typename T, std::size_t m, std::size_t n>
HLR::Kinematics::Matrix< T, m, n >::Matrix ( Matrix< T, m, n > &&  mat)
default

Default move constructor.

Parameters
matThe matrix to move.
template<typename T, std::size_t m, std::size_t n>
constexpr HLR::Kinematics::Matrix< T, m, n >::Matrix ( std::initializer_list< std::initializer_list< T >>  matrix_data)

Create matrix. Throws invalid argument if passed data doesn't match with amount of rows or columns.

Parameters
matrix_datamatrix_data The data to initialize matrix with.

Member Function Documentation

template<typename T, std::size_t m, std::size_t n>
constexpr std::array<T, n>& HLR::Kinematics::Matrix< T, m, n >::at ( std::size_t  pos)

Get row of matrix at pos. Throw out of range exception if out of range.

Parameters
posThe row to fetch.
Returns
array containing the requested row.
template<typename T, std::size_t m, std::size_t n>
constexpr const std::array<T, n>& HLR::Kinematics::Matrix< T, m, n >::at ( std::size_t  pos) const

Get row of matrix at pos. Throw out of range exception if out of range.

Parameters
posThe row to fetch.
Returns
array containing the requested row.
template<typename T, std::size_t m, std::size_t n>
constexpr bool HLR::Kinematics::Matrix< T, m, n >::fuzzy_equal ( const Matrix< T, m, n > &  mat,
fuzz 
) const
noexcept

Fuzzy compare 2 matrices.

Parameters
matThe matrix to compare with,
fuzzThe maximum allowed difference between each value where they are still considered fuzzy equal.
Returns
true When fuzzy equal
false When not equal
template<typename T, std::size_t m, std::size_t n>
static constexpr Matrix<T, m, n> HLR::Kinematics::Matrix< T, m, n >::get_identity ( )
staticnoexcept

Get identity matrix.

Returns
Identity matrix.
template<typename T, std::size_t m, std::size_t n>
constexpr std::size_t HLR::Kinematics::Matrix< T, m, n >::get_m ( ) const
noexcept

Get the amount of rows of the matrix.

Returns
amount of rows.
template<typename T, std::size_t m, std::size_t n>
constexpr T HLR::Kinematics::Matrix< T, m, n >::get_magnitude ( ) const
noexcept

Get the magnitude of the matrix. This is equivalent to the euclidean distance.

Returns
The calculated magnitude.
template<typename T, std::size_t m, std::size_t n>
constexpr std::size_t HLR::Kinematics::Matrix< T, m, n >::get_n ( ) const
noexcept

Get the amount of cols of the matrix.

Returns
amount of cols.
template<typename T, std::size_t m, std::size_t n>
template<std::size_t p>
constexpr Matrix<T, m, n + p> HLR::Kinematics::Matrix< T, m, n >::horizontal_augment ( const Matrix< T, m, p > &  mat) const
noexcept

Right augment the current matrix with the provided matrix.

Template Parameters
pThe columns of the matrix to augment with.
Parameters
matThe matrix that the current one will be augmented with.
Returns
A new matrix that is the current one augmented with the provided one.
template<typename T, std::size_t m, std::size_t n>
constexpr std::optional<Matrix<T, m, n> > HLR::Kinematics::Matrix< T, m, n >::inverse ( ) const
noexcept

Get the inverse of the matrix, implemented by using gauss-jordan. This operation is only available for square matrices/.

Returns
The inversed matrix if it is available.
template<typename T, std::size_t m, std::size_t n>
constexpr bool HLR::Kinematics::Matrix< T, m, n >::operator!= ( const Matrix< T, m, n > &  mat) const
noexcept

Compare two matrices.

Parameters
matThe matrix to compare this one with.
Returns
true If equal.
false If not equal.
template<typename T, std::size_t m, std::size_t n>
template<std::size_t p>
constexpr Matrix<T, m, p> HLR::Kinematics::Matrix< T, m, n >::operator* ( const Matrix< T, n, p > &  mat) const
noexcept

Multiply a matrix with the current matrix.

Template Parameters
pThe columns of the matrix to multiply with.
Parameters
matThe matrix to multiply with.
Returns
A new matrix that is the result of multiplying the current matrix with the provided one.
template<typename T, std::size_t m, std::size_t n>
constexpr void HLR::Kinematics::Matrix< T, m, n >::operator*= ( scalar)
noexcept

Multiply every element of the matrix with a scalar.

Parameters
scalarscalar The scalar to multiply with.
template<typename T, std::size_t m, std::size_t n>
constexpr Matrix<T, m, n> HLR::Kinematics::Matrix< T, m, n >::operator+ ( const Matrix< T, m, n > &  mat) const
noexcept

Add a matrix to another matrix. Returns a new matrix.

Parameters
matThe matrix to add to the current one.
Returns
A new matrix containing the summed elements.
template<typename T, std::size_t m, std::size_t n>
constexpr void HLR::Kinematics::Matrix< T, m, n >::operator+= ( scalar)
noexcept

Add a scalar from every element of the matrix.

Parameters
scalarThe scalar to add.
template<typename T, std::size_t m, std::size_t n>
constexpr void HLR::Kinematics::Matrix< T, m, n >::operator+= ( const Matrix< T, m, n > &  mat)
noexcept

Add a matrix to another matrix.

Parameters
matThe matrix to add to the current one.
template<typename T, std::size_t m, std::size_t n>
constexpr Matrix<T, m, n> HLR::Kinematics::Matrix< T, m, n >::operator- ( const Matrix< T, m, n > &  mat) const
noexcept

Subtract a matrix from another matrix. Returns a new matrix.

Parameters
matThe matrix to subtract from the current one.
Returns
A new matrix containing the subtracted elements.
template<typename T, std::size_t m, std::size_t n>
constexpr void HLR::Kinematics::Matrix< T, m, n >::operator-= ( scalar)
noexcept

Subtract a scalar from every element of the matrix.

Parameters
scalarThe scalar to subtract.
template<typename T, std::size_t m, std::size_t n>
constexpr void HLR::Kinematics::Matrix< T, m, n >::operator-= ( const Matrix< T, m, n > &  mat)
noexcept

Subtract a matrix to another matrix.

Parameters
matthe matrix to subtract from the current one.
template<typename T, std::size_t m, std::size_t n>
constexpr void HLR::Kinematics::Matrix< T, m, n >::operator/= ( scalar)
noexcept

Divide every element of the matrix with a scalar.

Parameters
scalarThe scalar to divide with.
template<typename T, std::size_t m, std::size_t n>
Matrix<T, m, n>& HLR::Kinematics::Matrix< T, m, n >::operator= ( const Matrix< T, m, n > &  mat)
default

Default assignment operator.

Parameters
matThe matrix that is assigned.
Returns
Reference to a matrix equivalent to mat.
template<typename T, std::size_t m, std::size_t n>
Matrix<T, m, n>& HLR::Kinematics::Matrix< T, m, n >::operator= ( Matrix< T, m, n > &&  mat)
default

Default move assignment operator.

Parameters
matThe rvalue matrix that is assigned.
Returns
Reference to a matrix equivalent to mat.
template<typename T, std::size_t m, std::size_t n>
constexpr bool HLR::Kinematics::Matrix< T, m, n >::operator== ( const Matrix< T, m, n > &  mat) const
noexcept

Compare two matrices.

Parameters
matThe matrix to compare this one with.
Returns
true If equal.
false If not equal.
template<typename T, std::size_t m, std::size_t n>
constexpr std::array<T, n>& HLR::Kinematics::Matrix< T, m, n >::operator[] ( std::size_t  pos)
noexcept

Get row of matrix at pos. No bounds checkin.

Parameters
pospos The row to fetch.
Returns
array containing the requested row.
template<typename T, std::size_t m, std::size_t n>
constexpr const std::array<T, n>& HLR::Kinematics::Matrix< T, m, n >::operator[] ( std::size_t  pos) const
noexcept

Get row of matrix at pos. No bounds checkin.

Parameters
posThe row to fetch.
Returns
array containing the requested row.
template<typename T, std::size_t m, std::size_t n>
template<std::size_t y, std::size_t x, std::size_t p, std::size_t q>
constexpr Matrix<T, p, q> HLR::Kinematics::Matrix< T, m, n >::slice ( ) const
noexcept

Create a new matrix from the current one where some columns and rows are sliced of.

Template Parameters
yThe amount of rows to slice of from the top.
xThe amount of columns to slice of from the bottom.
pThe amount of rows to take. If larger then the original matrix the elements will be filled with 0.
qThe amount of columns to take. If larger then the original matrix the elements will be filled with 0.
Returns
A new matrix which is subset of the original.
template<typename T, std::size_t m, std::size_t n>
std::string HLR::Kinematics::Matrix< T, m, n >::str ( ) const

Get a string representation.

Returns
The string representation.
template<typename T, std::size_t m, std::size_t n>
constexpr Matrix<T, n, m> HLR::Kinematics::Matrix< T, m, n >::transpose ( ) const
noexcept

Transpose the matrix.

Returns
A new matrix that is is the transpose of the current one.
template<typename T, std::size_t m, std::size_t n>
template<std::size_t p>
constexpr Matrix<T, m + p, n> HLR::Kinematics::Matrix< T, m, n >::vertical_augment ( const Matrix< T, p, n > &  mat) const
noexcept

Bottom augment the current matrix with the provided matrix.

Template Parameters
pThe rows of the matrix to augment with.
Parameters
matThe matrix that the current one will be augmented with.
Returns
A new matrix that is the current one augmented with the provided one.

The documentation for this class was generated from the following file: