PIP 5.5.3
Platform-Independent Primitives
Public Member Functions | Static Public Member Functions | List of all members
PIMathMatrixT< Rows, Cols, Type > Class Template Reference

A class for fixed size and type matrix. More...

#include <pimathmatrix.h>

Public Member Functions

 PIMathMatrixT (const Type &new_value=Type())
 Constructs PIMathMatrixT that is filled by new_value.
 
 PIMathMatrixT (const PIVector< Type > &val)
 Contructs PIMathMatrixT from PIVector.
 
 PIMathMatrixT (std::initializer_list< Type > init_list)
 Contructs PIMathMatrixT from C++11 initializer list.
 
constexpr uint cols () const
 Method which returns number of columns in matrix. More...
 
constexpr uint rows () const
 Method which returns number of rows in matrix. More...
 
PIMathVectorT< Rows, Type > col (uint index)
 Method which returns the selected column in PIMathVectorT format. More...
 
PIMathVectorT< Cols, Type > row (uint index)
 Method which returns the selected row in PIMathVectorT format. More...
 
PIMathMatrixT< Rows, Cols, Type > & setCol (uint index, const PIMathVectorT< Rows, Type > &v)
 Set the selected column in matrix. More...
 
PIMathMatrixT< Rows, Cols, Type > & setRow (uint index, const PIMathVectorT< Cols, Type > &v)
 Set the selected row in matrix. More...
 
PIMathMatrixT< Rows, Cols, Type > & swapRows (uint rf, uint rs)
 Method which swaps the selected rows in a matrix. More...
 
PIMathMatrixT< Rows, Cols, Type > & swapCols (uint cf, uint cs)
 Method which swaps the selected columns in a matrix. More...
 
PIMathMatrixT< Rows, Cols, Type > & fill (const Type &v)
 Method which fills the matrix with selected value. More...
 
constexpr bool isSquare () const
 Method which checks if matrix is square. More...
 
bool isIdentity () const
 Method which checks if main diagonal of matrix consists of ones and another elements are zeros. More...
 
bool isNull () const
 Method which checks if every elements of matrix are zeros. More...
 
Type at (uint row, uint col) const
 Read-only access to element by row number and col number. More...
 
Type & element (uint row, uint col)
 Full access to element by row number and col number. More...
 
const Type & element (uint row, uint col) const
 Read-only access to element by row number and col number. More...
 
Type * operator[] (uint row)
 Full access to the matrix row pointer. More...
 
const Type * operator[] (uint row) const
 Read-only access to the matrix row pointer. More...
 
bool operator== (const PIMathMatrixT< Rows, Cols, Type > &sm) const
 Matrix compare. More...
 
bool operator!= (const PIMathMatrixT< Rows, Cols, Type > &sm) const
 Matrix negative compare. More...
 
void operator+= (const PIMathMatrixT< Rows, Cols, Type > &sm)
 Addition assignment with matrix sm. More...
 
void operator-= (const PIMathMatrixT< Rows, Cols, Type > &sm)
 Subtraction assignment with matrix sm. More...
 
void operator*= (const Type &v)
 Multiplication assignment with value v. More...
 
void operator/= (const Type &v)
 Division assignment with value v. More...
 
PIMathMatrixT< Rows, Cols, Type > operator- () const
 Negation operation. More...
 
PIMathMatrixT< Rows, Cols, Type > operator+ (const PIMathMatrixT< Rows, Cols, Type > &sm) const
 Matrix addition. More...
 
PIMathMatrixT< Rows, Cols, Type > operator- (const PIMathMatrixT< Rows, Cols, Type > &sm) const
 Matrix substraction. More...
 
PIMathMatrixT< Rows, Cols, Type > operator* (const Type &v) const
 Matrix multiplication by a constant. More...
 
PIMathMatrixT< Rows, Cols, Type > operator/ (const Type &v) const
 Division a matrix by a constant. More...
 
Type determinant (bool *ok=0) const
 Calculate Determinant of the matrix. More...
 
Type trace () const
 Calculate the trace of a matrix. More...
 
PIMathMatrixT< Rows, Cols, Type > & toUpperTriangular (bool *ok=0)
 Transforming matrix to upper triangular. More...
 
PIMathMatrixT< Rows, Cols, Type > & invert (bool *ok=0)
 Matrix inversion operation. More...
 
PIMathMatrixT< Rows, Cols, Type > inverted (bool *ok=0) const
 Matrix inversion operation. More...
 
PIMathMatrixT< Cols, Rows, Type > transposed () const
 Matrix transposition operation. More...
 
PIMathMatrixT< Rows, Cols, Type > & rotate (Type angle)
 Matrix rotation operation. More...
 
PIMathMatrixT< Rows, Cols, Type > rotated (Type angle)
 Matrix rotation operation. More...
 
template<typename T >
PIMathMatrixT< Rows, Cols, T > toType () const
 Returns this matrix with another element type.
 
template<uint SubRows, uint SubCols = SubRows>
PIMathMatrixT< SubRows, SubCols, Type > submatrix (int row_offset=0, int col_offset=0) const
 Returns the submatrix with size SubRows x SubCols. Elements takes from coordinates "row_offset" and "col_offset".
 
template<uint SubRows, uint SubCols = SubRows>
PIMathMatrixT< Rows, Cols, Type > & setSubmatrix (int row_index, int col_index, const PIMathMatrixT< SubRows, SubCols, Type > &m)
 Set the submatrix "m" in coordinates "row_index" and "col_index".
 

Static Public Member Functions

static PIMathMatrixT< Rows, Cols, Type > identity ()
 Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros. More...
 

Detailed Description

template<uint Rows, uint Cols = Rows, typename Type = double>
class PIMathMatrixT< Rows, Cols, Type >

A class for fixed size and type matrix.

Template Parameters
`Rows`rows number of matrix.
`Сols`columns number of matrix.
`Type`is the data type of the matrix. There are can be basic C++ language data and different classes where the arithmetic operators(=, +=, -=, *=, /=, ==, !=, +, -, *, /) of the C++ language are implemented

Member Function Documentation

◆ identity()

template<uint Rows, uint Cols = Rows, typename Type = double>
static PIMathMatrixT< Rows, Cols, Type > PIMathMatrixT< Rows, Cols, Type >::identity ( )
inlinestatic

Сreates a matrix whose main diagonal is filled with ones and the remaining elements are zeros.

Returns
identity matrix of type PIMathMatrixT.

◆ cols()

template<uint Rows, uint Cols = Rows, typename Type = double>
constexpr uint PIMathMatrixT< Rows, Cols, Type >::cols ( ) const
inlineconstexpr

Method which returns number of columns in matrix.

Returns
type uint shows number of columns.

◆ rows()

template<uint Rows, uint Cols = Rows, typename Type = double>
constexpr uint PIMathMatrixT< Rows, Cols, Type >::rows ( ) const
inlineconstexpr

Method which returns number of rows in matrix.

Returns
type uint shows number of rows.

◆ col()

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathVectorT< Rows, Type > PIMathMatrixT< Rows, Cols, Type >::col ( uint  index)
inline

Method which returns the selected column in PIMathVectorT format.

If you enter an index out of the border of the matrix there will be "undefined behavior".

Parameters
indexis the number of the selected column.
Returns
column in PIMathVectorT format.

◆ row()

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathVectorT< Cols, Type > PIMathMatrixT< Rows, Cols, Type >::row ( uint  index)
inline

Method which returns the selected row in PIMathVectorT format.

If you enter an index out of the border of the matrix there will be "undefined behavior".

Parameters
indexis the number of the selected row.
Returns
row in PIMathVectorT format.

◆ setCol()

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathMatrixT< Rows, Cols, Type > & PIMathMatrixT< Rows, Cols, Type >::setCol ( uint  index,
const PIMathVectorT< Rows, Type > &  v 
)
inline

Set the selected column in matrix.

If you enter an index out of the border of the matrix there will be "undefined behavior".

Parameters
indexis the number of the selected column.
vis a vector of the type PIMathVectorT<Rows, Type> that needs to fill the column.
Returns
matrix type PIMathMatrixT<Rows, Cols, Type>.

◆ setRow()

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathMatrixT< Rows, Cols, Type > & PIMathMatrixT< Rows, Cols, Type >::setRow ( uint  index,
const PIMathVectorT< Cols, Type > &  v 
)
inline

Set the selected row in matrix.

If you enter an index out of the border of the matrix there will be "undefined behavior".

Parameters
indexis the number of the selected row.
vis a vector of the type PIMathVectorT<Cols, Type> that needs to fill the row.
Returns
matrix type PIMathMatrixT<Rows, Cols, Type>

◆ swapRows()

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathMatrixT< Rows, Cols, Type > & PIMathMatrixT< Rows, Cols, Type >::swapRows ( uint  rf,
uint  rs 
)
inline

Method which swaps the selected rows in a matrix.

If you enter an index out of the border of the matrix there will be "undefined behavior"

Parameters
rfis the number of the first selected row
rsis the number of the second selected row
Returns
matrix type PIMathMatrixT<Rows, Cols, Type>

◆ swapCols()

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathMatrixT< Rows, Cols, Type > & PIMathMatrixT< Rows, Cols, Type >::swapCols ( uint  cf,
uint  cs 
)
inline

Method which swaps the selected columns in a matrix.

If you enter an index out of the border of the matrix there will be "undefined behavior"

Parameters
cfis the number of the first selected column
csis the number of the second selected column
Returns
matrix type PIMathMatrixT<Rows, Cols, Type>

◆ fill()

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathMatrixT< Rows, Cols, Type > & PIMathMatrixT< Rows, Cols, Type >::fill ( const Type &  v)
inline

Method which fills the matrix with selected value.

Parameters
vis a parameter the type and value of which is selected and later filled into the matrix.
Returns
filled matrix type PIMathMatrixT<Rows, Cols, Type>.

◆ isSquare()

template<uint Rows, uint Cols = Rows, typename Type = double>
constexpr bool PIMathMatrixT< Rows, Cols, Type >::isSquare ( ) const
inlineconstexpr

Method which checks if matrix is square.

Returns
true if matrix is square, else false.

◆ isIdentity()

template<uint Rows, uint Cols = Rows, typename Type = double>
bool PIMathMatrixT< Rows, Cols, Type >::isIdentity ( ) const
inline

Method which checks if main diagonal of matrix consists of ones and another elements are zeros.

Returns
true if matrix is identitied, else false.

◆ isNull()

template<uint Rows, uint Cols = Rows, typename Type = double>
bool PIMathMatrixT< Rows, Cols, Type >::isNull ( ) const
inline

Method which checks if every elements of matrix are zeros.

Returns
true if matrix is null, else false.

◆ at()

template<uint Rows, uint Cols = Rows, typename Type = double>
Type PIMathMatrixT< Rows, Cols, Type >::at ( uint  row,
uint  col 
) const
inline

Read-only access to element by row number and col number.

If you enter an index out of the border of the matrix there will be "undefined behavior".

Parameters
rowmatrix row number.
colmatrix column number.
Returns
copy of element of matrix.

◆ element() [1/2]

template<uint Rows, uint Cols = Rows, typename Type = double>
Type & PIMathMatrixT< Rows, Cols, Type >::element ( uint  row,
uint  col 
)
inline

Full access to element by row number and col number.

If you enter an index out of the border of the matrix there will be "undefined behavior"

Parameters
rowmatrix row number.
colmatrix column number.
Returns
element of matrix

◆ element() [2/2]

template<uint Rows, uint Cols = Rows, typename Type = double>
const Type & PIMathMatrixT< Rows, Cols, Type >::element ( uint  row,
uint  col 
) const
inline

Read-only access to element by row number and col number.

If you enter an index out of the border of the matrix there will be "undefined behavior".

Parameters
rowmatrix row number.
colmatrix column number.
Returns
copy of element of matrix.

◆ operator[]() [1/2]

template<uint Rows, uint Cols = Rows, typename Type = double>
Type * PIMathMatrixT< Rows, Cols, Type >::operator[] ( uint  row)
inline

Full access to the matrix row pointer.

If you enter an index out of the border of the matrix there will be "undefined behavior".

Parameters
rowmatrix row number.
Returns
matrix row pointer

◆ operator[]() [2/2]

template<uint Rows, uint Cols = Rows, typename Type = double>
const Type * PIMathMatrixT< Rows, Cols, Type >::operator[] ( uint  row) const
inline

Read-only access to the matrix row pointer.

If you enter an index out of the border of the matrix there will be "undefined behavior".

Parameters
rowmatrix row number.
Returns
matrix row pointer

◆ operator==()

template<uint Rows, uint Cols = Rows, typename Type = double>
bool PIMathMatrixT< Rows, Cols, Type >::operator== ( const PIMathMatrixT< Rows, Cols, Type > &  sm) const
inline

Matrix compare.

Parameters
smmatrix for compare.
Returns
if matrices are equal true, else false.

◆ operator!=()

template<uint Rows, uint Cols = Rows, typename Type = double>
bool PIMathMatrixT< Rows, Cols, Type >::operator!= ( const PIMathMatrixT< Rows, Cols, Type > &  sm) const
inline

Matrix negative compare.

Parameters
smmatrix for compare.
Returns
if matrices are not equal true, else false.

◆ operator+=()

template<uint Rows, uint Cols = Rows, typename Type = double>
void PIMathMatrixT< Rows, Cols, Type >::operator+= ( const PIMathMatrixT< Rows, Cols, Type > &  sm)
inline

Addition assignment with matrix sm.

Parameters
smmatrix for the addition assigment.

◆ operator-=()

template<uint Rows, uint Cols = Rows, typename Type = double>
void PIMathMatrixT< Rows, Cols, Type >::operator-= ( const PIMathMatrixT< Rows, Cols, Type > &  sm)
inline

Subtraction assignment with matrix sm.

Parameters
smmatrix for the subtraction assigment.

◆ operator*=()

template<uint Rows, uint Cols = Rows, typename Type = double>
void PIMathMatrixT< Rows, Cols, Type >::operator*= ( const Type &  v)
inline

Multiplication assignment with value v.

Parameters
vvalue for the multiplication assigment.

◆ operator/=()

template<uint Rows, uint Cols = Rows, typename Type = double>
void PIMathMatrixT< Rows, Cols, Type >::operator/= ( const Type &  v)
inline

Division assignment with value v.

Parameters
vvalue for the division assigment.

◆ operator-() [1/2]

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathMatrixT< Rows, Cols, Type > PIMathMatrixT< Rows, Cols, Type >::operator- ( ) const
inline

Negation operation.

Returns
copy of the negative matrix

◆ operator+()

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathMatrixT< Rows, Cols, Type > PIMathMatrixT< Rows, Cols, Type >::operator+ ( const PIMathMatrixT< Rows, Cols, Type > &  sm) const
inline

Matrix addition.

Parameters
smis matrix term.
Returns
the result of matrix addition.

◆ operator-() [2/2]

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathMatrixT< Rows, Cols, Type > PIMathMatrixT< Rows, Cols, Type >::operator- ( const PIMathMatrixT< Rows, Cols, Type > &  sm) const
inline

Matrix substraction.

Parameters
smis matrix subtrahend.
Returns
the result of matrix substraction.

◆ operator*()

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathMatrixT< Rows, Cols, Type > PIMathMatrixT< Rows, Cols, Type >::operator* ( const Type &  v) const
inline

Matrix multiplication by a constant.

Parameters
vis value factor.
Returns
the result of matrix multiplication.

◆ operator/()

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathMatrixT< Rows, Cols, Type > PIMathMatrixT< Rows, Cols, Type >::operator/ ( const Type &  v) const
inline

Division a matrix by a constant.

Parameters
vis value divider.
Returns
the result of matrix division.

◆ determinant()

template<uint Rows, uint Cols = Rows, typename Type = double>
Type PIMathMatrixT< Rows, Cols, Type >::determinant ( bool *  ok = 0) const
inline

Calculate Determinant of the matrix.

Works only with square matrix, nonzero matrices and invertible matrix.

Parameters
okis a parameter with which we can find out if the method worked correctly.
Returns
matrix determinant.

◆ trace()

template<uint Rows, uint Cols = Rows, typename Type = double>
Type PIMathMatrixT< Rows, Cols, Type >::trace ( ) const
inline

Calculate the trace of a matrix.

Works only with square matrix.

Returns
matrix trace.

◆ toUpperTriangular()

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathMatrixT< Rows, Cols, Type > & PIMathMatrixT< Rows, Cols, Type >::toUpperTriangular ( bool *  ok = 0)
inline

Transforming matrix to upper triangular.

Works only with square matrix, nonzero matrices and invertible matrix.

Parameters
okis a parameter with which we can find out if the method worked correctly.
Returns
a transformed upper triangular matrix.

◆ invert()

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathMatrixT< Rows, Cols, Type > & PIMathMatrixT< Rows, Cols, Type >::invert ( bool *  ok = 0)
inline

Matrix inversion operation.

Works only with square matrix, nonzero matrices and invertible matrix.

Parameters
okis a parameter with which we can find out if the method worked correctly.
Returns
inverted matrix.

◆ inverted()

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathMatrixT< Rows, Cols, Type > PIMathMatrixT< Rows, Cols, Type >::inverted ( bool *  ok = 0) const
inline

Matrix inversion operation.

Works only with square matrix, nonzero matrices and invertible matrix.

Parameters
okis a parameter with which we can find out if the method worked correctly.
Returns
copy of inverted matrix.

◆ transposed()

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathMatrixT< Cols, Rows, Type > PIMathMatrixT< Rows, Cols, Type >::transposed ( ) const
inline

Matrix transposition operation.

Works only with square matrix.

Returns
copy of transposed matrix

◆ rotate()

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathMatrixT< Rows, Cols, Type > & PIMathMatrixT< Rows, Cols, Type >::rotate ( Type  angle)
inline

Matrix rotation operation.

Works only with 2x2 matrix.

Returns
rotated matrix.

◆ rotated()

template<uint Rows, uint Cols = Rows, typename Type = double>
PIMathMatrixT< Rows, Cols, Type > PIMathMatrixT< Rows, Cols, Type >::rotated ( Type  angle)
inline

Matrix rotation operation.

Works only with 2x2 matrix.

Returns
copy of rotated matrix.