matrix_NEWMAT.cpp
Go to the documentation of this file.
00001 // $Id: matrix_NEWMAT.cpp 29884 2009-01-30 15:28:43Z tdelaet $
00002 // Copyright (C) 2002 Klaas Gadeyne <first dot last at gmail dot com>
00003 
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser General Public License as published by
00007 // the Free Software Foundation; either version 2.1 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 //
00019 
00020 #include "../config.h"
00021 #ifdef __MATRIXWRAPPER_NEWMAT__
00022 
00023 #include <iostream>
00024 #include "matrix_NEWMAT.h"
00025 #include <assert.h>
00026 
00027 
00028 // Passing the constructor arguments...
00029 MyMatrix::Matrix() : NewMatMatrix() {}
00030 MyMatrix::Matrix(int num_rows, int num_cols) : NewMatMatrix(num_rows,
00031                                                             num_cols){}
00032 
00033 // Destructor
00034 MyMatrix::~Matrix(){}
00035 
00036 // Copy constructor
00037 MyMatrix::Matrix(const MyMatrix& a) : NewMatMatrix(a){}
00038 
00039 // ill-designed
00040 MyMatrix::Matrix(const NewMatMatrix & a) : NewMatMatrix(a){}
00041 
00042 // Number of Rows/Cols
00043 unsigned int MyMatrix::rows() const { return this->Nrows();}
00044 unsigned int MyMatrix::columns() const { return this->Ncols();}
00045 
00046 // MATRIX - SCALAR operators
00047 MyMatrix& MyMatrix::operator+= (double a)
00048 {
00049   NewMatMatrix & op1 = (*this);
00050   op1 += a;
00051   return (MyMatrix&) op1;
00052 }
00053 
00054 MyMatrix& MyMatrix::operator-= (double a)
00055 {
00056   NewMatMatrix & op1 = (*this);
00057   op1 -= a;
00058   return (MyMatrix&) op1;
00059 }
00060 
00061 MyMatrix& MyMatrix::operator*= (double a)
00062 {
00063   NewMatMatrix & op1 = (*this);
00064   op1 *= a;
00065   return (MyMatrix&) op1;
00066 }
00067 
00068 MyMatrix& MyMatrix::operator/= (double a)
00069 {
00070   NewMatMatrix & op1 = (*this);
00071   op1 /= a;
00072   return (MyMatrix&) op1;
00073 }
00074 
00075 MyMatrix MyMatrix::operator+ (double a) const
00076 {
00077   // make copy
00078   NewMatMatrix op1 = (*this);
00079   op1 += a;
00080   return (MyMatrix&) op1;
00081 }
00082 
00083 MyMatrix MyMatrix::operator- (double a) const
00084 {
00085   // make copy
00086   NewMatMatrix op1 = (*this);
00087   op1 -= a;
00088   return (MyMatrix&) op1;
00089 }
00090 
00091 MyMatrix MyMatrix::operator* (double a) const
00092 {
00093   // make copy
00094   NewMatMatrix op1 = (*this);
00095   op1 *= a;
00096   return (MyMatrix&) op1;
00097 }
00098 
00099 MyMatrix MyMatrix::operator/ (double a) const
00100 {
00101   // make copy
00102   NewMatMatrix op1 = (*this);
00103   op1 /= a;
00104   return (MyMatrix&) op1;
00105 }
00106 
00107 MyMatrix&
00108 MyMatrix::operator =(const MySymmetricMatrix& a)
00109 {
00110   *this =(MyMatrix) a;
00111 
00112   return *this;
00113 }
00114 
00115 // MATRIX - MATRIX Operators
00116 MyMatrix MyMatrix::operator- (const MyMatrix& a) const
00117 {
00118   const NewMatMatrix& op1 = (*this);
00119   const NewMatMatrix& op2 = a;
00120   NewMatMatrix result = (NewMatMatrix) (op1 - op2);
00121   return (MyMatrix) result;
00122 }
00123 
00124 MyMatrix MyMatrix::operator+ (const MyMatrix& a) const
00125 {
00126   const NewMatMatrix& op1 = (*this);
00127   const NewMatMatrix& op2 = a;
00128   NewMatMatrix result = (NewMatMatrix) (op1 + op2);
00129   return (MyMatrix) result;
00130 }
00131 
00132 MyMatrix MyMatrix::operator* (const MyMatrix& a) const
00133 {
00134   const NewMatMatrix& op1 = (*this);
00135   const NewMatMatrix& op2 = a;
00136   NewMatMatrix result = (NewMatMatrix) (op1 * op2);
00137   return (MyMatrix) result;
00138 }
00139 
00140 MyMatrix & MyMatrix::operator+= (const MyMatrix& a)
00141 {
00142   NewMatMatrix & op1 = (*this);
00143   const NewMatMatrix & op2 = a;
00144   op1 += op2;
00145   return (MyMatrix &) op1;
00146 }
00147 
00148 MyMatrix & MyMatrix::operator-= (const MyMatrix& a)
00149 {
00150   NewMatMatrix & op1 = (*this);
00151   const NewMatMatrix & op2 = a;
00152   op1 -= op2;
00153   return (MyMatrix &) op1;
00154 }
00155 
00156 
00157 // MATRIX - VECTOR Operators
00158 MyColumnVector MyMatrix::operator* (const MyColumnVector &b) const
00159 {
00160   const NewMatMatrix& op1 = (*this);
00161   const NewMatColumnVector& op2 = b;
00162   return (MyColumnVector) (op1 * op2);
00163 }
00164 
00165 
00166 // Set all elements equal to a
00167 MyMatrix& MyMatrix::operator=(double a)
00168 {
00169   NewMatMatrix temp = (NewMatMatrix) *this;
00170   temp = a;
00171   *this = (MyMatrix) temp;
00172 
00173   return *this;
00174 }
00175 
00176 
00177 MyRowVector MyMatrix::rowCopy(unsigned int r) const
00178 {
00179   const NewMatMatrix& temp = (*this);
00180   return (MyRowVector) temp.Row(r);
00181 }
00182 
00183 MyColumnVector MyMatrix::columnCopy(unsigned int c) const
00184 {
00185   const NewMatMatrix& temp = (*this);
00186   return (MyColumnVector) temp.Column(c);
00187 }
00188 
00189 
00190 
00191 
00192 MyMatrix MyMatrix::transpose() const
00193 {
00194   const NewMatMatrix & base = (*this);
00195   NewMatMatrix transposedbase = base.t();
00196   return (MyMatrix) transposedbase;
00197 }
00198 
00199 double MyMatrix::determinant() const
00200 {
00201   const NewMatMatrix& base = (*this);
00202   NEWMAT::LogAndSign temp = base.LogDeterminant();
00203   double result = temp.Value();
00204   return result;
00205 }
00206 
00207 
00208 MyMatrix MyMatrix::inverse() const
00209 {
00210   const NewMatMatrix & base = (*this);
00211   NewMatMatrix inverted = base.i();
00212   return (MyMatrix) inverted;
00213 }
00214 
00215 
00216 int
00217 MyMatrix::convertToSymmetricMatrix(MySymmetricMatrix& sym)
00218 {
00219   // test if matrix is square matrix
00220   assert( this->rows() == this->columns() );
00221 
00222   // if necessairy, resize sym
00223   // only check cols or rows. Symmetric matrix is square.
00224   if ( sym.rows() != this->rows() )
00225     sym.ReSize(this->rows());
00226 
00227 
00228   // copy elements
00229   for ( unsigned int i=0; i<this->rows(); i++ )
00230     for ( unsigned int j=0; j<=i; j++ )
00231       sym(i+1,j+1) = (*this)(i+1,j+1);
00232   return 0;
00233 }
00234 
00235 void
00236 MyMatrix::resize(unsigned int i, unsigned int j, bool copy, bool initialize)
00237 {
00238   NewMatMatrix & temp = (NewMatMatrix &) (*this);
00239   temp.ReSize(i,j);
00240 }
00241 
00242 // get sub matrix
00243 MyMatrix MyMatrix::sub(int i_start, int i_end, int j_start , int j_end) const
00244 {
00245   assert(i_start >= 0 && i_start <= rows());
00246   assert(j_start >= 0 && j_start <= columns());
00247   assert(i_end   >= 0 && i_end   <= rows());
00248   assert(j_end   >= 0 && j_end   <= columns());
00249   assert(i_start <= i_end);
00250   assert(j_start <= j_end);
00251 
00252   return (MyMatrix)(this->SubMatrix(i_start, i_end, j_start, j_end));
00253 }
00254 
00255 
00256 
00258 // CLASS SYMMETRIC MATRIX  //
00260 
00261 MySymmetricMatrix::SymmetricMatrix() : NewMatSymmetricMatrix() {}
00262 MySymmetricMatrix::SymmetricMatrix(int n) : NewMatSymmetricMatrix(n) {}
00263 
00264 // Copy constructor
00265 MySymmetricMatrix::SymmetricMatrix(const SymmetricMatrix& a) : NewMatSymmetricMatrix(a){}
00266 MySymmetricMatrix::SymmetricMatrix(const NewMatSymmetricMatrix & a) : NewMatSymmetricMatrix(a){}
00267 
00268 // Destructor
00269 MySymmetricMatrix::~SymmetricMatrix(){}
00270 
00271 // Ask Number of Rows and Columns
00272 unsigned int MySymmetricMatrix::rows() const { return this->Nrows();}
00273 unsigned int MySymmetricMatrix::columns() const { return this->Ncols();}
00274 
00275 
00276 MySymmetricMatrix MySymmetricMatrix::transpose() const {return (*this);}
00277 
00278 MySymmetricMatrix MySymmetricMatrix::inverse() const
00279 {
00280   const NewMatSymmetricMatrix & base = (NewMatSymmetricMatrix &) *this;
00281   NewMatSymmetricMatrix inverted = base.i();
00282   return (MySymmetricMatrix) inverted;
00283 }
00284 
00285 double MySymmetricMatrix::determinant() const
00286 {
00287   const NewMatSymmetricMatrix & base = (NewMatSymmetricMatrix &) *this;
00288   NEWMAT::LogAndSign temp = base.LogDeterminant();
00289   double result = temp.Value();
00290   return result;
00291 }
00292 
00293 
00294 double& MyMatrix::operator()(unsigned int a, unsigned int b)
00295 {
00296   NewMatMatrix & op1(*this);
00297   return op1(a,b);
00298 }
00299 
00300 const double MyMatrix::operator()(unsigned int a, unsigned int b) const
00301 {
00302   const NewMatMatrix& op1(*this);
00303   return op1(a,b);
00304 }
00305 
00306 const bool MyMatrix::operator==(const MyMatrix& a) const
00307 {
00308   const NewMatMatrix& op1 = *this;
00309   const NewMatMatrix& op2 = a;
00310   return (op1 == op2);
00311 }
00312 
00313 // Set all elements equal to a
00314 MySymmetricMatrix& MySymmetricMatrix::operator=(const double a)
00315 {
00316   NewMatSymmetricMatrix temp = (NewMatSymmetricMatrix) *this;
00317   temp = a;
00318   *this = (MySymmetricMatrix) temp;
00319 
00320   return *this;
00321 }
00322 
00323 
00324 // SYMMETRICMATRIX - SCALAR operators
00325 MySymmetricMatrix& MySymmetricMatrix::operator +=(double a)
00326 {
00327   NewMatSymmetricMatrix & op1 = (*this);
00328   op1 += a;
00329   return (MySymmetricMatrix&) op1;
00330 }
00331 
00332 MySymmetricMatrix& MySymmetricMatrix::operator -=(double a)
00333 {
00334   NewMatSymmetricMatrix & op1 = (*this);
00335   op1 -= a;
00336   return (MySymmetricMatrix&) op1;
00337 }
00338 
00339 MySymmetricMatrix& MySymmetricMatrix::operator *=(double b)
00340 {
00341   NewMatSymmetricMatrix & op1 = (*this);
00342   op1 *= b;
00343   return (MySymmetricMatrix&) op1;
00344 }
00345 
00346 MySymmetricMatrix& MySymmetricMatrix::operator /=(double b)
00347 {
00348   NewMatSymmetricMatrix & op1 = (*this);
00349   op1 /= b;
00350   return (MySymmetricMatrix&) op1;
00351 }
00352 
00353 MySymmetricMatrix MySymmetricMatrix::operator +(double a) const
00354 {
00355   // make copy
00356   NewMatSymmetricMatrix op1 = (*this);
00357   op1 += a;
00358   return (MySymmetricMatrix) op1;
00359 }
00360 
00361 MySymmetricMatrix MySymmetricMatrix::operator -(double a) const
00362 {
00363   // make copy
00364   NewMatSymmetricMatrix op1 = (*this);
00365   op1 -= a;
00366   return (MySymmetricMatrix) op1;
00367 }
00368 
00369 MySymmetricMatrix MySymmetricMatrix::operator *(double b) const
00370 {
00371   // make copy
00372   NewMatSymmetricMatrix op1 = (*this);
00373   op1 *= b;
00374   return (MySymmetricMatrix) op1;
00375 }
00376 
00377 MySymmetricMatrix MySymmetricMatrix::operator /(double b) const
00378 {
00379   // make copy
00380   NewMatSymmetricMatrix op1 = (*this);
00381   op1 /= b;
00382   return (MySymmetricMatrix) op1;
00383 }
00384 
00385 
00386 
00387 
00388 // SYMMETRICMATRIX - MATRIX operators
00389 MyMatrix& MySymmetricMatrix::operator +=(const MyMatrix& a)
00390 {
00391   NewMatSymmetricMatrix & op1 = (*this);
00392   const NewMatMatrix & op2 = a;
00393   op1 += op2;
00394   return (MyMatrix &) op1;
00395 }
00396 
00397 MyMatrix& MySymmetricMatrix::operator -=(const MyMatrix& a)
00398 {
00399   NewMatSymmetricMatrix & op1 = (*this);
00400   const NewMatMatrix & op2 = a;
00401   op1 -= op2;
00402   return (MyMatrix &) op1;
00403 }
00404 
00405 
00406 MyMatrix MySymmetricMatrix::operator+ (const MyMatrix &a) const
00407 {
00408   const NewMatMatrix& op1 = (*this);
00409   const NewMatMatrix& op2 = a;
00410   NewMatMatrix result = (NewMatMatrix) (op1 + op2);
00411   return (MyMatrix) result;
00412 }
00413 
00414 MyMatrix MySymmetricMatrix::operator- (const MyMatrix &a) const
00415 {
00416   const NewMatMatrix& op1 = (*this);
00417   const NewMatMatrix& op2 = a;
00418   NewMatMatrix result = (NewMatMatrix) (op1 - op2);
00419   return (MyMatrix) result;
00420 }
00421 
00422 MyMatrix MySymmetricMatrix::operator* (const MyMatrix &a) const
00423 {
00424   const NewMatMatrix& op1 = (*this);
00425   const NewMatMatrix& op2 = a;
00426   NewMatMatrix result = (NewMatMatrix) (op1 * op2);
00427   return (MyMatrix) result;
00428 }
00429 
00430 
00431 
00432 // SYMMETRICMATRIX - SYMMETRICMATRIX operators
00433 MySymmetricMatrix& MySymmetricMatrix::operator +=(const MySymmetricMatrix& a)
00434 {
00435   NewMatSymmetricMatrix & op1 = (*this);
00436   const NewMatSymmetricMatrix & op2 = a;
00437   op1 += op2;
00438   return (MySymmetricMatrix &) op1;
00439 }
00440 
00441 MySymmetricMatrix& MySymmetricMatrix::operator -=(const MySymmetricMatrix& a)
00442 {
00443   NewMatSymmetricMatrix & op1 = (*this);
00444   const NewMatSymmetricMatrix & op2 = a;
00445   op1 -= op2;
00446   return (MySymmetricMatrix &) op1;
00447 }
00448 
00449 MySymmetricMatrix MySymmetricMatrix::operator+ (const MySymmetricMatrix &a) const
00450 {
00451   const NewMatSymmetricMatrix& op1 = (*this);
00452   const NewMatSymmetricMatrix& op2 = a;
00453   NewMatSymmetricMatrix result = (NewMatSymmetricMatrix) (op1 + op2);
00454   return (MySymmetricMatrix) result;
00455 }
00456 
00457 MySymmetricMatrix MySymmetricMatrix::operator- (const MySymmetricMatrix &a) const
00458 {
00459   const NewMatSymmetricMatrix& op1 = (*this);
00460   const NewMatSymmetricMatrix& op2 = a;
00461   NewMatSymmetricMatrix result = (NewMatSymmetricMatrix) (op1 - op2);
00462   return (MySymmetricMatrix) result;
00463 }
00464 
00465 MyMatrix MySymmetricMatrix::operator* (const MySymmetricMatrix &a) const
00466 {
00467   const NewMatSymmetricMatrix& op1 = (*this);
00468   const NewMatSymmetricMatrix& op2 = a;
00469   return (MyMatrix) (op1 * op2);
00470 }
00471 
00472 
00473 
00474 
00475 MyColumnVector MySymmetricMatrix::operator* (const MyColumnVector &b) const
00476 {
00477   const NewMatSymmetricMatrix& op1 = *this;
00478   const NewMatColumnVector& op2 = b;
00479   return (MyColumnVector) (op1 * op2);
00480 }
00481 
00482 void MySymmetricMatrix::multiply (const MyColumnVector &b, MyColumnVector &result) const
00483 {
00484   const NewMatSymmetricMatrix& op1 = *this;
00485   const NewMatColumnVector& op2 = b;
00486   result = (MyColumnVector) (op1 * op2);
00487 }
00488 
00489 MyMatrix MySymmetricMatrix::sub(int i_start, int i_end, int j_start , int j_end) const
00490 {
00491   return (MyMatrix)(this->SubMatrix(i_start, i_end, j_start, j_end));
00492 }
00493 
00494 
00495 void
00496 MySymmetricMatrix::resize(unsigned int i, bool copy, bool initialize)
00497 {
00498   NewMatSymmetricMatrix & temp = (NewMatSymmetricMatrix &) (*this);
00499   temp.ReSize(i);
00500 }
00501 
00502 
00503 
00504 double& MySymmetricMatrix::operator()(unsigned int a, unsigned int b)
00505 {
00506   NewMatSymmetricMatrix & op1 = (*this);
00507   return op1(a,b);
00508 }
00509 
00510 const double MySymmetricMatrix::operator()(unsigned int a, unsigned int b) const
00511 {
00512   const NewMatSymmetricMatrix op1(*this);
00513   return op1(a,b);
00514 }
00515 
00516 const bool MySymmetricMatrix::operator==(const MySymmetricMatrix& a) const
00517 {
00518   const NewMatSymmetricMatrix& op1 = *this;
00519   const NewMatSymmetricMatrix& op2 = a;
00520   return (op1 == op2);
00521 }
00522 
00523 
00524 #endif


bfl
Author(s): Klaas Gadeyne, Wim Meeussen, Tinne Delaet and many others. See web page for a full contributor list. ROS package maintained by Wim Meeussen.
autogenerated on Fri Aug 28 2015 10:10:21