CPPLapack
 All Classes Files Functions Variables Friends
drovector_small-functions.hpp
Go to the documentation of this file.
00001 //=============================================================================
00002 /*!  */
00003 template<long l>
00004 inline _drovector drovector_small<l>::to_drovector() const
00005 {VERBOSE_REPORT;
00006   drovector vec(l);
00007   for(long k=0; k<l; k++){
00008     vec(k)=(*this)(k);
00009   }
00010   return _(vec);
00011 }
00012 
00013 ///////////////////////////////////////////////////////////////////////////////
00014 ///////////////////////////////////////////////////////////////////////////////
00015 ///////////////////////////////////////////////////////////////////////////////
00016 
00017 //=============================================================================
00018 /*!  */
00019 template<long l>
00020 inline double& drovector_small<l>::operator()(const long& k)
00021 {VERBOSE_REPORT;
00022   return array[k];
00023 }
00024 
00025 //=============================================================================
00026 /*!  */
00027 template<long l>
00028 inline double drovector_small<l>::operator()(const long& k) const
00029 {VERBOSE_REPORT;
00030   return array[k];
00031 }
00032 
00033 //=============================================================================
00034 /*!  */
00035 template<long l>
00036 inline drovector_small<l>& drovector_small<l>::set(const long& k, const double& v)
00037 {VERBOSE_REPORT;
00038   (*this)(k) =v;
00039   return *this;
00040 }
00041 
00042 //=============================================================================
00043 /*!  */
00044 template<long l>
00045 inline std::ostream& operator<<(std::ostream& s, const drovector_small<l>& A)
00046 {VERBOSE_REPORT;
00047   s << std::setiosflags(std::ios::showpos);
00048   for(long i=0; i<l; i++){
00049     s << " " << A(i) << std::flush;
00050   }
00051   s << std::endl;
00052   return s;
00053 }
00054 
00055 //=============================================================================
00056 /*!  */
00057 template<long l>
00058 inline void drovector_small<l>::write(const char* filename) const
00059 {VERBOSE_REPORT;
00060   std::ofstream ofs(filename, std::ios::trunc);
00061   ofs.setf(std::cout.flags());
00062   ofs.precision(std::cout.precision());
00063   ofs.width(std::cout.width());
00064   ofs.fill(std::cout.fill());
00065   
00066   ofs << "#drovector" << " " << l << std::endl;
00067   for(long k=0; k<l; k++){
00068     ofs << (*this)(k) << std::endl;
00069   }
00070   ofs.close();
00071 }
00072 
00073 //=============================================================================
00074 /*!  */
00075 template<long l>
00076 inline void drovector_small<l>::read(const char* filename)
00077 {VERBOSE_REPORT;
00078   std::ifstream s( filename );
00079   if(!s){
00080     ERROR_REPORT;
00081     std::cerr << "The file \"" << filename << "\" can not be opened." << std::endl;
00082     exit(1);
00083   }
00084   
00085   std::string id;
00086   s >> id;
00087   if( id != "drovector" && id != "#drovector" ){
00088     ERROR_REPORT;
00089     std::cerr << "The type name of the file \"" << filename << "\" is not drovector." << std::endl
00090               << "Its type name was " << id << " ." << std::endl;
00091     exit(1);
00092   }
00093   
00094   long _l;
00095   s >> _l;
00096   if(l!=_l){
00097     ERROR_REPORT;
00098     std::cerr << "Matrix size is invalid." << std::endl;
00099     exit(1);
00100   }
00101   for(long k=0; k<l; k++){
00102     s >> (*this)(k);
00103   }
00104   if(s.eof()){
00105     ERROR_REPORT;
00106     std::cerr << "There is something is wrong with the file \"" << filename << "\"." << std::endl
00107               << "Most likely, there is not enough data components, or a linefeed code or space code is missing at the end of the last line." << std::endl;
00108     exit(1);
00109   }
00110   
00111   s >> id;//tmp
00112   if(!s.eof()){
00113     ERROR_REPORT;
00114     std::cerr << "There is something is wrong with the file \"" << filename << "\"." << std::endl
00115               << "Most likely, there are extra data components." << std::endl;
00116     exit(1);
00117   }
00118   
00119   s.close();    
00120 }
00121 
00122 ///////////////////////////////////////////////////////////////////////////////
00123 ///////////////////////////////////////////////////////////////////////////////
00124 ///////////////////////////////////////////////////////////////////////////////
00125 ///////////////////////////////////////////////////////////////////////////////
00126 ///////////////////////////////////////////////////////////////////////////////
00127 ///////////////////////////////////////////////////////////////////////////////
00128 
00129 //=============================================================================
00130 /*!  */
00131 template<long n>
00132 inline dcovector_small<n> t(const drovector_small<n>& A)
00133 {VERBOSE_REPORT;
00134   dcovector_small<n> X;
00135   for(long i=0; i<n; i++){
00136     X(i)=A(i);
00137   }
00138   return X;
00139 }
00140 
00141 //=============================================================================
00142 /*!  */
00143 template<long l>
00144 inline double nrm2(const drovector_small<l>& A)
00145 {VERBOSE_REPORT;
00146   double v(0);
00147   for(long i=0; i<l; i++){
00148     v+=A(i)*A(i);
00149   }
00150   return sqrt(v);
00151 }
00152 
00153 //=============================================================================
00154 /*!  */
00155 template<long l>
00156 inline void idamax(long& K, const drovector_small<l>& A)
00157 {VERBOSE_REPORT;
00158   double max(-1.);
00159   for(int k=0; k<l; k++){
00160     if( max<fabs(A(k)) ){
00161       K=k;
00162       max =fabs(A(k));
00163     }
00164   }
00165   return;
00166 }
00167 
00168 //=============================================================================
00169 /*!  */
00170 template<long l>
00171 inline double damax(const drovector_small<l>& A)
00172 {VERBOSE_REPORT;
00173   long k(0);
00174   idamax(k,A);
00175   return A(k);
00176 }
00177 
00178 //=============================================================================
00179 /*!  */
00180 template<long l>
00181 inline drovector_small<l> colon(const drovector_small<l>& A, const drovector_small<l>& B)
00182 {VERBOSE_REPORT;
00183   drovector_small<l> C;
00184   for(long i=0; i<l; i++){
00185     C(i) =A(i)*B(i);
00186   }
00187   return C;
00188 }
00189 
00190 ///////////////////////////////////////////////////////////////////////////////
00191 ///////////////////////////////////////////////////////////////////////////////
00192 ///////////////////////////////////////////////////////////////////////////////
00193 ///////////////////////////////////////////////////////////////////////////////
00194 ///////////////////////////////////////////////////////////////////////////////
00195 ///////////////////////////////////////////////////////////////////////////////
00196 
00197 //=============================================================================
00198 /*!  */
00199 template<long l>
00200 inline drovector_small<l>& drovector_small<l>::zero()
00201 {VERBOSE_REPORT;
00202   for(long k=0; k<l; k++){
00203     array[k] =0.;
00204   }
00205   return *this;
00206 }
00207 
00208 ///////////////////////////////////////////////////////////////////////////////
00209 ///////////////////////////////////////////////////////////////////////////////
00210 ///////////////////////////////////////////////////////////////////////////////
00211 ///////////////////////////////////////////////////////////////////////////////
00212 ///////////////////////////////////////////////////////////////////////////////
00213 ///////////////////////////////////////////////////////////////////////////////
00214 
00215 //=============================================================================
00216 /*!  */
00217 template<long l>
00218 inline drovector_small<l>& operator+=(drovector_small<l>& A, const drovector_small<l>& B)
00219 {VERBOSE_REPORT;
00220   for(long i=0; i<l; i++){
00221     A(i) +=B(i);
00222   }
00223   return A;
00224 }
00225 
00226 //=============================================================================
00227 /*!  */
00228 template<long l>
00229 inline drovector_small<l>& operator-=(drovector_small<l>& A, const drovector_small<l>& B)
00230 {VERBOSE_REPORT;
00231   for(long i=0; i<l; i++){
00232     A(i) -=B(i);
00233   }
00234   return A;
00235 }
00236 
00237 //=============================================================================
00238 /*!  */
00239 template<long l>
00240 inline drovector_small<l>& operator*=(drovector_small<l>& A, const double& d)
00241 {VERBOSE_REPORT;
00242   for(long i=0; i<l; i++){
00243     A(i) *=d;
00244   }
00245   return A;
00246 }
00247 
00248 //=============================================================================
00249 /*!  */
00250 template<long l>
00251 inline drovector_small<l>& operator/=(drovector_small<l>& A, const double& d)
00252 {VERBOSE_REPORT;
00253   for(long i=0; i<l; i++){
00254     A(i) /=d;
00255   }
00256   return A;
00257 }
00258 
00259 ///////////////////////////////////////////////////////////////////////////////
00260 ///////////////////////////////////////////////////////////////////////////////
00261 ///////////////////////////////////////////////////////////////////////////////
00262 
00263 //=============================================================================
00264 /*! unary */
00265 template<long l>
00266 inline const drovector_small<l>& operator+(const drovector_small<l>& A)
00267 {VERBOSE_REPORT;
00268   return A;
00269 }
00270 
00271 //=============================================================================
00272 /*! unary */
00273 template<long l>
00274 inline drovector_small<l> operator-(const drovector_small<l>& A)
00275 {VERBOSE_REPORT;
00276   drovector_small<l> X;
00277   for(long i=0; i<l; i++){
00278     X(i) =-A(i);
00279   }
00280   return X;
00281 }
00282 
00283 ///////////////////////////////////////////////////////////////////////////////
00284 ///////////////////////////////////////////////////////////////////////////////
00285 ///////////////////////////////////////////////////////////////////////////////
00286 
00287 //=============================================================================
00288 /*!  */
00289 template<long l>
00290 inline drovector_small<l> operator+(const drovector_small<l>& A, const drovector_small<l>& B)
00291 {VERBOSE_REPORT;
00292   drovector_small<l> X;
00293   for(long i=0; i<l; i++){
00294     X(i) =A(i)+B(i);
00295   }
00296   return X;
00297 }
00298 
00299 //=============================================================================
00300 /*!  */
00301 template<long l>
00302 inline drovector_small<l> operator-(const drovector_small<l>& A, const drovector_small<l>& B)
00303 {VERBOSE_REPORT;
00304   drovector_small<l> X;
00305   for(long i=0; i<l; i++){
00306     X(i) =A(i)-B(i);
00307   }
00308   return X;
00309 }
00310 
00311 //=============================================================================
00312 /*!  */
00313 template<long l>
00314 inline double operator*(const drovector_small<l>& A, const dcovector_small<l>& B)
00315 {VERBOSE_REPORT;
00316   double x =0.;
00317   for(long i=0; i<l; i++){
00318     x +=A(i)*B(i);
00319   }
00320   return x;
00321 }
00322 
00323 //=============================================================================
00324 /*!  */
00325 template<long m, long n>
00326 inline drovector_small<n> operator*(const drovector_small<m>& A, const dgematrix_small<m,n>& B)
00327 {VERBOSE_REPORT;
00328   drovector_small<n> C(0.);
00329   for(long j=0; j<n; j++){
00330     for(long i=0; i<m; i++){
00331       C(j) +=A(i)*B(i,j);
00332     }
00333   }
00334   return C;
00335 }
00336 
00337 //=============================================================================
00338 /*!  */
00339 template<long l>
00340 inline drovector_small<l> operator*(const drovector_small<l>& A, const dsymatrix_small<l>& B)
00341 {VERBOSE_REPORT;
00342   drovector_small<l> C(0.);
00343   for(long j=0; j<l; j++){
00344     for(long i=0; i<j; i++){
00345       C(j) +=A(i)*B(j,i);
00346     }
00347     for(long i=j; i<l; i++){
00348       C(j) +=A(i)*B(i,j);
00349     }    
00350   }
00351   return C;
00352 }
00353 
00354 //=============================================================================
00355 /*!  */
00356 template<long l>
00357 inline drovector_small<l> operator*(const drovector_small<l>& A, const double& v)
00358 {VERBOSE_REPORT;
00359   drovector_small<l> C;
00360   for(long i=0; i<l; i++){
00361     C(i) =A(i)*v;
00362   }
00363   return C;
00364 }
00365 
00366 //=============================================================================
00367 /*!  */
00368 template<long l>
00369 inline drovector_small<l> operator/(const drovector_small<l>& A, const double& v)
00370 {VERBOSE_REPORT;
00371   drovector_small<l> C;
00372   for(long i=0; i<l; i++){
00373     C(i) =A(i)/v;
00374   }
00375   return C;
00376 }
 All Classes Files Functions Variables Friends