DGtal  1.0.0
SimpleMatrix.h
1 
17 #pragma once
18 
31 #if defined(SimpleMatrix_RECURSES)
32 #error Recursive header files inclusion detected in SimpleMatrix.h
33 #else // defined(SimpleMatrix_RECURSES)
34 
35 #define SimpleMatrix_RECURSES
36 
37 #if !defined SimpleMatrix_h
38 
39 #define SimpleMatrix_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/kernel/CEuclideanRing.h"
46 #include "DGtal/kernel/PointVector.h"
47 #include "DGtal/kernel/NumberTraits.h"
48 #include <array>
50 
51 namespace DGtal
52 {
53 
55  // template class SimpleMatrix
74  template <typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
76  {
77 
78  public:
79  typedef TComponent Component;
80  static const DGtal::Dimension M = TM;
81  static const DGtal::Dimension N = TN;
82 
85 
87 
89  typedef Dimension Index;
90  typedef Component Scalar;
91 
93  BOOST_STATIC_ASSERT(TM > 0 );
94  BOOST_STATIC_ASSERT(TM > 0 );
95 
102  SimpleMatrix();
103 
114  SimpleMatrix( std::initializer_list<TComponent> values );
115 
121  SimpleMatrix ( const Self & other );
122 
123  // ----------------------- Standard services ------------------------------
124 
129  void clear();
130 
131 
137  void constant(const Component &aScalar);
138 
144  void identity();
145  inline void setIdentity() { identity(); }
146 
153  RowVector row(const DGtal::Dimension i) const;
154 
159  inline Index rows() const { return M; }
160 
167  ColumnVector column(const DGtal::Dimension j) const;
168 
173  inline Index cols() const { return N; }
174 
185  void setComponent(const DGtal::Dimension i, const DGtal::Dimension j,
186  const Component & aValue);
187 
195  Component operator()(const DGtal::Dimension i, const DGtal::Dimension j) const;
196 
205 
206  // ----------------------- SimpleMatrix computations ------------------------------
207 
208 
215  bool operator==(const Self & aMatrix) const;
216 
226  template<typename TComponentOther>
228 
236  Self operator+(const Self & aMatrix) const;
237 
245  Self & operator+=(const Self & aMatrix);
246 
247 
255  Self operator-(const Self & aMatrix) const;
256 
264  Self & operator-=(const Self & aMatrix);
265 
273  Self operator*(const Component & aScalar) const;
274 
282  Self & operator*=(const Component & aScalar);
283 
291  Self operator/(const Component & aScalar) const;
292 
300  Self & operator/=(const Component & aScalar) ;
301 
311  operator*(const SimpleMatrix<Component,N,M> & aMatrix) const;
312 
313 
322  ColumnVector operator*(const RowVector & aVector) const;
323 
324 
331 
332 
340  const DGtal::Dimension j) const;
341 
342 
349  Self cofactor() const;
350 
364  const DGtal::Dimension j) const;
365 
366 
376  Component determinant() const;
377 
385 
386 
390  ~SimpleMatrix();
391 
392  // ----------------------- Interface --------------------------------------
393  public:
394 
399  void selfDisplay ( std::ostream & out ) const;
400 
405  bool isValid() const;
406 
407  // ------------------------- Protected Datas ------------------------------
408  private:
409 
410 
411  // ------------------------- Private Datas --------------------------------
412  private:
413 
415  std::array< Component, M*N> myValues;
416 
419  std::array< Component, M*N> myCofactorCoefs;
420 
421  // ------------------------- Hidden services ------------------------------
422  protected:
423 
424  }; // end of class SimpleMatrix
425 
432  template <typename T, DGtal::Dimension M, DGtal::Dimension N>
433  std::ostream&
434  operator<< ( std::ostream & out, const SimpleMatrix<T,M,N> & object );
435 
436 
440  template <typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
442  operator* ( const TComponent& scalar, const SimpleMatrix<TComponent, TM, TN>& matrix);
443 
444 } // namespace DGtal
445 
446 
448 // Includes inline functions.
449 #include "DGtal/math/linalg/SimpleMatrixSpecializations.h"
450 #include "DGtal/math/linalg/SimpleMatrix.ih"
451 
452 // //
454 
455 #endif // !defined SimpleMatrix_h
456 
457 #undef SimpleMatrix_RECURSES
458 #endif // else defined(SimpleMatrix_RECURSES)
Self & operator/=(const Component &aScalar)
Self operator+(const Self &aMatrix) const
SimpleMatrix< Component, TM, TN > Self
Definition: SimpleMatrix.h:86
DGtal::uint32_t Dimension
Definition: Common.h:127
std::array< Component, M *N > myCofactorCoefs
Definition: SimpleMatrix.h:419
Self operator-(const Self &aMatrix) const
Self & operator *=(const Component &aScalar)
BOOST_STATIC_ASSERT(TM > 0)
SimpleMatrix< Component, TM, TN > inverse() const
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:165
Component minorDeterminant(const DGtal::Dimension i, const DGtal::Dimension j) const
RowVector row(const DGtal::Dimension i) const
PointVector< M, Component > ColumnVector
Definition: SimpleMatrix.h:84
Aim: implements basic MxN Matrix services (M,N>=1).
Definition: SimpleMatrix.h:75
Aim: Defines the mathematical concept equivalent to a unitary commutative ring with a division operat...
TComponent Component
Definition: SimpleMatrix.h:79
Self operator *(const Component &aScalar) const
Self cofactor() const
bool operator==(const Self &aMatrix) const
void setComponent(const DGtal::Dimension i, const DGtal::Dimension j, const Component &aValue)
Self & operator-=(const Self &aMatrix)
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
std::array< Component, M *N > myValues
Matrix values containers.
Definition: SimpleMatrix.h:415
bool isValid() const
Index cols() const
Definition: SimpleMatrix.h:173
Index rows() const
Definition: SimpleMatrix.h:159
DGtal is the top-level namespace which contains all DGtal functions and types.
Component operator()(const DGtal::Dimension i, const DGtal::Dimension j) const
BOOST_CONCEPT_ASSERT((concepts::CEuclideanRing< TComponent >))
void constant(const Component &aScalar)
ColumnVector column(const DGtal::Dimension j) const
KForm< Calculus, order, duality > operator *(const typename Calculus::Scalar &scalar, const KForm< Calculus, order, duality > &form)
Dimension Index
Types needed by CLinearAlgebraContainer.
Definition: SimpleMatrix.h:89
Self & operator=(const SimpleMatrix< TComponentOther, M, N > &aMatrix)
Self operator/(const Component &aScalar) const
Component determinant() const
void selfDisplay(std::ostream &out) const
static const DGtal::Dimension N
Definition: SimpleMatrix.h:81
SimpleMatrix< Component, TN, TM > transpose() const
PointVector< N, Component > RowVector
Definition: SimpleMatrix.h:83
Self & operator+=(const Self &aMatrix)
static const DGtal::Dimension M
Definition: SimpleMatrix.h:80