00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef mrpt_math_forwddecls_H
00029 #define mrpt_math_forwddecls_H
00030
00031 #include <mrpt/config.h>
00032 #include <mrpt/base/link_pragmas.h>
00033 #include <mrpt/utils/types.h>
00034 #include <cmath>
00035 #include <cstdlib>
00036 #include <algorithm>
00037
00038
00039
00040
00041
00042
00043 namespace mrpt
00044 {
00045 namespace utils
00046 {
00047 class BASE_IMPEXP CStream;
00048 template<class T> inline T square(const T& x);
00049 }
00050
00051 namespace poses
00052 {
00053 class CPoint2D;
00054 class CPoint3D;
00055 class CPose2D;
00056 class CPose3D;
00057 class CPose3DQuat;
00058 }
00059
00060 namespace math
00061 {
00062 struct TPoint2D;
00063 struct TPoint3D;
00064 struct TPose2D;
00065 struct TPose3D;
00066 struct TPose3DQuat;
00067
00068
00069
00070 enum TMatrixTextFileFormat
00071 {
00072 MATRIX_FORMAT_ENG = 0,
00073 MATRIX_FORMAT_FIXED = 1,
00074 MATRIX_FORMAT_INT = 2
00075 };
00076
00077
00078
00079 #define UNINITIALIZED_MATRIX false,false,false
00080
00081
00082
00083 template <class T> class CVectorTemplate;
00084
00085 template <class T> class CMatrixTemplate;
00086 template <class T> class BASE_IMPEXP CMatrixTemplateNumeric;
00087 template <typename T,size_t NROWS,size_t NCOLS> class CMatrixFixedNumeric;
00088 template<typename MATRIXTYPE> class CArbitrarySubmatrixView;
00089
00090 template <typename T, std::size_t N> class CArray;
00091 template <typename T> class CArray<T,0>;
00092 template <typename T, std::size_t N> class CArrayPOD;
00093 template <typename T, std::size_t N> class CArrayNumeric;
00094
00095 class BASE_IMPEXP CMatrix;
00096 class BASE_IMPEXP CMatrixD;
00097
00098
00099
00100
00101 #define DECLARE_COMMON_CONTAINERS_MEMBERS(NUMTYPE) \
00102 \
00103 \
00104 inline size_t countNonZero() const { return mrpt::math::countNonZero(*this); } \
00105 \
00106 inline void fill(const NUMTYPE &val) { std::fill(mrpt_autotype::begin(),mrpt_autotype::end(),val); } \
00107 \
00108 inline NUMTYPE maximum(size_t *maxIndex = NULL) const { return mrpt::math::maximum(*this,maxIndex); } \
00109 \
00110 inline NUMTYPE minimum(size_t *minIndex = NULL) const { return mrpt::math::minimum(*this,minIndex ); } \
00111 \
00112 inline void minimum_maximum(NUMTYPE &out_min, NUMTYPE &out_max, \
00113 size_t *minIndex = NULL, size_t *maxIndex = NULL) const \
00114 { mrpt::math::minimum_maximum(*this,out_min,out_max,minIndex,maxIndex); } \
00115 \
00116 inline NUMTYPE norm_inf(size_t *maxIndex = NULL) const { return mrpt::math::norm_inf(*this,maxIndex); } \
00117 \
00118 inline NUMTYPE sumAll() const { return mrpt::math::sum(*this); } \
00119 \
00120 template <typename RET_TYPE> inline RET_TYPE sumAllRetType() const { return mrpt::math::sumRetType<mrpt_autotype,NUMTYPE>(*this); } \
00121 \
00122 template <class CONTAINEROUT> inline void cumsum(CONTAINEROUT &out) const { mrpt::math::cumsum(*this,out); } \
00123 \
00124 template <class CONTAINEROUT> inline CONTAINEROUT cumsum() const { CONTAINEROUT o; mrpt::math::cumsum(*this,o); return o;} \
00125 \
00126 template <class CONTAINER2> inline size_t countCommonElements(const CONTAINER2 &b) const { return mrpt::math::countCommonElements(*this,b); } \
00127 \
00128 inline std::vector<double> histogram(double limit_min,double limit_max,size_t number_bins,bool do_normalization = false ) const { \
00129 return mrpt::math::histogram(*this,limit_min,limit_max,number_bins,do_normalization); } \
00130 \
00131 template <class F> mrpt_autotype & applyToAllElements( NUMTYPE (*function)(NUMTYPE) ) { \
00132 std::for_each(this->begin(),this->end(), function); \
00133 return *this; } \
00134 inline mrpt_autotype & Sqrt() { for (typename mrpt_autotype::iterator it=this->begin();it!=this->end();++it) *it = ::sqrt(*it); return *this; } \
00135 inline mrpt_autotype & Abs() { for (typename mrpt_autotype::iterator it=this->begin();it!=this->end();++it) *it = ::fabs(*it); return *this; } \
00136 inline mrpt_autotype & Square() { for (typename mrpt_autotype::iterator it=this->begin();it!=this->end();++it) *it = mrpt::utils::square(*it); return *this; } \
00137 inline mrpt_autotype & Exp() { for (typename mrpt_autotype::iterator it=this->begin();it!=this->end();++it) *it = ::exp(*it); return *this; } \
00138 inline mrpt_autotype & Log() { for (typename mrpt_autotype::iterator it=this->begin();it!=this->end();++it) *it = ::log(*it); return *this; } \
00139 \
00140 inline NUMTYPE squareNorm() const { return mrpt::math::squareNorm(*this); } \
00141 \
00142 inline NUMTYPE norm() const { return mrpt::math::norm(*this); } \
00143 \
00144 inline double mean() const { return mrpt::math::mean(*this); } \
00145 inline void adjustRange(const NUMTYPE min_val,const NUMTYPE max_val) { mrpt::math::adjustRange(*this,min_val,max_val); } \
00146 inline void normalize(const NUMTYPE min_val=0,const NUMTYPE max_val=1) { mrpt::math::adjustRange(*this,min_val,max_val); } \
00147 inline double std(bool unbiased=true) const { return mrpt::math::stddev(*this); } \
00148 void meanAndStd(double &out_mean, double &out_std, bool unbiased = true) { \
00149 return mrpt::math::meanAndStd(*this,out_mean,out_std,unbiased); } \
00150
00151
00152
00153
00154 #define DECLARE_COMMON_MATRIX_MEMBERS(NUMTYPE) \
00155 DECLARE_COMMON_CONTAINERS_MEMBERS(NUMTYPE) \
00156 \
00157 \
00158 inline mrpt_autotype operator+() {\
00159 return *this;\
00160 }\
00161 inline mrpt_autotype operator-() const {\
00162 mrpt_autotype res(*this);\
00163 for (size_t i=0;i<mrpt_autotype::getRowCount();++i) for (size_t j=0;j<mrpt_autotype::getColCount();++j) res.set_unsafe(i,j,-res.get_unsafe(i,j));\
00164 return res;\
00165 }\
00166 mrpt_autotype &operator+=(const NUMTYPE n) {\
00167 for (size_t i=0;i<mrpt_autotype::getRowCount();++i) for (size_t j=0;j<mrpt_autotype::getColCount();++j) mrpt_autotype::get_unsafe(i,j)+=n;\
00168 return *this;\
00169 }\
00170 mrpt_autotype &operator-=(const NUMTYPE n) {\
00171 for (size_t i=0;i<mrpt_autotype::getRowCount();++i) for (size_t j=0;j<mrpt_autotype::getColCount();++j) mrpt_autotype::get_unsafe(i,j)-=n;\
00172 return *this;\
00173 }\
00174 mrpt_autotype &operator*=(const NUMTYPE n) {\
00175 for (size_t i=0;i<mrpt_autotype::getRowCount();++i) for (size_t j=0;j<mrpt_autotype::getColCount();++j) mrpt_autotype::get_unsafe(i,j)*=n;\
00176 return *this;\
00177 }\
00178 inline mrpt_autotype& operator/=(const NUMTYPE n) {\
00179 return (*this)*=NUMTYPE(1)/n; } \
00180 template<typename OTHERMATRIX> \
00181 inline RET_VOID_ASSERT_MRPTMATRIX(OTHERMATRIX) operator*=(const OTHERMATRIX &m) {\
00182 mrpt::math::detail::multiply_AB(*this,m,*this); } \
00183 template<typename OTHERMATRIX> mrpt_autotype &add_At(const OTHERMATRIX &m) {\
00184 ASSERT_((m.getRowCount()==mrpt_autotype::getColCount())&&(m.getColCount()==mrpt_autotype::getRowCount()));\
00185 for (size_t i=0;i<mrpt_autotype::getRowCount();++i) for (size_t j=0;j<mrpt_autotype::getColCount();++j) mrpt_autotype::get_unsafe(i,j)+=m.get_unsafe(j,i);\
00186 return *this;\
00187 }\
00188 template<typename OTHERMATRIX> mrpt_autotype &add_Ac(const OTHERMATRIX &m,const NUMTYPE c) {\
00189 ASSERT_((m.getRowCount()==mrpt_autotype::getRowCount())&&(m.getColCount()==mrpt_autotype::getColCount()));\
00190 for (size_t i=0;i<mrpt_autotype::getRowCount();++i) for (size_t j=0;j<mrpt_autotype::getColCount();++j) mrpt_autotype::get_unsafe(i,j)+=c*m.get_unsafe(i,j);\
00191 return *this;\
00192 }\
00193 template<typename OTHERMATRIX> mrpt_autotype &substract_At(const OTHERMATRIX &m) {\
00194 ASSERT_((m.getRowCount()==mrpt_autotype::getColCount())&&(m.getColCount()==mrpt_autotype::getRowCount()));\
00195 for (size_t i=0;i<mrpt_autotype::getRowCount();++i) for (size_t j=0;j<mrpt_autotype::getColCount();++j) mrpt_autotype::get_unsafe(i,j)-=m.get_unsafe(j,i);\
00196 return *this;\
00197 } \
00198 \
00199 template<typename OTHERMATRIX> mrpt_autotype & substract_An(const OTHERMATRIX& m, const size_t n) {\
00200 ASSERT_((m.getRowCount()==mrpt_autotype::getRowCount())&&(m.getColCount()==mrpt_autotype::getColCount()));\
00201 for (size_t i=0;i<mrpt_autotype::getRowCount();++i) for (size_t j=0;j<mrpt_autotype::getColCount();++j) mrpt_autotype::get_unsafe(i,j)-=n*m.get_unsafe(i,j);\
00202 return *this;\
00203 }\
00204 \
00205 template<typename OTHERMATRIX> mrpt_autotype &substract_Ac(const OTHERMATRIX &m,const NUMTYPE c) {\
00206 ASSERT_((m.getRowCount()==mrpt_autotype::getRowCount())&&(m.getColCount()==mrpt_autotype::getColCount()));\
00207 for (size_t i=0;i<mrpt_autotype::getRowCount();++i) for (size_t j=0;j<mrpt_autotype::getColCount();++j) mrpt_autotype::get_unsafe(i,j)-=c*m.get_unsafe(i,j);\
00208 return *this;\
00209 }\
00210 \
00211 template<typename OTHERMATRIX> mrpt_autotype &add_AAt(const OTHERMATRIX &m) {\
00212 ASSERT_((mrpt_autotype::getRowCount()==mrpt_autotype::getColCount())&&(mrpt_autotype::getRowCount()==m.getRowCount())&&(mrpt_autotype::getColCount()==m.getColCount()));\
00213 for (size_t i=0;i<mrpt_autotype::getRowCount();++i) for (size_t j=0;j<mrpt_autotype::getColCount();++j) mrpt_autotype::get_unsafe(i,j)+=m.get_unsafe(i,j)+m.get_unsafe(j,i);\
00214 return *this;\
00215 }\
00216 \
00217 template<typename OTHERMATRIX> mrpt_autotype &substract_AAt(const OTHERMATRIX &m) {\
00218 ASSERT_((mrpt_autotype::getRowCount()==mrpt_autotype::getColCount())&&(mrpt_autotype::getRowCount()==m.getRowCount())&&(mrpt_autotype::getColCount()==m.getColCount()));\
00219 for (size_t i=0;i<mrpt_autotype::getRowCount();++i) for (size_t j=0;j<mrpt_autotype::getColCount();++j) mrpt_autotype::get_unsafe(i,j)-=m.get_unsafe(i,j)+m.get_unsafe(j,i);\
00220 return *this;\
00221 }\
00222 \
00223 bool empty() const { return this->getColCount()==0 || this->getRowCount()==0; } \
00224 template <class MATRIX1,class MATRIX2> \
00225 inline void multiply( const MATRIX1& A, const MATRIX2 &B ) { mrpt::math::detail::multiply_AB(A,B,*this); } \
00226 template <class MATRIX1,class MATRIX2> \
00227 inline void multiply_AB( const MATRIX1& A, const MATRIX2 &B ) { mrpt::math::detail::multiply_AB(A,B,*this); } \
00228 \
00229 template<typename OTHERVECTOR1,typename OTHERVECTOR2> \
00230 inline void multiply_Ab(const OTHERVECTOR1 &vIn,OTHERVECTOR2 &vOut,bool accumToOutput = false) const {\
00231 mrpt::math::detail::multiply_Ab(*this,vIn,vOut,accumToOutput); } \
00232 \
00233 template<typename OTHERVECTOR1,typename OTHERVECTOR2> \
00234 inline void multiply_Atb(const OTHERVECTOR1 &vIn,OTHERVECTOR2 &vOut,bool accumToOutput = false) const {\
00235 mrpt::math::detail::multiply_Atb(*this,vIn,vOut,accumToOutput); } \
00236 template <typename MAT_C, typename MAT_R> \
00237 inline void multiply_HCHt(const MAT_C &C,MAT_R &R,bool accumResultInOutput=false,bool allow_submatrix_mult=false) const { \
00238 mrpt::math::detail::multiply_HCHt(*this,C,R,accumResultInOutput,allow_submatrix_mult); } \
00239 \
00240 template <typename MAT_C> NUMTYPE multiply_HCHt_scalar(const MAT_C &C) const { return mrpt::math::detail::multiply_HCHt_scalar(*this,C); } \
00241 \
00242 template <typename MAT_C> NUMTYPE multiply_HtCH_scalar(const MAT_C &C) const { return mrpt::math::detail::multiply_HCHt_scalar(*this,C); } \
00243 \
00244 template <typename MAT_C, typename MAT_R> \
00245 inline void multiply_HtCH(const MAT_C &C,MAT_R &R,bool accumResultInOutput=false,bool allow_submatrix_mult=false) const { \
00246 mrpt::math::detail::multiply_HtCH(*this,C,R,accumResultInOutput,allow_submatrix_mult); } \
00247 template <class MAT_A,class MAT_OUT> \
00248 inline void multiply_subMatrix(const MAT_A &A,MAT_OUT &outResult,const size_t A_cols_offset,const size_t A_rows_offset,const size_t A_col_count) const { \
00249 mrpt::math::detail::multiply_subMatrix(*this,A,outResult,A_cols_offset,A_rows_offset,A_col_count); } \
00250 template <class MAT_A,class MAT_B,class MAT_C> \
00251 void multiply_ABC(const MAT_A &A, const MAT_B &B, const MAT_C &C) { \
00252 mrpt::math::detail::multiply_ABC(A,B,C, *this); } \
00253 template <class MAT_A,class MAT_B,class MAT_C> \
00254 void multiply_ABCt(const MAT_A &A, const MAT_B &B, const MAT_C &C) { \
00255 mrpt::math::detail::multiply_ABCt(A,B,C, *this); } \
00256 template <class MAT_A,class MAT_B> \
00257 inline void multiply_ABt(const MAT_A &A,const MAT_B &B) { \
00258 mrpt::math::detail::multiply_ABt(A,B,*this); } \
00259 template <class MAT_A> \
00260 inline void multiply_AAt(const MAT_A &A) { \
00261 mrpt::math::detail::multiply_AAt(A,*this); } \
00262 template <class MAT_A> \
00263 inline void multiply_AtA(const MAT_A &A) { \
00264 mrpt::math::detail::multiply_AtA(A,*this); } \
00265 template <class MAT_A,class MAT_B> \
00266 inline void multiply_result_is_symmetric(const MAT_A &A,const MAT_B &B) { \
00267 mrpt::math::detail::multiply_result_is_symmetric(A,B,*this); } \
00268 \
00269 \
00270 template<typename OTHERMATRIX> inline mrpt_autotype &assignMatrix(const OTHERMATRIX &m) {\
00271 setSize(m.getRowCount(),m.getColCount());\
00272 for (size_t i=0;i<mrpt_autotype::getRowCount();++i) for (size_t j=0;j<mrpt_autotype::getColCount();++j) mrpt_autotype::set_unsafe(i,j,m.get_unsafe(i,j));\
00273 return *this;\
00274 }\
00275 \
00276 template<typename OTHERMATRIX> inline mrpt_autotype &assignMatrixTransposed(const OTHERMATRIX &m) {\
00277 setSize(m.getColCount(),m.getRowCount());\
00278 for (size_t i=0;i<m.getRowCount();++i) for (size_t j=0;j<m.getColCount();++j) set_unsafe(j,i,m.get_unsafe(i,j));\
00279 return *this;\
00280 }\
00281 \
00282 \
00283 inline mrpt_autotype & operator=( const TPose2D &p) { this->setSize(3,1); mrpt::math::containerFromPoseOrPoint(*this,p); return *this; } \
00284 inline mrpt_autotype & operator=( const TPose3D &p) { this->setSize(6,1); mrpt::math::containerFromPoseOrPoint(*this,p); return *this;} \
00285 inline mrpt_autotype & operator=( const TPose3DQuat &p) { this->setSize(7,1); mrpt::math::containerFromPoseOrPoint(*this,p); return *this;} \
00286 inline mrpt_autotype & operator=( const TPoint2D &p) { this->setSize(2,1); mrpt::math::containerFromPoseOrPoint(*this,p); return *this;} \
00287 inline mrpt_autotype & operator=( const TPoint3D &p) { this->setSize(3,1); mrpt::math::containerFromPoseOrPoint(*this,p); return *this;} \
00288 inline mrpt_autotype & operator=( const mrpt::poses::CPose2D &p) { this->setSize(3,1); mrpt::math::containerFromPoseOrPoint(*this,p); return *this;} \
00289 inline mrpt_autotype & operator=( const mrpt::poses::CPose3D &p) { this->setSize(6,1); mrpt::math::containerFromPoseOrPoint(*this,p); return *this;} \
00290 inline mrpt_autotype & operator=( const mrpt::poses::CPose3DQuat &p) { this->setSize(7,1); mrpt::math::containerFromPoseOrPoint(*this,p); return *this;} \
00291 inline mrpt_autotype & operator=( const mrpt::poses::CPoint2D &p) { this->setSize(2,1); mrpt::math::containerFromPoseOrPoint(*this,p); return *this;} \
00292 inline mrpt_autotype & operator=( const mrpt::poses::CPoint3D &p) { this->setSize(3,1); mrpt::math::containerFromPoseOrPoint(*this,p); return *this;} \
00293 \
00294 \
00295 inline NUMTYPE _E(const size_t row, const size_t col) const { return mrpt_autotype::get_unsafe(row-1,col-1); } \
00296 \
00297 inline NUMTYPE & _E(const size_t row, const size_t col) { return mrpt_autotype::get_unsafe(row-1,col-1); } \
00298 \
00299 inline NUMTYPE _A(const size_t n) const { return mrpt_autotype::get_unsafe(n/mrpt_autotype::getColCount(),n%mrpt_autotype::getColCount()); } \
00300 \
00301 inline NUMTYPE &_A(const size_t n) { return mrpt_autotype::get_unsafe(n/mrpt_autotype::getColCount(),n%mrpt_autotype::getColCount()); } \
00302 inline bool IsSquare() const { return mrpt_autotype::getColCount()==mrpt_autotype::getRowCount(); } \
00303 inline bool isSquare() const { return mrpt_autotype::getColCount()==mrpt_autotype::getRowCount(); } \
00304 \
00305 inline bool isSingular(const NUMTYPE epsilon=0) const { \
00306 if (!isSquare()) return false; else return std::abs(this->det())<=epsilon; } \
00307 \
00308 inline NUMTYPE trace() const { return mrpt::math::detail::trace(*this); }\
00309 template <class MAT_OUT> \
00310 void pseudoInverse( MAT_OUT &out ) const { \
00311 mrpt_autotype A, Ainv; A.multiply_AtA(*this); A.inv_fast(Ainv); out.multiply_ABt(Ainv,*this); } \
00312 template <class MAT_OUT> \
00313 MAT_OUT pseudoInverse() const { \
00314 mrpt_autotype A, Ainv; A.multiply_AtA(*this); A.inv_fast(Ainv); \
00315 MAT_OUT out; out.multiply_ABt(Ainv,*this); return out; } \
00316 inline NUMTYPE det() const { return mrpt::math::detail::detMatrix(*this); } \
00317 template <class MATRIXOUT> inline void inv( MATRIXOUT& out ) const { mrpt::math::detail::invMatrix(*this,out); } \
00318 inline mrpt_autotype inv() const { mrpt_autotype ret; mrpt::math::detail::invMatrix(*this,ret); return ret; } \
00319 template <class MATRIXOUT> inline void inv_fast( MATRIXOUT& out ) { mrpt::math::detail::invMatrix_destroySrc(*this,out); } \
00320 \
00321 template <class MAT2,class MAT3> inline void leftDivideSquare(const MAT2 &A,MAT3 &RES) const { mrpt::math::detail::leftDivideSquare(*this,A,RES); } \
00322 \
00323 template <class MAT2,class MAT3> inline void rightDivideSquare(const MAT2 &B, MAT3 &RES) const { mrpt::math::detail::rightDivideSquare(*this,B,RES); } \
00324 \
00325 template <typename MAT2> inline void fastLeftDivideSquare(MAT2 &A) { mrpt::math::detail::fastLeftDivideSquare(*this,A); } \
00326 \
00327 template <typename MAT2> inline void fastRightDivideSquare(MAT2 &B) { mrpt::math::detail::fastRightDivideSquare(*this,B); } \
00328 \
00329 inline void saveToTextFile(const std::string &file,mrpt::math::TMatrixTextFileFormat fileFormat = MATRIX_FORMAT_ENG,bool appendMRPTHeader=false,const std::string &userHeader = std::string("") ) const { \
00330 mrpt::math::detail::saveMatrixToTextFile(*this, file,fileFormat,appendMRPTHeader,userHeader); } \
00331 \
00332 inline std::string inMatlabFormat(const size_t decimal_digits=6) const { return detail::matrix_inMatlabFormat(*this,decimal_digits); } \
00333 inline int pivot(const size_t row) { return mrpt::math::detail::matrix_pivot(*this,row); } \
00334 \
00335 \
00336 template <class MATRIXOUT> inline bool chol(MATRIXOUT &out) const { return mrpt::math::detail::chol(*this,out); } \
00337 \
00338 template <class MATRIX1,class MATRIX2> \
00339 inline RET_VOID_ASSERT_MRPTMATRICES(MATRIX1,MATRIX2) eigenVectors( MATRIX1& eVecs, MATRIX2& eVals) const { \
00340 ARRAY_TYPE_SAMESIZE_ROWS_OF(mrpt_autotype) eigVals; \
00341 eigVals.resize(this->getRowCount()); \
00342 mrpt::math::detail::eigenVectorsMatrix(*this, &eVecs,eigVals); \
00343 const size_t n = eigVals.size(); \
00344 eVals.zeros(n,n); for (size_t i=0;i<n;i++) eVals.get_unsafe(i,i)=eigVals[i]; \
00345 } \
00346 \
00347 template <class MATRIX1,class VECTOR1> \
00348 inline void eigenVectorsVec( MATRIX1& eVecs, VECTOR1& eVals) const { mrpt::math::detail::eigenVectorsMatrix(*this, &eVecs,eVals); } \
00349 \
00350 template <class VECTOR1> \
00351 inline void eigenValues( VECTOR1& eVals) const { mrpt::math::detail::eigenVectorsMatrix(*this,static_cast<const mrpt_autotype*>(NULL),eVals); } \
00352 inline void setIdentity() {\
00353 ASSERT_(isSquare());\
00354 set_unsafe(0,0,NUMTYPE(1));\
00355 for (size_t i=1;i<mrpt_autotype::getRowCount();++i) {\
00356 set_unsafe(i,i,NUMTYPE(1));\
00357 for (size_t j=0;j<i;++j) {\
00358 set_unsafe(i,j,NUMTYPE(0));\
00359 set_unsafe(j,i,NUMTYPE(0));\
00360 }\
00361 }\
00362 }\
00363 inline void setIdentity(size_t N) {\
00364 setSize(N,N);\
00365 setIdentity();\
00366 }\
00367 inline size_t rank(NUMTYPE eps=1e-7) const {\
00368 return mrpt::math::detail::rank(*this,eps);\
00369 }\
00370 \
00371 template <class MATRIXLIKE> inline void insertMatrix(const size_t nRow, const size_t nCol, const MATRIXLIKE &in) \
00372 { detail::insertMatrixInto(*this,nRow,nCol,in); } \
00373 \
00374 template <class MATRIXLIKE> inline void insertMatrixTranspose(const size_t nRow, const size_t nCol, const MATRIXLIKE &in) \
00375 { detail::insertMatrixTransposeInto(*this,nRow,nCol,in); } \
00376 \
00377 template <class MATOUT> inline void extractMatrix(const size_t first_row, const size_t first_col, MATOUT &outMat) const { detail::extractMatrix(*this,first_row,first_col,outMat); } \
00378 \
00379 template <class MATOUT> inline void extractMatrix(const size_t first_row, const size_t first_col, const size_t nRows, const size_t nCols, MATOUT &outMat) const { outMat.setSize(nRows,nCols); detail::extractMatrix(*this,first_row,first_col,outMat); } \
00380 template <class VECLIKE> inline void extractRow(const size_t nRow, VECLIKE &out, const size_t startingCol = 0) const { detail::extractRowFromMatrix(*this,nRow,out,startingCol); } \
00381 template <class VECLIKE> inline void extractCol(const size_t nCol, VECLIKE &out, const size_t startingRow = 0) const { detail::extractColFromMatrix(*this,nCol,out,startingRow); } \
00382 template <class VECLIKE> inline void insertRow(const size_t nRow, VECLIKE &in, const size_t startingCol = 0) { detail::insertRowToMatrix(*this,nRow,in,startingCol); } \
00383 template <class VECLIKE> inline void insertCol(const size_t nCol, VECLIKE &in, const size_t startingRow = 0) { detail::insertColToMatrix(*this,nCol,in,startingRow); } \
00384
00385
00386
00387
00388 namespace detail
00389 {
00390 template<class MATRIX1,class MATRIX2>
00391 bool chol(const MATRIX1 &in, MATRIX2 &out);
00392 template<class MATRIX1>
00393 typename MATRIX1::value_type trace(const MATRIX1 &m);
00394
00395 template <class MATRIX1,class MATRIX2,class MATRIXRES>
00396 void multiply_AB(const MATRIX1& m1,const MATRIX2& m2, MATRIXRES& RESULT );
00397 template<class MATRIX1, class OTHERVECTOR1,class OTHERVECTOR2>
00398 void multiply_Ab(const MATRIX1 &m, const OTHERVECTOR1 &vIn,OTHERVECTOR2 &vOut,bool accumToOutput );
00399 template<class MATRIX1, class OTHERVECTOR1,class OTHERVECTOR2>
00400 void multiply_Atb(const MATRIX1 &m, const OTHERVECTOR1 &vIn,OTHERVECTOR2 &vOut,bool accumToOutput );
00401 template <class MATRIX1,class MATRIX2>
00402 void multiply_AAt( const MATRIX1& m1, MATRIX2& RESULT );
00403 template <class MATRIX1,class MATRIX2>
00404 void multiply_AtA( const MATRIX1& m1, MATRIX2& RESULT );
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417 template <typename MAT_H, typename MAT_C, typename MAT_R>
00418 void multiply_HCHt(const MAT_H &H,const MAT_C &C,MAT_R &R,bool accumResultInOutput=false,bool allow_submatrix_mult=false);
00419 template <typename MAT_H, typename MAT_C, typename MAT_R>
00420 void multiply_HtCH(const MAT_H &H,const MAT_C &C,MAT_R &R,bool accumResultInOutput=false,bool allow_submatrix_mult=false);
00421 template <typename VECTOR_H, typename MAT_C> typename MAT_C::value_type
00422 multiply_HCHt_scalar(const VECTOR_H &H, const MAT_C &C);
00423
00424 template <class MAT_X,class MAT_A,class MAT_OUT>
00425 void multiply_subMatrix(const MAT_X &X,const MAT_A &A,MAT_OUT &outResult,const size_t A_cols_offset,const size_t A_rows_offset,const size_t A_col_count);
00426
00427 template <class MAT_A,class MAT_B,class MAT_C,class MAT_OUT>
00428 void multiply_ABC(const MAT_A &A, const MAT_B &B, const MAT_C &C, MAT_OUT & RES);
00429 template <class MAT_A,class MAT_B,class MAT_C,class MAT_OUT>
00430 void multiply_ABCt(const MAT_A &A, const MAT_B &B, const MAT_C &C, MAT_OUT & RES);
00431
00432 template <class MAT_A,class MAT_B,class MAT_OUT>
00433 void multiply_ABt(const MAT_A &A,const MAT_B &B, MAT_OUT &out);
00434 template <class MAT_A,class MAT_OUT>
00435 void multiply_AAt(const MAT_A &A, MAT_OUT &out);
00436 template <class MAT_A,class MAT_OUT>
00437 void multiply_AAt(const MAT_A &A,MAT_OUT &out);
00438 template <class MAT_A,class MAT_B,class MAT_OUT>
00439 void multiply_result_is_symmetric(const MAT_A &A,const MAT_B &B, MAT_OUT &out);
00440
00441
00442 template<typename MatrixType> size_t rank(const MatrixType &m,typename MatrixType::value_type eps=1e-7);
00443
00444
00445 template <class MATRIXIN,class MATRIXOUT> inline void invMatrix( const MATRIXIN &M, MATRIXOUT &out_inv );
00446 template <class MATRIXIN,class MATRIXOUT> inline void invMatrix_destroySrc( MATRIXIN &M, MATRIXOUT &out_inv );
00447
00448
00449
00450 template <class MATRIXIN,class MATRIXOUT> inline void invMatrix_special_2x2( const MATRIXIN &M, MATRIXOUT &out_inv );
00451 template <class MATRIXIN,class MATRIXOUT> inline void invMatrix_special_3x3( const MATRIXIN &M, MATRIXOUT &out_inv );
00452
00453
00454
00455 template <class MATRIX> RET_ELEMENT_ASSERT_MRPTCONTAINER(MATRIX)
00456 detMatrix(const MATRIX& M);
00457
00458
00459
00460 template <class MATRIX> inline typename MATRIX::value_type detMatrix_special_2x2(const MATRIX &M);
00461 template <class MATRIX> inline typename MATRIX::value_type detMatrix_special_3x3(const MATRIX &M);
00462 template <class MATRIX> typename MATRIX::value_type detMatrix_special_4x4(const MATRIX &M);
00463
00464
00465
00466 template <class MATRIX1,class MATRIX2,class VECTOR1> void
00467 eigenVectorsMatrix(const MATRIX1 &M,MATRIX2 *eVecs,VECTOR1 &eVals );
00468
00469
00470 template <class MATRIX1,class MATRIX2,class VECTOR1> void eigenVectorsMatrix_special_2x2(const MATRIX1 &M,MATRIX2 *eVecs,VECTOR1 &eVals );
00471
00472
00473 template <> inline void eigenVectorsMatrix<CMatrixFixedNumeric<float,2,2>,CMatrixFixedNumeric<float,2,2>,CArrayNumeric<float,2> >(const CMatrixFixedNumeric<float,2,2> &M,CMatrixFixedNumeric<float,2,2> *eVecs,CArrayNumeric<float,2> &eVals ) { eigenVectorsMatrix_special_2x2(M,eVecs,eVals); }
00474 template <> inline void eigenVectorsMatrix<CMatrixFixedNumeric<double,2,2>,CMatrixFixedNumeric<double,2,2>,CArrayNumeric<double,2> >(const CMatrixFixedNumeric<double,2,2> &M,CMatrixFixedNumeric<double,2,2> *eVecs,CArrayNumeric<double,2> &eVals ) { eigenVectorsMatrix_special_2x2(M,eVecs,eVals); }
00475
00476
00477 template <class MAT> void
00478 saveMatrixToTextFile(const MAT &theMatrix, const std::string &file, TMatrixTextFileFormat fileFormat = MATRIX_FORMAT_ENG, bool appendMRPTHeader = false, const std::string &userHeader = std::string("") );
00479 template <class MATRIX>
00480 std::string matrix_inMatlabFormat(const MATRIX &m,const size_t decimal_digits);
00481
00482 template <typename T,size_t NROWS,size_t NCOLS> void fixedToDynMatrix( const CMatrixFixedNumeric<T,NROWS,NCOLS> &SRC, CMatrixTemplateNumeric<T> &DST);
00483 template <class MAT1,class MAT2> void insertMatrixInto( MAT1 &M,const size_t nRow,const size_t nCol,const MAT2 &in);
00484 template <class MAT1,class MAT2> void insertMatrixTransposeInto( MAT1 &M,const size_t nRow,const size_t nCol,const MAT2 &in);
00485
00486 template <class MATORG, class MATDEST> void extractMatrix(const MATORG &origin,const size_t first_row,const size_t first_col, MATDEST &out_subMatrix);
00487 template <class MAT,class VEC> void extractRowFromMatrix(const MAT &m, size_t nRow, VEC &out, const size_t startingCol);
00488 template <class MAT,class VEC> void extractColFromMatrix(const MAT &m, size_t nCol, VEC &out, const size_t startingRow);
00489 template <class MAT,class VEC> void insertRowToMatrix(MAT &m, size_t nRow, const VEC &in, const size_t startingCol);
00490 template <class MAT,class VEC> void insertColToMatrix(MAT &m, size_t nCol, const VEC &in, const size_t startingRow);
00491
00492 template <class MATRIX> int matrix_pivot(MATRIX &M, const size_t row);
00493
00494 template <typename MAT1,typename MAT2,typename MAT3> inline void leftDivideSquare(const MAT1 &C,const MAT2 &A,MAT3 &RES);
00495 template <typename MAT1,typename MAT2,typename MAT3> inline void rightDivideSquare(const MAT1 &C,const MAT2 &B, MAT3 &RES);
00496 template <typename MAT1,typename MAT2> inline void fastLeftDivideSquare(MAT1 &inout_CB,MAT2 &willBeDestroyed_A);
00497 template <typename MAT1,typename MAT2> inline void fastRightDivideSquare(MAT1 &inout_CA,MAT2 &willBeDestroyed_B);
00498
00499
00500
00501 template <class MATRIX> inline bool isMatrixTypeResizable(const MATRIX&) { return false; }
00502
00503
00504
00505
00506 TPoint2D BASE_IMPEXP lightFromPose(const mrpt::poses::CPoint2D &p);
00507 TPoint3D BASE_IMPEXP lightFromPose(const mrpt::poses::CPoint3D &p);
00508 TPose2D BASE_IMPEXP lightFromPose(const mrpt::poses::CPose2D &p);
00509 TPose3D BASE_IMPEXP lightFromPose(const mrpt::poses::CPose3D &p);
00510 TPose3DQuat BASE_IMPEXP lightFromPose(const mrpt::poses::CPose3DQuat &p);
00511
00512 }
00513
00514
00515
00516
00517 template <class CONTAINER> size_t countNonZero(const CONTAINER &a);
00518 template <class CONTAINER> typename CONTAINER::value_type maximum(const CONTAINER &v, size_t *maxIndex = NULL);
00519 template <class CONTAINER> typename CONTAINER::value_type minimum(const CONTAINER &v, size_t *minIndex = NULL);
00520 template <class CONTAINER> void minimum_maximum(const CONTAINER &v,typename CONTAINER::mrpt_autotype::value_type & out_min,typename CONTAINER::mrpt_autotype::value_type& out_max,size_t *minIndex = static_cast<size_t*>(NULL), size_t *maxIndex = static_cast<size_t*>(NULL));
00521 template <class CONTAINER> typename CONTAINER::value_type norm_inf(const CONTAINER &v, size_t *maxIndex = NULL);
00522 template <class CONTAINER> typename CONTAINER::value_type squareNorm(const CONTAINER &v);
00523 template <class CONTAINER> inline typename CONTAINER::value_type norm(const CONTAINER &v);
00524 template <class CONTAINER> inline double mean(const CONTAINER &v);
00525 template <class CONTAINER> inline typename CONTAINER::value_type sum(const CONTAINER &v);
00526 template <class CONTAINER,typename RET> inline RET sumRetType(const CONTAINER &v);
00527 template <class CONTAINER> void adjustRange(CONTAINER &m, const typename CONTAINER::value_type minVal,const typename CONTAINER::value_type maxVal);
00528 template <class CONTAINER1,class CONTAINER2> void cumsum(const CONTAINER1 &in_data, CONTAINER2 &out_cumsum);
00529 template <class CONTAINER1,class CONTAINER2> size_t countCommonElements(const CONTAINER1 &a,const CONTAINER2 &b);
00530 template <class CONTAINER> std::vector<double> histogram(const CONTAINER &v,double limit_min,double limit_max,size_t number_bins,bool do_normalization=false, std::vector<double> *out_bin_centers=NULL);
00531 template<class VECTORLIKE> double stddev(const VECTORLIKE &v, bool unbiased=true);
00532 template<class VECTORLIKE> void meanAndStd(const VECTORLIKE &v,double &out_mean, double &out_std, bool unbiased = true);
00533
00534
00535 template <class CONTAINER> CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const TPoint2D &p);
00536 template <class CONTAINER> CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const TPoint3D &p);
00537 template <class CONTAINER> CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const TPose2D &p);
00538 template <class CONTAINER> CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const TPose3D &p);
00539 template <class CONTAINER> CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const TPose3DQuat &p);
00540
00541 template <class CONTAINER> inline CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const mrpt::poses::CPoint2D &p) { return containerFromPoseOrPoint(C, mrpt::math::detail::lightFromPose(p)); }
00542 template <class CONTAINER> inline CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const mrpt::poses::CPoint3D &p) { return containerFromPoseOrPoint(C, mrpt::math::detail::lightFromPose(p)); }
00543 template <class CONTAINER> inline CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const mrpt::poses::CPose2D &p) { return containerFromPoseOrPoint(C, mrpt::math::detail::lightFromPose(p)); }
00544 template <class CONTAINER> inline CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const mrpt::poses::CPose3D &p) { return containerFromPoseOrPoint(C, mrpt::math::detail::lightFromPose(p)); }
00545 template <class CONTAINER> inline CONTAINER & containerFromPoseOrPoint(CONTAINER &C, const mrpt::poses::CPose3DQuat &p) { return containerFromPoseOrPoint(C, mrpt::math::detail::lightFromPose(p)); }
00546
00547
00548
00549 namespace detail {
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559 template<typename T> class VicinityTraits;
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571 template<typename MatrixType,typename T,typename ReturnType,size_t D> struct getVicinity;
00572
00573 }
00574
00575
00576
00577 template <class T> T wrapTo2Pi(T a);
00578
00579
00580 }
00581 }
00582
00583 #endif