vector_EIGEN.cpp
Go to the documentation of this file.
00001 #include "../config.h"
00002 #ifdef __MATRIXWRAPPER_EIGEN__
00003 
00004 #include "vector_EIGEN.h"
00005 #include <iostream>
00006 
00007 
00008 // Constructors
00009 MyColumnVector::ColumnVector() : EigenColumnVector() {}
00010 MyColumnVector::ColumnVector(int num_rows) : EigenColumnVector(num_rows){}
00011 MyColumnVector::ColumnVector(int num_rows,double value) : EigenColumnVector(num_rows){
00012   ((EigenColumnVector*)this)->setConstant(value);
00013 }
00014 MyColumnVector::ColumnVector(const MyColumnVector& a, const MyColumnVector& b) : EigenColumnVector(a.rows() + b.rows())
00015 {
00016   EigenColumnVector& opl = (*this);
00017   opl.head(a.rows()) = (const EigenColumnVector &)(a);
00018   opl.tail(b.rows()) = (const EigenColumnVector &)(b);
00019 }
00020 
00021 // Destructor
00022 MyColumnVector::~ColumnVector(){}
00023 
00024 // Copy constructor
00025 MyColumnVector::ColumnVector(const MyColumnVector& a) :
00026   EigenColumnVector(a){}
00027 MyColumnVector::ColumnVector(const EigenColumnVector & a) :
00028   EigenColumnVector(a){}
00029 
00030 // Resizing
00031 void MyColumnVector::resize(int num_rows)
00032 {
00033   EigenColumnVector & op1 = (*this);
00034   op1.resize(num_rows);
00035 }
00036 
00037 // Assign
00038 void MyColumnVector::assign(int num_rows, double value)
00039 {
00040   EigenColumnVector & op1 = (*this);
00041   op1.resize(num_rows);
00042   op1.setConstant(value);
00043 }
00044 
00045 // Number of Rows / Cols
00046 unsigned int MyColumnVector::rows() const { return ((const EigenColumnVector *)this)->rows();}
00047 unsigned int MyColumnVector::columns() const { return ((const EigenColumnVector *)this)->cols();}
00048 unsigned int MyColumnVector::capacity() const { return ((const EigenColumnVector *)this)->size();}
00049 
00050 MyColumnVector
00051 MyColumnVector::vectorAdd(const MyColumnVector& v2) const
00052 {
00053   const MyColumnVector& v1 = *this;
00054   MyColumnVector res(v1.rows() + v2.rows());
00055   EigenColumnVector& opl = res;
00056   opl.head(v1.rows()) = (const EigenColumnVector &)(v1);
00057   opl.tail(v2.rows()) = (const EigenColumnVector &)(v2);
00058 
00059   return res;
00060 }
00061 
00062 double& MyColumnVector::operator()(unsigned int i)
00063 {
00064   //std::cout << "(BOOSTVECTOR) operator() called" << std::endl;
00065   EigenColumnVector& op1 = *(this);
00066   return op1(i-1);
00067 }
00068 
00069 double MyColumnVector::operator()(unsigned int i) const
00070 {
00071   //std::cout << "(BOOSTVECTOR) operator() called" << std::endl;
00072   const EigenColumnVector op1 = (*this);
00073   return op1(i-1);
00074 }
00075 
00076 
00077 bool MyColumnVector::operator==(const MyColumnVector& a) const
00078 {
00079   if (this->rows() != a.rows()) return false;
00080   return(((EigenColumnVector)(*this)-(EigenColumnVector)a).isApproxToConstant(0.0));
00081 }
00082 
00083 // Operators
00084 MyColumnVector & MyColumnVector::operator+= (const MyColumnVector& a)
00085 {
00086   EigenColumnVector & op1 = (*this);
00087   const EigenColumnVector & op2 = a;
00088   op1 += op2;
00089   return (MyColumnVector &) op1;
00090 }
00091 
00092 MyColumnVector & MyColumnVector::operator-= (const MyColumnVector& a)
00093 {
00094   EigenColumnVector & op1 = (*this);
00095   const EigenColumnVector & op2 = a;
00096   op1 -= op2;
00097   return (MyColumnVector &) op1;
00098 }
00099 
00100 MyColumnVector MyColumnVector::operator+ (const MyColumnVector &a) const
00101 {
00102   return (MyColumnVector) ((EigenColumnVector)(*this) + (EigenColumnVector)a);
00103 }
00104 
00105 MyColumnVector MyColumnVector::operator- (const MyColumnVector &a) const
00106 {
00107   return (MyColumnVector) ((EigenColumnVector)(*this) - (EigenColumnVector)a);
00108 }
00109 
00110 
00111 
00112 MyColumnVector& MyColumnVector::operator+= (double a)
00113 {
00114   EigenColumnVector & op1 = *this;
00115   op1 += EigenColumnVector::Constant(rows(), a);
00116   return (MyColumnVector&)op1;
00117 }
00118 
00119 MyColumnVector& MyColumnVector::operator-= (double a)
00120 {
00121   EigenColumnVector & op1 = *this;
00122   op1 -= EigenColumnVector::Constant(rows(), a);
00123   return (MyColumnVector&)op1;
00124 }
00125 
00126 MyColumnVector& MyColumnVector::operator*= (double a)
00127 {
00128   EigenColumnVector& op1 = *this;
00129   op1 *= a;
00130   return (MyColumnVector&) op1;
00131 }
00132 
00133 MyColumnVector& MyColumnVector::operator/= (double a)
00134 {
00135   EigenColumnVector& op1 = *this;
00136   op1 /= a;
00137   return (MyColumnVector&) op1;
00138 }
00139 
00140 
00141 MyColumnVector MyColumnVector::operator+ (double a) const
00142 {
00143   return (MyColumnVector)(((EigenColumnVector)(*this)) + EigenColumnVector::Constant(rows(), a));
00144 }
00145 
00146 MyColumnVector MyColumnVector::operator- (double a) const
00147 {
00148   return (MyColumnVector)(((EigenColumnVector)(*this)) - EigenColumnVector::Constant(rows(), a));
00149 }
00150 
00151 MyColumnVector MyColumnVector::operator* (double a) const
00152 {
00153   const EigenColumnVector & op1 = (*this);
00154   return (MyColumnVector) (op1 * a);
00155 }
00156 
00157 MyColumnVector MyColumnVector::operator/ (double a) const
00158 {
00159   const EigenColumnVector & op1 = (*this);
00160   return (MyColumnVector) (op1 / a);
00161 }
00162 
00163 
00164 
00165 MyRowVector MyColumnVector::transpose() const
00166 {
00167   const EigenColumnVector & op1 = (*this);
00168   return MyRowVector(op1.transpose());
00169 }
00170 
00171 MyMatrix MyColumnVector::operator* (const MyRowVector &a) const
00172 {
00173   const EigenColumnVector & op1 = (*this);
00174   const EigenRowVector & op2 = a;
00175 
00176   return MyMatrix(op1 * op2);
00177 }
00178 
00179 MyColumnVector&
00180 MyColumnVector::operator=(const MyColumnVector &a)
00181 {
00182   EigenColumnVector& op1 = *this;
00183   op1 = (EigenColumnVector)a;
00184   return *this;
00185 }
00186 
00187 MyColumnVector&
00188 MyColumnVector::operator=(double a)
00189 {
00190   EigenColumnVector& op1 = *this;
00191   op1.setConstant(a);
00192   return *this;
00193 }
00194 
00195 MyColumnVector MyColumnVector::sub(int j_start , int j_end) const
00196 {
00197   const EigenColumnVector& op1 = *this;
00198   return MyColumnVector(op1.segment(j_start-1,j_end-j_start+1));
00199 }
00200 
00201 
00202 
00206 
00207 // Constructors
00208 MyRowVector::RowVector() : EigenRowVector() {}
00209 MyRowVector::RowVector(int num_cols) : EigenRowVector(num_cols){}
00210 MyRowVector::RowVector(int num_cols,double value) : EigenRowVector(num_cols){
00211   ((EigenRowVector*)this)->setConstant(value);
00212 }
00213 
00214 // Destructor
00215 MyRowVector::~RowVector(){}
00216 
00217 // Copy constructor
00218 MyRowVector::RowVector(const MyRowVector& a) :
00219   EigenRowVector(a){}
00220 MyRowVector::RowVector(const EigenRowVector & a) :
00221   EigenRowVector(a){}
00222 
00223 // Resizing
00224 void MyRowVector::resize(int num_columns)
00225 {
00226   EigenRowVector & op1 = (*this);
00227   op1.resize(num_columns);
00228 }
00229 
00230 // Assign
00231 void MyRowVector::assign(int num_columns, double value)
00232 {
00233   EigenRowVector & op1 = (*this);
00234   op1.resize(num_columns);
00235   op1.setConstant(value);
00236 }
00237 
00238 // Number of Rows / Cols
00239 unsigned int MyRowVector::rows() const { return ((const EigenRowVector *)this)->rows();}
00240 unsigned int MyRowVector::columns() const { return ((const EigenRowVector *)this)->cols();}
00241 unsigned int MyRowVector::capacity() const { return ((const EigenRowVector *)this)->size();}
00242 
00243 MyRowVector
00244 MyRowVector::vectorAdd(const MyRowVector& v2) const
00245 {
00246   const MyRowVector& v1 = *this;
00247   MyRowVector res(v1.rows() + v2.rows());
00248   EigenRowVector& opl = res;
00249   opl.head(v1.rows()) = (const EigenRowVector &)(v1);
00250   opl.tail(v2.rows()) = (const EigenRowVector &)(v2);
00251   return res;
00252 }
00253 
00254 double& MyRowVector::operator()(unsigned int i)
00255 {
00256   EigenRowVector& op1 = *(this);
00257   return op1(i-1);
00258 }
00259 
00260 double MyRowVector::operator()(unsigned int i) const
00261 {
00262   const EigenRowVector& op1 = (*this);
00263   return op1(i-1);
00264 }
00265 
00266 bool MyRowVector::operator==(const MyRowVector& a) const
00267 {
00268   if (this->columns() != a.columns()) return false;
00269   return(((EigenRowVector)(*this)-(EigenRowVector)a).isApproxToConstant(0.0));
00270 }
00271 
00272 // Operators
00273 MyRowVector & MyRowVector::operator+= (const MyRowVector& a)
00274 {
00275   EigenRowVector & op1 = (*this);
00276   const EigenRowVector & op2 = a;
00277   op1 += op2;
00278   return (MyRowVector &) op1;
00279 }
00280 
00281 MyRowVector & MyRowVector::operator-= (const MyRowVector& a)
00282 {
00283   EigenRowVector & op1 = (*this);
00284   const EigenRowVector & op2 = a;
00285   op1 -= op2;
00286   return (MyRowVector &) op1;
00287 }
00288 
00289 MyRowVector MyRowVector::operator+ (const MyRowVector &a) const
00290 {
00291   return (MyRowVector) ((EigenRowVector)(*this) + (EigenRowVector)a);
00292 }
00293 
00294 MyRowVector MyRowVector::operator- (const MyRowVector &a) const
00295 {
00296   return (MyRowVector) ((EigenRowVector)(*this) - (EigenRowVector)a);
00297 }
00298 
00299 
00300 
00301 MyRowVector& MyRowVector::operator+= (double a)
00302 {
00303   EigenRowVector & op1 = *this;
00304   op1 += EigenRowVector::Constant(columns(),a);
00305   return (MyRowVector&)op1;
00306 }
00307 
00308 MyRowVector& MyRowVector::operator-= (double a)
00309 {
00310   EigenRowVector & op1 = *this;
00311   op1 -= EigenRowVector::Constant(columns(),a);
00312   return (MyRowVector&)op1;
00313 }
00314 
00315 MyRowVector& MyRowVector::operator*= (double a)
00316 {
00317   EigenRowVector& op1 = *this;
00318   op1 *= a;
00319   return (MyRowVector&) op1;
00320 }
00321 
00322 MyRowVector& MyRowVector::operator/= (double a)
00323 {
00324   EigenRowVector& op1 = *this;
00325   op1 /= a;
00326   return (MyRowVector&) op1;
00327 }
00328 
00329 
00330 MyRowVector MyRowVector::operator+ (double a) const
00331 {
00332   return (MyRowVector)(((EigenRowVector)(*this)) + EigenRowVector::Constant(columns(),a));
00333 }
00334 
00335 MyRowVector MyRowVector::operator- (double a) const
00336 {
00337   return (MyRowVector)(((EigenRowVector)(*this)) - EigenRowVector::Constant(columns(),a));
00338 }
00339 
00340 MyRowVector MyRowVector::operator* (double a) const
00341 {
00342   const EigenRowVector & op1 = (*this);
00343   return (MyRowVector) (op1 * a);
00344 }
00345 
00346 MyRowVector MyRowVector::operator/ (double a) const
00347 {
00348   const EigenRowVector & op1 = (*this);
00349   return (MyRowVector) (op1 / a);
00350 }
00351 
00352 
00353 
00354 MyColumnVector MyRowVector::transpose() const
00355 {
00356   const EigenRowVector & op1 = (*this);
00357   return MyColumnVector(op1.transpose());
00358 }
00359 
00360 double MyRowVector::operator* (const MyColumnVector &a) const
00361 {
00362   const EigenRowVector & op1 = (*this);
00363   const EigenColumnVector & op2 = a;
00364   return (op1 * op2)(0,0);
00365 }
00366 
00367 MyRowVector&
00368 MyRowVector::operator=(const MyRowVector &a)
00369 {
00370   EigenRowVector& op1 = *this;
00371   op1 = (EigenRowVector)a;
00372   return *this;
00373 }
00374 
00375 MyRowVector&
00376 MyRowVector::operator=(double a)
00377 {
00378   EigenRowVector& op1 = *this;
00379   op1.setConstant(a);
00380   return *this;
00381 }
00382 
00383 MyRowVector MyRowVector::sub(int j_start , int j_end) const
00384 {
00385   const EigenRowVector& op1 = *this;
00386   return MyRowVector(op1.segment(j_start-1,j_end-j_start+1));
00387 }
00388 
00389 #endif


bfl_eigen
Author(s): Klaas Gadeyne, Wim Meeussen, Tinne Delaet and many others. See web page for a full contributor list. Eigen matrix library support added by Johannes Meyer.
autogenerated on Mon Oct 6 2014 00:20:35