dmatrix.hh
Go to the documentation of this file.
00001 #ifndef DMATRIX_HXX 
00002 #define DMATRIX_HXX
00003 
00004 #include <iostream>
00005 #include <exception>
00006 
00007 class DNotInvertibleMatrixException: public std::exception {};
00008 class DIncompatibleMatrixException: public std::exception {};
00009 class DNotSquareMatrixException: public std::exception {};
00010 
00011 
00012 template <class X> struct DVector{
00013 public:
00014   DVector(int n=0);
00015   ~DVector();
00016   
00017   DVector(const DVector&);
00018   DVector& operator=(const DVector&);
00019   
00020   X&  operator[](int i) {
00021     if ((*shares)>1) detach();
00022     return elems[i];
00023   }
00024   
00025   const X&  operator[](int i) const { return elems[i]; }
00026   
00027   X operator*(const DVector&) const;
00028   DVector operator+(const DVector&) const;
00029   DVector operator-(const DVector&) const;
00030   DVector operator*(const X&) const;
00031   
00032   int dim() const { return size; }
00033   
00034   void detach();
00035   
00036   static DVector<X> I(int);
00037   
00038 protected:
00039   X * elems;
00040   int size;
00041   int * shares;
00042 };
00043 
00044 
00045 
00046 template <class X> class DMatrix {
00047 public:
00048   DMatrix(int n=0,int m=0);
00049   ~DMatrix();
00050   
00051   DMatrix(const DMatrix&);
00052   DMatrix& operator=(const DMatrix&);
00053   
00054   X * operator[](int i) {
00055     if ((*shares)>1) detach();
00056     return mrows[i];
00057   }
00058   
00059   const X * operator[](int i) const { return mrows[i]; }
00060   
00061   const X det() const;
00062   DMatrix inv() const;
00063   DMatrix transpose() const;
00064   DMatrix operator*(const DMatrix&) const;
00065   DMatrix operator+(const DMatrix&) const;
00066   DMatrix operator-(const DMatrix&) const;
00067   DMatrix operator*(const X&) const;
00068   
00069   int rows() const { return nrows; }
00070   int columns() const { return ncols; }
00071   
00072   void detach();
00073   
00074   static DMatrix I(int);
00075   
00076 protected:
00077   X * elems;
00078   int nrows,ncols;
00079   X ** mrows;
00080   
00081   int * shares;
00082 };
00083 
00084 
00085 template <class X> DVector<X> operator * (const DMatrix<X> m, const DVector<X> v);
00086 
00087 template <class X> DVector<X> operator * (const DVector<X> v, const DMatrix<X> m);
00088 
00089 
00090 /*************** IMPLEMENTATION ***************/
00091 
00092 #include "dmatrix.hxx"
00093 
00094 #endif


rtabmap
Author(s): Mathieu Labbe
autogenerated on Sat Jul 23 2016 11:44:15