DGtal 1.3.0
Searching...
No Matches
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
 TComponent any model of CEuclideanRing TM number of rows of the matrix TN number of columns of the matrix
Examples
examples/tutorial-examples/polyhedralizer.cpp, and tutorial-examples/polyhedralizer.cpp.

Definition at line 75 of file SimpleMatrix.h.

## ◆ ColumnVector

template<typename TComponent , DGtal::Dimension TM, DGtal::Dimension TN>
 typedef PointVector 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 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 DGtal::SimpleMatrix< TComponent, TM, TN >::Self

Definition at line 86 of file SimpleMatrix.h.

## ◆ 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
 values the 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
 other the object to clone. Forbidden by default.

## ◆ ~SimpleMatrix()

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

Destructor.

## ◆ 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 , 0 )

## ◆ BOOST_STATIC_ASSERT() [2/2]

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

## ◆ 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

Get column vector.

Parameters
 j the column index.
Returns
the j-th column

## ◆ constant()

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

Set a constant scalar to each matrix component.

Parameters
 aScalar the scalar

## ◆ 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 ( )

Set values to create identity matrix

Precondition
the matrix is a square one.

## ◆ 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
 i row index j column 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
 i row index j column 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
 i row index j column 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
 aScalar the 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
 aVector the 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
 aMatrix the 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
 aScalar the 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
 aMatrix the 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
 aMatrix the 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
 aMatrix the 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
 aMatrix the 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
 aScalar the 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
 aScalar the 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
 other the 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
 TComponentOther another Component type.
Parameters
 aMatrix the 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
 aMatrix another 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
 i the 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
 out the 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 )

Set a value at position (i,j).

Precondition
(i,j) must be in the range [0,M-1]x[0,N-1]
Parameters
 i row index j column index aValue a component

## ◆ setIdentity()

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

Definition at line 152 of file SimpleMatrix.h.

152{ identity(); }

## ◆ transpose()

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

Transpose the matrix.

Returns
the transposted NxM matrix

## ◆ 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: