DGtal 1.3.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Private Attributes
DGtal::SimpleMatrix< TComponent, TM, TN > Class Template Reference

Aim: implements basic MxN Matrix services (M,N>=1). More...

#include <DGtal/math/linalg/SimpleMatrix.h>

Public Types

typedef TComponent Component
 
typedef PointVector< N, ComponentRowVector
 
typedef PointVector< M, ComponentColumnVector
 
typedef SimpleMatrix< Component, TM, TN > Self
 
typedef Dimension Index
 Types needed by CLinearAlgebraContainer. More...
 
typedef Component Scalar
 

Public Member Functions

 BOOST_CONCEPT_ASSERT ((concepts::CEuclideanRing< TComponent >))
 
 BOOST_STATIC_ASSERT (TM > 0)
 
 BOOST_STATIC_ASSERT (TM > 0)
 
 SimpleMatrix ()
 
 SimpleMatrix (std::initializer_list< TComponent > values)
 
 SimpleMatrix (const Self &other)
 
SimpleMatrixoperator= (const Self &other)=default
 
void clear ()
 
void constant (const Component &aScalar)
 
void identity ()
 
void setIdentity ()
 
RowVector row (const DGtal::Dimension i) const
 
Index rows () const
 
ColumnVector column (const DGtal::Dimension j) const
 
Index cols () const
 
void setComponent (const DGtal::Dimension i, const DGtal::Dimension j, const Component &aValue)
 
Component operator() (const DGtal::Dimension i, const DGtal::Dimension j) const
 
Componentoperator() (const DGtal::Dimension i, const DGtal::Dimension j)
 
bool operator== (const Self &aMatrix) const
 
template<typename TComponentOther >
Selfoperator= (const SimpleMatrix< TComponentOther, M, N > &aMatrix)
 
Self operator+ (const Self &aMatrix) const
 
Selfoperator+= (const Self &aMatrix)
 
Self operator- (const Self &aMatrix) const
 
Selfoperator-= (const Self &aMatrix)
 
Self operator* (const Component &aScalar) const
 
Selfoperator*= (const Component &aScalar)
 
Self operator/ (const Component &aScalar) const
 
Selfoperator/= (const Component &aScalar)
 
SimpleMatrix< Component, TM, TM > operator* (const SimpleMatrix< Component, N, M > &aMatrix) const
 
ColumnVector operator* (const RowVector &aVector) const
 
SimpleMatrix< Component, TN, TM > transpose () const
 
Component cofactor (const DGtal::Dimension i, const DGtal::Dimension j) const
 
Self cofactor () const
 
Component minorDeterminant (const DGtal::Dimension i, const DGtal::Dimension j) const
 
Component determinant () const
 
SimpleMatrix< Component, TM, TN > inverse () const
 
 ~SimpleMatrix ()
 
void selfDisplay (std::ostream &out) const
 
bool isValid () const
 

Static Public Attributes

static const DGtal::Dimension M = TM
 
static const DGtal::Dimension N = TN
 

Private Attributes

std::array< Component, M *NmyValues
 Matrix values containers. More...
 
std::array< Component, M *NmyCofactorCoefs
 

Detailed Description

template<typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
class DGtal::SimpleMatrix< TComponent, TM, TN >

Aim: implements basic MxN Matrix services (M,N>=1).

Description of template class 'SimpleMatrix'

This class defines simple matrix with static size. Computations are performed in the euclidean ring associated with the type TComponent.

Matrix coefficient indices are in the range [0,M-1] and [0,N-1].

This class also defines types for row and column vectors as specialized PointVector types.

Class inspired by Anis Benyoub (INSA-Lyon).

Template Parameters
TComponentany model of CEuclideanRing
TMnumber of rows of the matrix
TNnumber of columns of the matrix
Examples
examples/tutorial-examples/polyhedralizer.cpp, and tutorial-examples/polyhedralizer.cpp.

Definition at line 75 of file SimpleMatrix.h.

Member Typedef Documentation

◆ ColumnVector

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
typedef PointVector<M,Component> DGtal::SimpleMatrix< TComponent, TM, TN >::ColumnVector

Definition at line 84 of file SimpleMatrix.h.

◆ Component

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
typedef TComponent DGtal::SimpleMatrix< TComponent, TM, TN >::Component

Definition at line 79 of file SimpleMatrix.h.

◆ Index

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
typedef Dimension DGtal::SimpleMatrix< TComponent, TM, TN >::Index

Types needed by CLinearAlgebraContainer.

Definition at line 89 of file SimpleMatrix.h.

◆ RowVector

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
typedef PointVector<N,Component> DGtal::SimpleMatrix< TComponent, TM, TN >::RowVector

Definition at line 83 of file SimpleMatrix.h.

◆ Scalar

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
typedef Component DGtal::SimpleMatrix< TComponent, TM, TN >::Scalar

Definition at line 90 of file SimpleMatrix.h.

◆ Self

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
typedef SimpleMatrix<Component,TM,TN> DGtal::SimpleMatrix< TComponent, TM, TN >::Self

Definition at line 86 of file SimpleMatrix.h.

Constructor & Destructor Documentation

◆ SimpleMatrix() [1/3]

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
DGtal::SimpleMatrix< TComponent, TM, TN >::SimpleMatrix ( )

Create a static mxn matrix.

SimpleMatrix values are all set to the zero value associated to Component type.

◆ SimpleMatrix() [2/3]

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
DGtal::SimpleMatrix< TComponent, TM, TN >::SimpleMatrix ( std::initializer_list< TComponent >  values)

Constructor from initializer list.

This matrix values are given row by row (top to bottom) from left to right. {a,b,c,d} = [[a b] [c d]]

Parameters
valuesthe initializer list.

◆ SimpleMatrix() [3/3]

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
DGtal::SimpleMatrix< TComponent, TM, TN >::SimpleMatrix ( const Self other)

Copy constructor.

Parameters
otherthe object to clone. Forbidden by default.

◆ ~SimpleMatrix()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
DGtal::SimpleMatrix< TComponent, TM, TN >::~SimpleMatrix ( )

Destructor.

Member Function Documentation

◆ BOOST_CONCEPT_ASSERT()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
DGtal::SimpleMatrix< TComponent, TM, TN >::BOOST_CONCEPT_ASSERT ( (concepts::CEuclideanRing< TComponent >)  )

◆ BOOST_STATIC_ASSERT() [1/2]

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
DGtal::SimpleMatrix< TComponent, TM, TN >::BOOST_STATIC_ASSERT ( TM  ,
 
)

◆ BOOST_STATIC_ASSERT() [2/2]

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
DGtal::SimpleMatrix< TComponent, TM, TN >::BOOST_STATIC_ASSERT ( TM  ,
 
)

◆ clear()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
void DGtal::SimpleMatrix< TComponent, TM, TN >::clear ( )

◆ cofactor() [1/2]

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
Self DGtal::SimpleMatrix< TComponent, TM, TN >::cofactor ( ) const

Cofactor matrix computation.

Precondition
the matrix is a square one.
Returns
the cofactor matrix.

◆ cofactor() [2/2]

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
Component DGtal::SimpleMatrix< TComponent, TM, TN >::cofactor ( const DGtal::Dimension  i,
const DGtal::Dimension  j 
) const

Cofactor of the matrix at position (i,j).

Precondition
the matrix is a square one.
Returns
the cofactor at (i,j).

◆ cols()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
Index DGtal::SimpleMatrix< TComponent, TM, TN >::cols ( ) const
inline

Get number of columns.

Definition at line 180 of file SimpleMatrix.h.

180{ return N; }
static const DGtal::Dimension N
Definition: SimpleMatrix.h:81

References DGtal::SimpleMatrix< TComponent, TM, TN >::N.

◆ column()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
ColumnVector DGtal::SimpleMatrix< TComponent, TM, TN >::column ( const DGtal::Dimension  j) const

◆ constant()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
void DGtal::SimpleMatrix< TComponent, TM, TN >::constant ( const Component aScalar)

◆ determinant()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
Component DGtal::SimpleMatrix< TComponent, TM, TN >::determinant ( ) const

Returns the determinant of square matrix. Slow method for large matrices.

Precondition
this must be NxN

Specialized methods exist for 2x2 and 3x3 matrices.

Returns
the determinant.

◆ identity()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
void DGtal::SimpleMatrix< TComponent, TM, TN >::identity ( )

◆ inverse()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
SimpleMatrix< Component, TM, TN > DGtal::SimpleMatrix< TComponent, TM, TN >::inverse ( ) const

Compute the inverse of the matrix.

Precondition
the matrix is a square one.
Returns
the inverse matrix.

◆ isValid()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
bool DGtal::SimpleMatrix< TComponent, TM, TN >::isValid ( ) const

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.

◆ minorDeterminant()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
Component DGtal::SimpleMatrix< TComponent, TM, TN >::minorDeterminant ( const DGtal::Dimension  i,
const DGtal::Dimension  j 
) const

Return the minor determinant (i,j) of the current matrix

Specialized methods exist for 2x2 and 3x3 matrices.

Precondition
the matrix is a square one.
Parameters
irow index
jcolumn index
Returns
the minor (i,j)

◆ operator()() [1/2]

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
Component & DGtal::SimpleMatrix< TComponent, TM, TN >::operator() ( const DGtal::Dimension  i,
const DGtal::Dimension  j 
)

Get a reference to the value at position (i,j).

Parameters
irow index
jcolumn index

◆ operator()() [2/2]

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
Component DGtal::SimpleMatrix< TComponent, TM, TN >::operator() ( const DGtal::Dimension  i,
const DGtal::Dimension  j 
) const

Get a value at position (i,j).

Parameters
irow index
jcolumn index

◆ operator*() [1/3]

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
Self DGtal::SimpleMatrix< TComponent, TM, TN >::operator* ( const Component aScalar) const

Product between the matrix 'this' and a scalar

Parameters
aScalarthe scalar coefficient
Returns
the resulting matrix

◆ operator*() [2/3]

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
ColumnVector DGtal::SimpleMatrix< TComponent, TM, TN >::operator* ( const RowVector aVector) const

Product between the matrix and a Column vector.

Note
the product is O(N^3) for NxN matrices.
Parameters
aVectorthe vector to multiply
Returns
the product MxM matrix

◆ operator*() [3/3]

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
SimpleMatrix< Component, TM, TM > DGtal::SimpleMatrix< TComponent, TM, TN >::operator* ( const SimpleMatrix< Component, N, M > &  aMatrix) const

Product between the matrix 'this' and aMatrix.

Note
the product is O(N^3) for NxN matrices.
Parameters
aMatrixthe NxM matrix to multiply
Returns
the product MxM matrix

◆ operator*=()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
Self & DGtal::SimpleMatrix< TComponent, TM, TN >::operator*= ( const Component aScalar)

Product between the matrix 'this' and a scalar

Parameters
aScalarthe scalar coefficient
Returns
the resulting a reference to the matrix

◆ operator+()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
Self DGtal::SimpleMatrix< TComponent, TM, TN >::operator+ ( const Self aMatrix) const

Addition between the matrix 'this' and aMatrix.

Parameters
aMatrixthe matrix to add to self.
Returns
the summed matrix

◆ operator+=()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
Self & DGtal::SimpleMatrix< TComponent, TM, TN >::operator+= ( const Self aMatrix)

Addition and assignment between the matrix 'this' and aMatrix.

Parameters
aMatrixthe matrix to add to self.
Returns
a reference to the result

◆ operator-()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
Self DGtal::SimpleMatrix< TComponent, TM, TN >::operator- ( const Self aMatrix) const

Substract between the matrix 'this' and aMatrix.

Parameters
aMatrixthe matrix to substract to self.
Returns
the difference matrix

◆ operator-=()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
Self & DGtal::SimpleMatrix< TComponent, TM, TN >::operator-= ( const Self aMatrix)

Substract and assignment between the matrix 'this' and aMatrix.

Parameters
aMatrixthe matrix to substract to self.
Returns
a reference to the result

◆ operator/()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
Self DGtal::SimpleMatrix< TComponent, TM, TN >::operator/ ( const Component aScalar) const

Division of a matrix by a scalar.

Parameters
aScalarthe scalar value
Returns
the resulting matrix

◆ operator/=()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
Self & DGtal::SimpleMatrix< TComponent, TM, TN >::operator/= ( const Component aScalar)

Division of a matrix by a scalar.

Parameters
aScalarthe scalar value
Returns
a reference to the updated matrix

◆ operator=() [1/2]

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
SimpleMatrix & DGtal::SimpleMatrix< TComponent, TM, TN >::operator= ( const Self other)
default

Default assignment operator.

Parameters
otherthe object to copy.

◆ operator=() [2/2]

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
template<typename TComponentOther >
Self & DGtal::SimpleMatrix< TComponent, TM, TN >::operator= ( const SimpleMatrix< TComponentOther, M, N > &  aMatrix)

Assignment operator from another matrix. Note: a static_cast from TComponentOther to Component is performed.

Template Parameters
TComponentOtheranother Component type.
Parameters
aMatrixthe matrix to copy.
Returns
reference on the matrix

◆ operator==()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
bool DGtal::SimpleMatrix< TComponent, TM, TN >::operator== ( const Self aMatrix) const

SimpleMatrix comparison.

Parameters
aMatrixanother matrix.
Returns
true if aMatrix equals this

◆ row()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
RowVector DGtal::SimpleMatrix< TComponent, TM, TN >::row ( const DGtal::Dimension  i) const

Get row vector.

Parameters
ithe row index
Returns
the i-th row

Referenced by testColRow().

◆ rows()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
Index DGtal::SimpleMatrix< TComponent, TM, TN >::rows ( ) const
inline

Get number of rows.

Definition at line 166 of file SimpleMatrix.h.

166{ return M; }
static const DGtal::Dimension M
Definition: SimpleMatrix.h:80

References DGtal::SimpleMatrix< TComponent, TM, TN >::M.

◆ selfDisplay()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
void DGtal::SimpleMatrix< TComponent, TM, TN >::selfDisplay ( std::ostream &  out) const

Writes/Displays the object on an output stream.

Parameters
outthe output stream where the object is written.

◆ setComponent()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
void DGtal::SimpleMatrix< TComponent, TM, TN >::setComponent ( const DGtal::Dimension  i,
const DGtal::Dimension  j,
const Component aValue 
)

◆ setIdentity()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
void DGtal::SimpleMatrix< TComponent, TM, TN >::setIdentity ( )
inline

◆ transpose()

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
SimpleMatrix< Component, TN, TM > DGtal::SimpleMatrix< TComponent, TM, TN >::transpose ( ) const

Field Documentation

◆ M

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
const DGtal::Dimension DGtal::SimpleMatrix< TComponent, TM, TN >::M = TM
static

Definition at line 80 of file SimpleMatrix.h.

Referenced by DGtal::SimpleMatrix< TComponent, TM, TN >::rows().

◆ myCofactorCoefs

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
std::array< Component, M*N> DGtal::SimpleMatrix< TComponent, TM, TN >::myCofactorCoefs
private

Static computation of cofactor coefficients

Todo:
should be static

Definition at line 426 of file SimpleMatrix.h.

◆ myValues

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
std::array< Component, M*N> DGtal::SimpleMatrix< TComponent, TM, TN >::myValues
private

Matrix values containers.

Definition at line 422 of file SimpleMatrix.h.

◆ N

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
const DGtal::Dimension DGtal::SimpleMatrix< TComponent, TM, TN >::N = TN
static

Definition at line 81 of file SimpleMatrix.h.

Referenced by DGtal::SimpleMatrix< TComponent, TM, TN >::cols().


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