DGtal  1.5.beta
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)
35 #define SimpleMatrix_RECURSES
36 
37 #if !defined SimpleMatrix_h
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 
95 
103 
114  SimpleMatrix( std::initializer_list<TComponent> values );
115 
121  SimpleMatrix ( const Self & other );
122 
128  SimpleMatrix &operator=( const Self & other ) = default;
129 
130  // ----------------------- Standard services ------------------------------
131 
136  void clear();
137 
138 
144  void constant(const Component &aScalar);
145 
151  void identity();
152  inline void setIdentity() { identity(); }
153 
161 
166  inline Index rows() const { return M; }
167 
175 
180  inline Index cols() const { return N; }
181 
193  const Component & aValue);
194 
203 
212 
213  // ----------------------- SimpleMatrix computations ------------------------------
214 
215 
222  bool operator==(const Self & aMatrix) const;
223 
233  template<typename TComponentOther>
235 
243  Self operator+(const Self & aMatrix) const;
244 
252  Self & operator+=(const Self & aMatrix);
253 
254 
262  Self operator-(const Self & aMatrix) const;
263 
271  Self & operator-=(const Self & aMatrix);
272 
280  Self operator*(const Component & aScalar) const;
281 
289  Self & operator*=(const Component & aScalar);
290 
298  Self operator/(const Component & aScalar) const;
299 
307  Self & operator/=(const Component & aScalar) ;
308 
318  operator*(const SimpleMatrix<Component,N,M> & aMatrix) const;
319 
320 
329  ColumnVector operator*(const RowVector & aVector) const;
330 
331 
338 
339 
347  const DGtal::Dimension j) const;
348 
349 
356  Self cofactor() const;
357 
371  const DGtal::Dimension j) const;
372 
373 
384 
392 
393 
398 
399  // ----------------------- Interface --------------------------------------
400  public:
401 
406  void selfDisplay ( std::ostream & out ) const;
407 
412  bool isValid() const;
413 
414  // ------------------------- Protected Datas ------------------------------
415  private:
416 
417 
418  // ------------------------- Private Datas --------------------------------
419  private:
420 
422  std::array< Component, M*N> myValues;
423 
426  std::array< Component, M*N> myCofactorCoefs;
427 
428  // ------------------------- Hidden services ------------------------------
429  protected:
430 
431  }; // end of class SimpleMatrix
432 
439  template <typename T, DGtal::Dimension M, DGtal::Dimension N>
440  std::ostream&
441  operator<< ( std::ostream & out, const SimpleMatrix<T,M,N> & object );
442 
443 
447  template <typename TComponent, DGtal::Dimension TM, DGtal::Dimension TN>
449  operator* ( const TComponent& scalar, const SimpleMatrix<TComponent, TM, TN>& matrix);
450 
451 } // namespace DGtal
452 
453 
455 // Includes inline functions.
456 #include "DGtal/math/linalg/SimpleMatrixSpecializations.h"
457 #include "DGtal/math/linalg/SimpleMatrix.ih"
458 
459 // //
461 
462 #endif // !defined SimpleMatrix_h
463 
464 #undef SimpleMatrix_RECURSES
465 #endif // else defined(SimpleMatrix_RECURSES)
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
Aim: implements basic MxN Matrix services (M,N>=1).
Definition: SimpleMatrix.h:76
SimpleMatrix(std::initializer_list< TComponent > values)
std::array< Component, M *N > myCofactorCoefs
Definition: SimpleMatrix.h:426
Component & operator()(const DGtal::Dimension i, const DGtal::Dimension j)
Component minorDeterminant(const DGtal::Dimension i, const DGtal::Dimension j) const
Index rows() const
Definition: SimpleMatrix.h:166
TComponent Component
Definition: SimpleMatrix.h:79
Component determinant() const
SimpleMatrix< Component, TM, TN > Self
Definition: SimpleMatrix.h:86
static const DGtal::Dimension M
Definition: SimpleMatrix.h:80
ColumnVector column(const DGtal::Dimension j) const
Self cofactor() const
ColumnVector operator*(const RowVector &aVector) const
SimpleMatrix< Component, TM, TM > operator*(const SimpleMatrix< Component, N, M > &aMatrix) const
Self operator+(const Self &aMatrix) const
Component operator()(const DGtal::Dimension i, const DGtal::Dimension j) const
Self operator/(const Component &aScalar) const
RowVector row(const DGtal::Dimension i) const
static const DGtal::Dimension N
Definition: SimpleMatrix.h:81
SimpleMatrix< Component, TM, TN > inverse() const
Self & operator/=(const Component &aScalar)
void selfDisplay(std::ostream &out) const
Self & operator-=(const Self &aMatrix)
SimpleMatrix & operator=(const Self &other)=default
Component cofactor(const DGtal::Dimension i, const DGtal::Dimension j) const
void setComponent(const DGtal::Dimension i, const DGtal::Dimension j, const Component &aValue)
bool isValid() const
void constant(const Component &aScalar)
Self operator*(const Component &aScalar) const
Self & operator+=(const Self &aMatrix)
std::array< Component, M *N > myValues
Matrix values containers.
Definition: SimpleMatrix.h:422
SimpleMatrix(const Self &other)
Index cols() const
Definition: SimpleMatrix.h:180
PointVector< M, Component > ColumnVector
Definition: SimpleMatrix.h:84
BOOST_CONCEPT_ASSERT((concepts::CEuclideanRing< TComponent >))
Self & operator*=(const Component &aScalar)
Dimension Index
Types needed by CLinearAlgebraContainer.
Definition: SimpleMatrix.h:89
Self operator-(const Self &aMatrix) const
bool operator==(const Self &aMatrix) const
BOOST_STATIC_ASSERT(TM > 0)
Self & operator=(const SimpleMatrix< TComponentOther, M, N > &aMatrix)
PointVector< N, Component > RowVector
Definition: SimpleMatrix.h:83
SimpleMatrix< Component, TN, TM > transpose() const
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::uint32_t Dimension
Definition: Common.h:136
KForm< Calculus, order, duality > operator*(const typename Calculus::Scalar &scalar, const KForm< Calculus, order, duality > &form)
Aim: Defines the mathematical concept equivalent to a unitary commutative ring with a division operat...