dmatrix.hh
Go to the documentation of this file.
1 #ifndef DMATRIX_HXX
2 #define DMATRIX_HXX
3 
4 #include <iostream>
5 #include <exception>
6 
7 class DNotInvertibleMatrixException: public std::exception {};
8 class DIncompatibleMatrixException: public std::exception {};
9 class DNotSquareMatrixException: public std::exception {};
10 
11 
12 template <class X> struct DVector{
13 public:
14  DVector(int n=0);
15  ~DVector();
16 
17  DVector(const DVector&);
18  DVector& operator=(const DVector&);
19 
20  X& operator[](int i) {
21  if ((*shares)>1) detach();
22  return elems[i];
23  }
24 
25  const X& operator[](int i) const { return elems[i]; }
26 
27  X operator*(const DVector&) const;
28  DVector operator+(const DVector&) const;
29  DVector operator-(const DVector&) const;
30  DVector operator*(const X&) const;
31 
32  int dim() const { return size; }
33 
34  void detach();
35 
36  static DVector<X> I(int);
37 
38 protected:
39  X * elems;
40  int size;
41  int * shares;
42 };
43 
44 
45 
46 template <class X> class DMatrix {
47 public:
48  DMatrix(int n=0,int m=0);
49  ~DMatrix();
50 
51  DMatrix(const DMatrix&);
52  DMatrix& operator=(const DMatrix&);
53 
54  X * operator[](int i) {
55  if ((*shares)>1) detach();
56  return mrows[i];
57  }
58 
59  const X * operator[](int i) const { return mrows[i]; }
60 
61  const X det() const;
62  DMatrix inv() const;
63  DMatrix transpose() const;
64  DMatrix operator*(const DMatrix&) const;
65  DMatrix operator+(const DMatrix&) const;
66  DMatrix operator-(const DMatrix&) const;
67  DMatrix operator*(const X&) const;
68 
69  int rows() const { return nrows; }
70  int columns() const { return ncols; }
71 
72  void detach();
73 
74  static DMatrix I(int);
75 
76 protected:
77  X * elems;
78  int nrows,ncols;
79  X ** mrows;
80 
81  int * shares;
82 };
83 
84 
85 template <class X> DVector<X> operator * (const DMatrix<X> m, const DVector<X> v);
86 
87 template <class X> DVector<X> operator * (const DVector<X> v, const DMatrix<X> m);
88 
89 
90 /*************** IMPLEMENTATION ***************/
91 
92 #include "dmatrix.hxx"
93 
94 #endif
const X & operator[](int i) const
Definition: dmatrix.hh:25
int size
Definition: dmatrix.hh:40
int * shares
Definition: dmatrix.hh:41
int columns() const
Definition: dmatrix.hh:70
DVector< X > operator*(const DMatrix< X > m, const DVector< X > v)
X * operator[](int i)
Definition: dmatrix.hh:54
int nrows
Definition: dmatrix.hh:78
int rows() const
Definition: dmatrix.hh:69
X ** mrows
Definition: dmatrix.hh:79
X * elems
Definition: dmatrix.hh:39
GLM_FUNC_DECL tmat2x2< T, P > operator+(tmat2x2< T, P > const &m, T const &s)
GLM_FUNC_DECL tmat2x2< T, P > operator-(tmat2x2< T, P > const &m, T const &s)
int dim() const
Definition: dmatrix.hh:32
X * elems
Definition: dmatrix.hh:77
X & operator[](int i)
Definition: dmatrix.hh:20
const X * operator[](int i) const
Definition: dmatrix.hh:59
int * shares
Definition: dmatrix.hh:81


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:34:58