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