dmatrix.h
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
DMatrix::columns
int columns() const
Definition: dmatrix.h:70
DVector::detach
void detach()
DMatrix::nrows
int nrows
Definition: dmatrix.h:78
DMatrix::operator[]
const X * operator[](int i) const
Definition: dmatrix.h:59
DMatrix::shares
int * shares
Definition: dmatrix.h:81
DVector::elems
X * elems
Definition: dmatrix.h:39
DMatrix::operator=
DMatrix & operator=(const DMatrix &)
DMatrix::operator-
DMatrix operator-(const DMatrix &) const
DMatrix::elems
X * elems
Definition: dmatrix.h:77
DVector::operator=
DVector & operator=(const DVector &)
DIncompatibleMatrixException
Definition: dmatrix.h:8
DVector::shares
int * shares
Definition: dmatrix.h:41
DMatrix::DMatrix
DMatrix(int n=0, int m=0)
n
int n
DVector::operator[]
const X & operator[](int i) const
Definition: dmatrix.h:25
X
const char X
DMatrix::operator[]
X * operator[](int i)
Definition: dmatrix.h:54
DMatrix::operator+
DMatrix operator+(const DMatrix &) const
DMatrix::inv
DMatrix inv() const
DMatrix::ncols
int ncols
Definition: dmatrix.h:78
DMatrix::operator*
DMatrix operator*(const DMatrix &) const
DMatrix::transpose
DMatrix transpose() const
m
Matrix3f m
DNotInvertibleMatrixException
Definition: dmatrix.h:7
DVector::operator+
DVector operator+(const DVector &) const
operator*
DVector< X > operator*(const DMatrix< X > m, const DVector< X > v)
DNotSquareMatrixException
Definition: dmatrix.h:9
DMatrix::~DMatrix
~DMatrix()
DVector::operator-
DVector operator-(const DVector &) const
DVector::DVector
DVector(int n=0)
DMatrix::mrows
X ** mrows
Definition: dmatrix.h:79
DMatrix::I
static DMatrix I(int)
DVector::I
static DVector< X > I(int)
DMatrix::rows
int rows() const
Definition: dmatrix.h:69
DVector::~DVector
~DVector()
DVector::operator*
X operator*(const DVector &) const
DVector::operator[]
X & operator[](int i)
Definition: dmatrix.h:20
DVector
Definition: dmatrix.h:12
i
int i
DMatrix
Definition: dmatrix.h:46
DVector::size
int size
Definition: dmatrix.h:40
DMatrix::det
const X det() const
DVector::dim
int dim() const
Definition: dmatrix.h:32
DMatrix::detach
void detach()


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:09