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

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

#include <pimathmatrix.h>

Inheritance diagram for PIMathMatrix< Type >:
Inheritance graph
[legend]

Public Member Functions

 PIMathMatrix (const uint cols=0, const uint rows=0, const Type &f=Type())
 Constructor of class PIMathMatrix, which creates a matrix. More...
 
 PIMathMatrix (const uint cols, const uint rows, const PIVector< Type > &val)
 Constructor of class PIMathMatrix, which creates a matrix. More...
 
 PIMathMatrix (const PIVector< PIVector< Type > > &val)
 Constructor of class PIMathMatrix, which creates a matrix. More...
 
 PIMathMatrix (const PIVector2D< Type > &val)
 Constructor of class PIMathMatrix, which creates a matrix. More...
 
PIMathMatrix< Type > & setCol (uint index, const PIMathVector< Type > &v)
 Set the selected column in matrix. More...
 
PIMathMatrix< Type > & setRow (uint index, const PIMathVector< Type > &v)
 Set the selected row in matrix. More...
 
PIMathMatrix< Type > & swapCols (uint r0, uint r1)
 Method which swaps selected columns in a matrix. More...
 
PIMathMatrix< Type > & swapRows (uint c0, uint c1)
 Method which replace selected rows in a matrix. More...
 
PIMathMatrix< Type > & fill (const Type &v)
 Method which fills the matrix with selected value. More...
 
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...
 
bool isValid () const
 Method which checks if matrix is empty. More...
 
void operator+= (const PIMathMatrix< Type > &sm)
 Addition assignment with matrix sm. More...
 
void operator-= (const PIMathMatrix< 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...
 
PIMathMatrix< Type > operator- () const
 Negation operation. More...
 
PIMathMatrix< Type > operator+ (const PIMathMatrix< Type > &sm) const
 Matrix addition. More...
 
PIMathMatrix< Type > operator- (const PIMathMatrix< Type > &sm) const
 Matrix substraction. More...
 
PIMathMatrix< Type > operator* (const Type &v) const
 Matrix multiplication. More...
 
PIMathMatrix< Type > operator/ (const Type &v) const
 Matrix division. More...
 
Type determinant (bool *ok=0) const
 â€‹Calculate Determinant of the matrix. More...
 
Type trace () const
 Calculate the trace of a matrix. More...
 
PIMathMatrix< Type > & toUpperTriangular (bool *ok=0)
 Transforming matrix to upper triangular. More...
 
PIMathMatrix< Type > & invert (bool *ok=0, PIMathVector< Type > *sv=0)
 Matrix inversion operation. More...
 
PIMathMatrix< Type > inverted (bool *ok=0) const
 Matrix inversion operation. More...
 
PIMathMatrix< Type > transposed () const
 Matrix transposition operation. More...
 

Static Public Member Functions

static PIMathMatrix< Type > identity (const uint cols, const uint rows)
 Creates a matrix whose main diagonal is filled with ones and the remaining elements are zeros. More...
 
static PIMathMatrix< Type > matrixRow (const PIMathVector< Type > &val)
 Creates a row matrix of every element that is equal to every element of the vector. More...
 
static PIMathMatrix< Type > matrixCol (const PIMathVector< Type > &val)
 Creates a column matrix of every element that is equal to every element of the vector. More...
 

Detailed Description

template<typename Type>
class PIMathMatrix< Type >

A class for dynamic size and fixed type matrix.

Template Parameters
`Type`There are can be basic C++ language data and different classes where the arithmetic operators(=, +=, -=, *=, /=, ==, !=, +, -, *, /) of the C++ language are implemented.

Constructor & Destructor Documentation

◆ PIMathMatrix() [1/4]

template<typename Type >
PIMathMatrix< Type >::PIMathMatrix ( const uint  cols = 0,
const uint  rows = 0,
const Type &  f = Type() 
)
inline

Constructor of class PIMathMatrix, which creates a matrix.

Parameters
colsis number of matrix column uint type.
rowsis number of matrix row uint type.
fis type of matrix elements.

◆ PIMathMatrix() [2/4]

template<typename Type >
PIMathMatrix< Type >::PIMathMatrix ( const uint  cols,
const uint  rows,
const PIVector< Type > &  val 
)
inline

Constructor of class PIMathMatrix, which creates a matrix.

Parameters
colsis number of matrix column uint type
rowsis number of matrix row uint type
valis PIVector<Type> of matrix elements

◆ PIMathMatrix() [3/4]

template<typename Type >
PIMathMatrix< Type >::PIMathMatrix ( const PIVector< PIVector< Type > > &  val)
inline

Constructor of class PIMathMatrix, which creates a matrix.

Parameters
valis PIVector<Type> of PIVector, which creates matrix.

◆ PIMathMatrix() [4/4]

template<typename Type >
PIMathMatrix< Type >::PIMathMatrix ( const PIVector2D< Type > &  val)
inline

Constructor of class PIMathMatrix, which creates a matrix.

Parameters
valis PIVector2D<Type>, which creates matrix.

Member Function Documentation

◆ identity()

template<typename Type >
static PIMathMatrix< Type > PIMathMatrix< Type >::identity ( const uint  cols,
const uint  rows 
)
inlinestatic

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

Parameters
colsis number of matrix column uint type
rowsis number of matrix row uint type
Returns
identity matrix(cols, rows)

◆ matrixRow()

template<typename Type >
static PIMathMatrix< Type > PIMathMatrix< Type >::matrixRow ( const PIMathVector< Type > &  val)
inlinestatic

Creates a row matrix of every element that is equal to every element of the vector.

Parameters
valis the vector type PIMathVector
Returns
row matrix of every element that is equal to every element of the vector

◆ matrixCol()

template<typename Type >
static PIMathMatrix< Type > PIMathMatrix< Type >::matrixCol ( const PIMathVector< Type > &  val)
inlinestatic

Creates a column matrix of every element that is equal to every element of the vector.

Parameters
valis the vector type PIMathVector
Returns
column matrix of every element that is equal to every element of the vector

◆ setCol()

template<typename Type >
PIMathMatrix< Type > & PIMathMatrix< Type >::setCol ( uint  index,
const PIMathVector< Type > &  v 
)
inline

Set the selected column in matrix.

If there are more elements of the vector than elements in the column of the matrix or index larger than the number of columns otherwise there will be "undefined behavior".

Parameters
indexis the number of the selected column.
vis a vector of the type PIMathVector<Type> that needs to fill the column.
Returns
matrix type PIMathMatrix<Type>

◆ setRow()

template<typename Type >
PIMathMatrix< Type > & PIMathMatrix< Type >::setRow ( uint  index,
const PIMathVector< Type > &  v 
)
inline

Set the selected row in matrix.

If there are more elements of the vector than elements in the row of the matrix, or index larger than the number of rows otherwise there will be "undefined behavior".

Parameters
indexis the number of the selected row.
vis a vector of the type PIMathVector<Type> that needs to fill the row.
Returns
matrix type PIMathMatrix<Type>.

◆ swapCols()

template<typename Type >
PIMathMatrix< Type > & PIMathMatrix< Type >::swapCols ( uint  r0,
uint  r1 
)
inline

Method which swaps selected columns in a matrix.

You cannot use an index larger than the number of columns, otherwise there will be "undefined behavior".

Parameters
r0is the number of the first selected column.
r1is the number of the second selected column.
Returns
matrix type PIMathMatrix<Type>.

◆ swapRows()

template<typename Type >
PIMathMatrix< Type > & PIMathMatrix< Type >::swapRows ( uint  c0,
uint  c1 
)
inline

Method which replace selected rows in a matrix.

You cannot use an index larger than the number of rows, otherwise there will be "undefined behavior"

Parameters
c0is the number of the first selected row.
c1is the number of the second selected row.
Returns
matrix type PIMathMatrix<Type>.

◆ fill()

template<typename Type >
PIMathMatrix< Type > & PIMathMatrix< 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 PIMathMatrix<Type>.

◆ isSquare()

template<typename Type >
bool PIMathMatrix< Type >::isSquare ( ) const
inline

Method which checks if matrix is square.

Returns
true if matrix is square, else false.

◆ isIdentity()

template<typename Type >
bool PIMathMatrix< 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<typename Type >
bool PIMathMatrix< Type >::isNull ( ) const
inline

Method which checks if every elements of matrix are zeros.

Returns
true if matrix is null, else false.

◆ isValid()

template<typename Type >
bool PIMathMatrix< Type >::isValid ( ) const
inline

Method which checks if matrix is empty.

Returns
true if matrix is valid, else false.

◆ operator+=()

template<typename Type >
void PIMathMatrix< Type >::operator+= ( const PIMathMatrix< Type > &  sm)
inline

Addition assignment with matrix sm.

Parameters
smmatrix for the addition assigment.

◆ operator-=()

template<typename Type >
void PIMathMatrix< Type >::operator-= ( const PIMathMatrix< Type > &  sm)
inline

Subtraction assignment with matrix sm.

Parameters
smmatrix for the subtraction assigment.

◆ operator*=()

template<typename Type >
void PIMathMatrix< Type >::operator*= ( const Type &  v)
inline

Multiplication assignment with value v.

Parameters
vvalue for the multiplication assigment.

◆ operator/=()

template<typename Type >
void PIMathMatrix< Type >::operator/= ( const Type &  v)
inline

Division assignment with value v.

Parameters
vvalue for the division assigment.

◆ operator-() [1/2]

template<typename Type >
PIMathMatrix< Type > PIMathMatrix< Type >::operator- ( ) const
inline

Negation operation.

Returns
copy of the negative matrix

◆ operator+()

template<typename Type >
PIMathMatrix< Type > PIMathMatrix< Type >::operator+ ( const PIMathMatrix< Type > &  sm) const
inline

Matrix addition.

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

◆ operator-() [2/2]

template<typename Type >
PIMathMatrix< Type > PIMathMatrix< Type >::operator- ( const PIMathMatrix< Type > &  sm) const
inline

Matrix substraction.

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

◆ operator*()

template<typename Type >
PIMathMatrix< Type > PIMathMatrix< Type >::operator* ( const Type &  v) const
inline

Matrix multiplication.

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

◆ operator/()

template<typename Type >
PIMathMatrix< Type > PIMathMatrix< Type >::operator/ ( const Type &  v) const
inline

Matrix division.

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

◆ determinant()

template<typename Type >
Type PIMathMatrix< 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<typename Type >
Type PIMathMatrix< Type >::trace ( ) const
inline

Calculate the trace of a matrix.

Works only with square matrix matrix.

Returns
matrix trace.

◆ toUpperTriangular()

template<typename Type >
PIMathMatrix< Type > & PIMathMatrix< 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
copy of transformed upper triangular matrix.

◆ invert()

template<typename Type >
PIMathMatrix< Type > & PIMathMatrix< Type >::invert ( bool *  ok = 0,
PIMathVector< Type > *  sv = 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<typename Type >
PIMathMatrix< Type > PIMathMatrix< 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<typename Type >
PIMathMatrix< Type > PIMathMatrix< Type >::transposed ( ) const
inline

Matrix transposition operation.

Works only with square matrix matrix.

Returns
copy of transposed matrix