DGtal  0.9.2
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 
109  SimpleMatrix ( const Self & other );
110 
111  // ----------------------- Standard services ------------------------------
112 
117  void clear();
118 
119 
125  void constant(const Component &aScalar);
126 
132  void identity();
133  inline void setIdentity() { identity(); }
134 
141  RowVector row(const DGtal::Dimension i) const;
142 
147  inline Index rows() const { return M; }
148 
155  ColumnVector column(const DGtal::Dimension j) const;
156 
161  inline Index cols() const { return N; }
162 
173  void setComponent(const DGtal::Dimension i, const DGtal::Dimension j,
174  const Component & aValue);
175 
183  Component operator()(const DGtal::Dimension i, const DGtal::Dimension j) const;
184 
192  Component& operator()(const DGtal::Dimension i, const DGtal::Dimension j);
193 
194  // ----------------------- SimpleMatrix computations ------------------------------
195 
196 
203  bool operator==(const Self & aMatrix) const;
204 
214  template<typename TComponentOther>
215  Self & operator=(const SimpleMatrix<TComponentOther, M, N>& aMatrix);
216 
224  Self operator+(const Self & aMatrix) const;
225 
233  Self & operator+=(const Self & aMatrix);
234 
235 
243  Self operator-(const Self & aMatrix) const;
244 
252  Self & operator-=(const Self & aMatrix);
253 
261  Self operator*(const Component & aScalar) const;
262 
270  Self & operator*=(const Component & aScalar);
271 
279  Self operator/(const Component & aScalar) const;
280 
288  Self & operator/=(const Component & aScalar) ;
289 
299  operator*(const SimpleMatrix<Component,N,M> & aMatrix) const;
300 
301 
310  ColumnVector operator*(const RowVector & aVector) const;
311 
312 
319 
320 
327  Component cofactor(const DGtal::Dimension i,
328  const DGtal::Dimension j) const;
329 
330 
337  Self cofactor() const;
338 
351  Component minorDeterminant(const DGtal::Dimension i,
352  const DGtal::Dimension j) const;
353 
354 
364  Component determinant() const;
365 
373 
374 
378  ~SimpleMatrix();
379 
380  // ----------------------- Interface --------------------------------------
381  public:
382 
387  void selfDisplay ( std::ostream & out ) const;
388 
393  bool isValid() const;
394 
395  // ------------------------- Protected Datas ------------------------------
396  private:
397 
398 
399  // ------------------------- Private Datas --------------------------------
400  private:
401 
403  std::array< Component, M*N> myValues;
404 
407  std::array< Component, M*N> myCofactorCoefs;
408 
409  // ------------------------- Hidden services ------------------------------
410  protected:
411 
412  }; // end of class SimpleMatrix
413 
420  template <typename T, DGtal::Dimension M, DGtal::Dimension N>
421  std::ostream&
422  operator<< ( std::ostream & out, const SimpleMatrix<T,M,N> & object );
423 
424 
428  template <typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
430  operator* ( const TComponent& scalar, const SimpleMatrix<TComponent, TM, TN>& matrix);
431 
432 } // namespace DGtal
433 
434 
436 // Includes inline functions.
437 #include "DGtal/math/linalg/SimpleMatrixSpecializations.h"
438 #include "DGtal/math/linalg/SimpleMatrix.ih"
439 
440 // //
442 
443 #endif // !defined SimpleMatrix_h
444 
445 #undef SimpleMatrix_RECURSES
446 #endif // else defined(SimpleMatrix_RECURSES)
SimpleMatrix< Component, TM, TN > inverse() const
SimpleMatrix< Component, TN, TM > transpose() const
Component determinant() const
Self cofactor() const
Self & operator/=(const Component &aScalar)
SimpleMatrix< Component, TM, TN > Self
Definition: SimpleMatrix.h:86
DGtal::uint32_t Dimension
Definition: Common.h:113
std::array< Component, M *N > myCofactorCoefs
Definition: SimpleMatrix.h:407
RowVector row(const DGtal::Dimension i) const
void selfDisplay(std::ostream &out) const
BOOST_STATIC_ASSERT(TM > 0)
Component operator()(const DGtal::Dimension i, const DGtal::Dimension j) const
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
Self operator*(const Component &aScalar) 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)
Self operator+(const Self &aMatrix) const
Component minorDeterminant(const DGtal::Dimension i, const DGtal::Dimension j) const
void setComponent(const DGtal::Dimension i, const DGtal::Dimension j, const Component &aValue)
Self & operator-=(const Self &aMatrix)
std::array< Component, M *N > myValues
Matrix values containers.
Definition: SimpleMatrix.h:403
bool operator==(const Self &aMatrix) const
Index cols() const
Definition: SimpleMatrix.h:161
DGtal is the top-level namespace which contains all DGtal functions and types.
BOOST_CONCEPT_ASSERT((concepts::CEuclideanRing< TComponent >))
void constant(const Component &aScalar)
ColumnVector column(const DGtal::Dimension j) const
bool isValid() const
Dimension Index
Types needed by CLinearAlgebraContainer.
Definition: SimpleMatrix.h:89
Self & operator=(const SimpleMatrix< TComponentOther, M, N > &aMatrix)
Self operator/(const Component &aScalar) const
Self operator-(const Self &aMatrix) const
Index rows() const
Definition: SimpleMatrix.h:147
static const DGtal::Dimension N
Definition: SimpleMatrix.h:81
KForm< Calculus, order, duality > operator*(const typename Calculus::Scalar &scalar, const KForm< Calculus, order, duality > &form)
PointVector< N, Component > RowVector
Definition: SimpleMatrix.h:83
Self & operator+=(const Self &aMatrix)
static const DGtal::Dimension M
Definition: SimpleMatrix.h:80