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