vector_NEWMAT.cpp
Go to the documentation of this file.
00001 // $Id: vector_NEWMAT.cpp 29495 2008-08-13 12:57:49Z 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 "vector_NEWMAT.h"
00024 
00025 // Constructors
00026 MyColumnVector::ColumnVector() : NewMatColumnVector() {}
00027 MyColumnVector::ColumnVector(int num_rows) : NewMatColumnVector(num_rows){}
00028 MyColumnVector::ColumnVector(const MyColumnVector& a, const MyColumnVector& b) : NewMatColumnVector(a.rows() + b.rows())
00029 {
00030   NewMatColumnVector& opl = (*this);
00031 
00032   unsigned int i;
00033 
00034   // copy elements of a to opl
00035   for (i=0; i< a.rows(); i++)
00036     opl(i+1) = a(i+1);
00037 
00038   // copy elements of b to opl
00039   for (i=0; i< b.rows(); i++)
00040     opl(a.rows() + i+1) = b(i+1);
00041 }
00042 
00043 // Destructor
00044 MyColumnVector::~ColumnVector(){}
00045 
00046 // Copy constructor
00047 MyColumnVector::ColumnVector(const MyColumnVector& a) :
00048   NewMatColumnVector(a){}
00049 MyColumnVector::ColumnVector(const NewMatColumnVector & a) :
00050   NewMatColumnVector(a){}
00051 
00052 // Resizing
00053 void MyColumnVector::resize(int num_rows)
00054 {
00055   NewMatColumnVector & op1 = (*this);
00056   op1.ReSize(num_rows);
00057 }
00058 
00059 // Number of Rows / Cols
00060 unsigned int MyColumnVector::rows() const { return this->Nrows();}
00061 unsigned int MyColumnVector::columns() const { return this->Ncols();}
00062 
00063 MyColumnVector
00064 MyColumnVector::vectorAdd(const MyColumnVector& v2) const
00065 {
00066   const MyColumnVector& v1 = *this;
00067   MyColumnVector res(v1.rows() + v2.rows());
00068 
00069   for (unsigned int i=0; i<v1.rows(); i++)
00070     res(i+1) = v1(i+1);
00071 
00072   for (unsigned int i=0; i<v2.rows(); i++)
00073     res(v1.rows()+i+1) = v2(i+1);
00074 
00075   return res;
00076 }
00077 
00078 double& MyColumnVector::operator()(unsigned int i)
00079 {
00080   NewMatColumnVector& op1 = *(this);
00081   return op1(i);
00082 }
00083 
00084 const double MyColumnVector::operator()(unsigned int i) const
00085 {
00086   NewMatColumnVector op1 = (*this);
00087   return op1(i);
00088 }
00089 
00090 
00091 // Operators
00092 MyColumnVector & MyColumnVector::operator+= (const MyColumnVector& a)
00093 {
00094   NewMatColumnVector & op1 = (*this);
00095   const NewMatColumnVector & op2 = a;
00096   op1 += op2;
00097   return (MyColumnVector &) op1 ;
00098 }
00099 
00100 MyColumnVector & MyColumnVector::operator-= (const MyColumnVector& a)
00101 {
00102   NewMatColumnVector & op1 = (*this);
00103   const NewMatColumnVector & op2 = a;
00104   op1 -= op2;
00105   return (MyColumnVector &) op1 ;
00106 }
00107 
00108 MyColumnVector MyColumnVector::operator+ (const MyColumnVector &a) const
00109 {
00110   const NewMatColumnVector& op1 = (*this);
00111   const NewMatColumnVector & op2 = a;
00112   NewMatColumnVector result = (NewMatColumnVector) (op1 + op2);
00113   return (MyColumnVector) result;
00114 }
00115 
00116 MyColumnVector MyColumnVector::operator- (const MyColumnVector &a) const
00117 {
00118   const NewMatColumnVector & op1 = (*this);
00119   const NewMatColumnVector & op2 = a;
00120   NewMatColumnVector result = (NewMatColumnVector) (op1 - op2);
00121   return (MyColumnVector) result;
00122 }
00123 
00124 
00125 
00126 MyColumnVector& MyColumnVector::operator+= (double a)
00127 {
00128   NewMatColumnVector& op1 = *this;
00129   op1 += a;
00130   return (MyColumnVector&) op1;
00131 }
00132 
00133 MyColumnVector& MyColumnVector::operator-= (double a)
00134 {
00135   NewMatColumnVector& op1 = *this;
00136   op1 -= a;
00137   return (MyColumnVector&) op1;
00138 }
00139 
00140 MyColumnVector& MyColumnVector::operator*= (double a)
00141 {
00142   NewMatColumnVector& op1 = *this;
00143   op1 *= a;
00144   return (MyColumnVector&) op1;
00145 }
00146 
00147 MyColumnVector& MyColumnVector::operator/= (double a)
00148 {
00149   NewMatColumnVector& op1 = *this;
00150   op1 /= a;
00151   return (MyColumnVector&) op1;
00152 }
00153 
00154 
00155 MyColumnVector MyColumnVector::operator+ (double a) const
00156 {
00157   const NewMatColumnVector & op1 = (*this);
00158   return (MyColumnVector) (op1 + a);
00159 }
00160 
00161 MyColumnVector MyColumnVector::operator- (double a) const
00162 {
00163   const NewMatColumnVector & op1 = (*this);
00164   return (MyColumnVector) (op1 - a);
00165 }
00166 
00167 MyColumnVector MyColumnVector::operator* (double a) const
00168 {
00169   const NewMatColumnVector & op1 = (*this);
00170   return (MyColumnVector) (op1 * a);
00171 }
00172 
00173 MyColumnVector MyColumnVector::operator/ (double a) const
00174 {
00175   const NewMatColumnVector & op1 = (*this);
00176   return (MyColumnVector) (op1 / a);
00177 }
00178 
00179 const bool MyColumnVector::operator==(const MyColumnVector& a) const
00180 {
00181   const NewMatColumnVector& op1 = *this;
00182   const NewMatColumnVector& op2 = a;
00183   return (op1 == op2);
00184 }
00185 
00186 MyRowVector MyColumnVector::transpose() const
00187 {
00188   NewMatColumnVector & base = (NewMatColumnVector &) *this;
00189   NewMatRowVector transposedbase = base.t();
00190   return (MyRowVector) transposedbase;
00191 }
00192 
00193 MyMatrix MyColumnVector::operator* (const MyRowVector &a) const
00194 {
00195   const NewMatColumnVector & op1 = (*this);
00196   const NewMatRowVector & op2 = a;
00197   NewMatMatrix result = (NewMatMatrix) (op1 * op2);
00198   return (MyMatrix) result;
00199 }
00200 
00201 MyColumnVector&
00202 MyColumnVector::operator=(const MyColumnVector &a)
00203 {
00204   // Both these implementations result in the same
00205   NewMatColumnVector * op1; const NewMatColumnVector * op2;
00206   op1 = this; op2 = &a;
00207   *op1 = *op2;
00208   return *(this);
00209 }
00210 
00211 MyColumnVector&
00212 MyColumnVector::operator=(double a)
00213 {
00214   // Both these implementations result in the same
00215   NewMatColumnVector * op1;
00216   op1 = this;
00217   *op1 = a;
00218   return *this;
00219 }
00220 
00221 // KG temporary: to read in files fast
00222 istream& operator >> (istream& is, MyColumnVector& a)
00223 {
00224   int nr = a.rows();
00225   int nc = 1;
00226 
00227   if (nr < 1 || nc < 1)
00228     is.clear (ios::badbit);
00229   else
00230     {
00231       double tmp;
00232       for (int i = 0; i < nr; i++)
00233         {
00234           is >> tmp;
00235           if (is)
00236             a(i+1) = tmp; // check if this is ok
00237           else
00238             goto done;
00239         }
00240     }
00241 done:
00242   return is;
00243 }
00244 
00245 
00246 MyColumnVector MyColumnVector::sub(int j_start , int j_end) const
00247 {
00248   return (MyColumnVector)(this->SubMatrix(j_start, j_end, 1, 1));
00249 }
00250 
00254 
00255 // Constructors
00256 MyRowVector::RowVector() : NewMatRowVector() {}
00257 MyRowVector::RowVector(int num_rows) : NewMatRowVector(num_rows){}
00258 
00259 // Destructor
00260 MyRowVector::~RowVector(){}
00261 
00262 // Copy constructor
00263 MyRowVector::RowVector(const MyRowVector& a) : NewMatRowVector(a){}
00264 MyRowVector::RowVector(const NewMatRowVector & a) : NewMatRowVector(a){}
00265 
00266 // Number of Rows / Cols
00267 unsigned int MyRowVector::rows() const { return this->Nrows();}
00268 unsigned int MyRowVector::columns() const { return this->Ncols();}
00269 
00270 // Operators
00271 MyRowVector & MyRowVector::operator+= (const MyRowVector& a)
00272 {
00273   NewMatRowVector & op1 = (*this);
00274   const NewMatRowVector & op2 = a;
00275   op1 += op2;
00276   return (MyRowVector &) op1 ;
00277 }
00278 
00279 MyRowVector & MyRowVector::operator-= (const MyRowVector& a)
00280 {
00281   NewMatRowVector & op1 = (*this);
00282   const NewMatRowVector & op2 = a;
00283   op1 -= op2;
00284   return (MyRowVector &) op1 ;
00285 }
00286 
00287 MyRowVector MyRowVector::operator+ (const MyRowVector &a) const
00288 {
00289   const NewMatRowVector & op1 = (*this);
00290   const NewMatRowVector & op2 = a;
00291   NewMatRowVector result = (NewMatRowVector) (op1 + op2);
00292   return (MyRowVector) result;
00293 }
00294 
00295 MyRowVector MyRowVector::operator- (const MyRowVector &a) const
00296 {
00297   const NewMatRowVector & op1 = (*this);
00298   const NewMatRowVector & op2 = a;
00299   NewMatRowVector result = (NewMatRowVector) (op1 - op2);
00300   return (MyRowVector) result;
00301 }
00302 
00303 
00304 
00305 
00306 double
00307 MyRowVector::operator*(const MyColumnVector& a) const
00308 {
00309   assert (this->columns() == a.rows());
00310 
00311   const NewMatRowVector& op1 = (*this);
00312   const NewMatColumnVector & op2 = a;
00313   NewMatMatrix matrixresult = op1 * op2;
00314   double result = matrixresult.AsScalar();
00315   return result;
00316 }
00317 
00318 
00319 MyRowVector&
00320 MyRowVector::operator=(const MyRowVector &a)
00321 {
00322   // Both these implementations result in the same
00323   NewMatRowVector * op1; const NewMatRowVector * op2;
00324   op1 = this; op2 = &a;
00325   *op1 = *op2;
00326 
00327   return *this;
00328 }
00329 
00330 
00331 MyColumnVector MyRowVector::transpose() const
00332 {
00333   NewMatRowVector & base = (NewMatRowVector &) *this;
00334   NewMatColumnVector transposedbase = base.t();
00335   return (MyColumnVector) transposedbase;
00336 }
00337 
00338 
00339 MyRowVector MyRowVector::sub(int j_start , int j_end) const
00340 {
00341   return (MyRowVector)(this->SubMatrix(1, 1, j_start, j_end));
00342 }
00343 
00344 
00345 
00346 MyRowVector& MyRowVector::operator+= (double a)
00347 {
00348   NewMatRowVector& op1 = *this;
00349   op1 += a;
00350   return (MyRowVector&) op1;
00351 }
00352 
00353 MyRowVector& MyRowVector::operator-= (double a)
00354 {
00355   NewMatRowVector& op1 = *this;
00356   op1 -= a;
00357   return (MyRowVector&) op1;
00358 }
00359 
00360 MyRowVector& MyRowVector::operator*= (double a)
00361 {
00362   NewMatRowVector& op1 = *this;
00363   op1 *= a;
00364   return (MyRowVector&) op1;
00365 }
00366 
00367 MyRowVector& MyRowVector::operator/= (double a)
00368 {
00369   NewMatRowVector& op1 = *this;
00370   op1 /= a;
00371   return (MyRowVector&) op1;
00372 }
00373 
00374 
00375 MyRowVector MyRowVector::operator+ (double a) const
00376 {
00377   const NewMatRowVector & op1 = (*this);
00378   return (MyRowVector) (op1 + a);
00379 }
00380 
00381 MyRowVector MyRowVector::operator- (double a) const
00382 {
00383   const NewMatRowVector & op1 = (*this);
00384   return (MyRowVector) (op1 - a);
00385 }
00386 
00387 MyRowVector MyRowVector::operator* (double a) const
00388 {
00389   const NewMatRowVector & op1 = (*this);
00390   return (MyRowVector) (op1 * a);
00391 }
00392 
00393 MyRowVector MyRowVector::operator/ (double a) const
00394 {
00395   const NewMatRowVector & op1 = (*this);
00396   return (MyRowVector) (op1 / a);
00397 }
00398 
00399 
00400 
00401 MyRowVector&
00402 MyRowVector::operator=(double a)
00403 {
00404   // Both these implementations result in the same
00405   NewMatRowVector * op1;
00406   op1 = this;
00407   *op1 = a;
00408   return *this;
00409 }
00410 
00411 
00412 double& MyRowVector::operator()(unsigned int i)
00413 {
00414   NewMatRowVector& op1 = *(this);
00415   return  op1(i);
00416 }
00417 
00418 const double MyRowVector::operator()(unsigned int i) const
00419 {
00420   NewMatRowVector op1 = (*this);
00421   return  op1(i);
00422 }
00423 
00424 const bool MyRowVector::operator==(const MyRowVector& a) const
00425 {
00426   const NewMatRowVector& op1 = *this;
00427   const NewMatRowVector& op2 = a;
00428   return (op1 == op2);
00429 }
00430 
00431 
00432 MyRowVector
00433 MyRowVector::vectorAdd(const MyRowVector& v2) const
00434 {
00435   const MyRowVector& v1 = *this;
00436   MyRowVector res(v1.rows() + v2.rows());
00437 
00438   for (unsigned int i=0; i<v1.rows(); i++)
00439     res(i+1) = v1(i+1);
00440 
00441   for (unsigned int i=0; i<v2.rows(); i++)
00442     res(v1.rows()+i+1) = v2(i+1);
00443 
00444   return res;
00445 }
00446 
00447 
00448 // Resizing
00449 void MyRowVector::resize(int num_cols)
00450 {
00451   NewMatRowVector & op1 = (*this);
00452   op1.ReSize(num_cols);
00453 }
00454 
00455 
00456 #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