00001
00002
00003 template<long m, long n>
00004 inline _zgematrix zgematrix_small<m,n>::to_zgematrix() const
00005 {VERBOSE_REPORT;
00006 zgematrix mat(m,n);
00007 for(long i=0; i<m; i++){
00008 for(long j=0; j<n; j++){
00009 mat(i,j) =(*this)(i,j);
00010 }
00011 }
00012 return _(mat);
00013 }
00014
00015
00016
00017
00018
00019
00020
00021 template<long m, long n>
00022 inline comple& zgematrix_small<m,n>::operator()(const long& i, const long& j)
00023 {VERBOSE_REPORT;
00024 return array[i+m*j];
00025 }
00026
00027
00028
00029 template<long m, long n>
00030 inline comple zgematrix_small<m,n>::operator()(const long& i, const long& j) const
00031 {VERBOSE_REPORT;
00032 return array[i+m*j];
00033 }
00034
00035
00036
00037 template<long m, long n>
00038 inline zgematrix_small<m,n>& zgematrix_small<m,n>::set(const long& i, const long& j, const comple& v)
00039 {VERBOSE_REPORT;
00040 (*this)(i,j) =v;
00041 return *this;
00042 }
00043
00044
00045
00046 template<long m, long n>
00047 inline std::ostream& operator<<(std::ostream& s, const zgematrix_small<m,n>& A)
00048 {VERBOSE_REPORT;
00049 s << std::setiosflags(std::ios::showpos);
00050 for(long i=0; i<m; i++){
00051 for(long j=0; j<n; j++){
00052 s << " " << A(i,j);
00053 }
00054 s << std::endl;
00055 }
00056 return s;
00057 }
00058
00059
00060
00061 template<long m, long n>
00062 inline void zgematrix_small<m,n>::write(const char* filename) const
00063 {VERBOSE_REPORT;
00064 std::ofstream ofs(filename, std::ios::trunc);
00065 ofs.setf(std::cout.flags());
00066 ofs.precision(std::cout.precision());
00067 ofs.width(std::cout.width());
00068 ofs.fill(std::cout.fill());
00069 ofs << "#zgematrix" << " " << m << " " << n << std::endl;
00070 for(long i=0; i<m; i++){
00071 for(long j=0; j<n; j++){
00072 ofs << (*this)(i,j) << " ";
00073 }
00074 ofs << std::endl;
00075 }
00076 ofs.close();
00077 }
00078
00079
00080
00081 template<long m, long n>
00082 inline void zgematrix_small<m,n>::read(const char* filename)
00083 {VERBOSE_REPORT;
00084 std::ifstream s( filename );
00085 if(!s){
00086 ERROR_REPORT;
00087 std::cerr << "The file \"" << filename << "\" can not be opened." << std::endl;
00088 exit(1);
00089 }
00090
00091 std::string id;
00092 s >> id;
00093 if( id != "zgematrix" && id != "#zgematrix" ){
00094 ERROR_REPORT;
00095 std::cerr << "The type name of the file \"" << filename << "\" is not zgematrix." << std::endl
00096 << "Its type name was " << id << " ." << std::endl;
00097 exit(1);
00098 }
00099
00100 long _m, _n;
00101 s >> _m >> _n;
00102 if(m!=_m || n!=_n){
00103 ERROR_REPORT;
00104 std::cerr << "Matrix size is invalid." << std::endl;
00105 exit(1);
00106 }
00107 for(long i=0; i<m; i++){
00108 for(long j=0; j<n; j++ ){
00109 s >> operator()(i,j);
00110 }
00111 }
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 is not enough data components, or a linefeed code or space code is missing at the end of the last line." << std::endl;
00116 exit(1);
00117 }
00118
00119 s >> id;
00120 if(!s.eof()){
00121 ERROR_REPORT;
00122 std::cerr << "There is something is wrong with the file \"" << filename << "\"." << std::endl
00123 << "Most likely, there are extra data components." << std::endl;
00124 exit(1);
00125 }
00126
00127 s.close();
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 template<long m, long n>
00140 inline zgematrix_small<n,m> t(const zgematrix_small<m,n>& A)
00141 {VERBOSE_REPORT;
00142 zgematrix_small<n,m> X;
00143 for(long i=0; i<m; i++){
00144 for(long j=0; j<n; j++){
00145 X(j,i) =A(i,j);
00146 }
00147 }
00148 return X;
00149 }
00150
00151
00152
00153
00154
00155
00156
00157 template<long m, long n>
00158 inline zgematrix_small<m,n>& zgematrix_small<m,n>::zero()
00159 {VERBOSE_REPORT;
00160 for(long k=0; k<m*n; k++){
00161 array[k] =comple(0.,0.);
00162 }
00163 return *this;
00164 }
00165
00166
00167
00168 template<long m, long n>
00169 inline zgematrix_small<m,n>& zgematrix_small<m,n>::identity()
00170 {VERBOSE_REPORT;
00171 zero();
00172 for(long k=0; k<std::min(m,n); k++){
00173 (*this)(k,k) =1.;
00174 }
00175 return *this;
00176 }
00177
00178
00179
00180 template<long m, long n>
00181 inline zcovector_small<m> zgematrix_small<m,n>::col(const long& j) const
00182 {VERBOSE_REPORT;
00183 zcovector_small<m> vec;
00184 for(long i=0; i<m; i++){
00185 vec(i) =(*this)(i,j);
00186 }
00187 return vec;
00188 }
00189
00190
00191
00192 template<long m, long n>
00193 inline zrovector_small<n> zgematrix_small<m,n>::row(const long& i) const
00194 {VERBOSE_REPORT;
00195 zrovector_small<n> vec;
00196 for(long j=0; j<n; j++){
00197 vec(j)=(*this)(i,j);
00198 }
00199 return vec;
00200 }
00201
00202
00203
00204
00205
00206
00207
00208 template<long m, long n>
00209 inline zgematrix_small<m,n>& operator+=(zgematrix_small<m,n>& A, const zgematrix_small<m,n>& B)
00210 {VERBOSE_REPORT;
00211 for(long k=0; k<m*n; k++){
00212 A.array[k] +=B.array[k];
00213 }
00214 return A;
00215 }
00216
00217
00218
00219 template<long m, long n>
00220 inline zgematrix_small<m,n>& operator-=(zgematrix_small<m,n>& A, const zgematrix_small<m,n>& B)
00221 {VERBOSE_REPORT;
00222 for(long k=0; k<m*n; k++){
00223 A.array[k] -=B.array[k];
00224 }
00225 return A;
00226 }
00227
00228
00229
00230 template<long m, long l, long n>
00231 inline zgematrix_small<m,n>& operator*=(zgematrix_small<m,l>& A, const zgematrix_small<l,n>& B)
00232 {VERBOSE_REPORT;
00233 zgematrix_small<m,n> X(0.);
00234 for(long i=0; i<m; i++){
00235 for(long j=0; j<n; j++){
00236 for(long k=0; k<l; k++){
00237 X(i,j) += A(i,k)*B(k,j);
00238 }
00239 }
00240 }
00241 return X;
00242 }
00243
00244
00245
00246 template<long m, long n>
00247 inline zgematrix_small<m,n>& operator*=(zgematrix_small<m,n>& A, const double& d)
00248 {VERBOSE_REPORT;
00249 for(long k=0; k<m*n; k++){
00250 A.array[k] *=d;
00251 }
00252 return A;
00253 }
00254
00255
00256
00257 template<long m, long n>
00258 inline zgematrix_small<m,n>& operator*=(zgematrix_small<m,n>& A, const comple& d)
00259 {VERBOSE_REPORT;
00260 for(long k=0; k<m*n; k++){
00261 A.array[k] *=d;
00262 }
00263 return A;
00264 }
00265
00266
00267
00268 template<long m, long n>
00269 inline zgematrix_small<m,n>& operator/=(zgematrix_small<m,n>& A, const double& d)
00270 {VERBOSE_REPORT;
00271 for(long k=0; k<m*n; k++){
00272 A.array[k] /=d;
00273 }
00274 return A;
00275 }
00276
00277
00278 template<long m, long n>
00279 inline zgematrix_small<m,n>& operator/=(zgematrix_small<m,n>& A, const comple& d)
00280 {VERBOSE_REPORT;
00281 for(long k=0; k<m*n; k++){
00282 A.array[k] /=d;
00283 }
00284 return A;
00285 }
00286
00287
00288
00289
00290
00291
00292
00293 template<long m, long n>
00294 inline const zgematrix_small<m,n>& operator+(const zgematrix_small<m,n>& A)
00295 {VERBOSE_REPORT;
00296 return A;
00297 }
00298
00299
00300
00301 template<long m, long n>
00302 inline zgematrix_small<m,n> operator-(const zgematrix_small<m,n>& A)
00303 {VERBOSE_REPORT;
00304 zgematrix_small<m,n> X;
00305 for(long i=0; i<m; i++){
00306 for(long j=0; j<n; j++){
00307 X(i,j) =-A(i,j);
00308 }
00309 }
00310 return X;
00311 }
00312
00313
00314
00315
00316
00317
00318
00319 template<long m, long n>
00320 inline zgematrix_small<m,n> operator+(const zgematrix_small<m,n>& A, const zgematrix_small<m,n>& B)
00321 {VERBOSE_REPORT;
00322 zgematrix_small<m,n> C;
00323 for(int i=0; i<m; i++){
00324 for(int j=0; j<n; j++){
00325 C(i,j) =A(i,j)+B(i,j);
00326 }
00327 }
00328 return C;
00329 }
00330
00331
00332
00333 template<long n>
00334 inline zgematrix_small<n,n> operator+(const zgematrix_small<n,n>& A, const zhematrix_small<n>& B)
00335 {VERBOSE_REPORT;
00336 zgematrix_small<n,n> X;
00337 for(long i=0; i<n; i++){
00338 for(long j=0; j<i; j++){
00339 X(i,j) =A(i,j)+B(i,j);
00340 }
00341 for(long j=i; j<n; j++){
00342 X(i,j) =A(i,j)+B(j,i);
00343 }
00344 }
00345 return X;
00346 }
00347
00348
00349
00350 template<long m, long n>
00351 inline zgematrix_small<m,n> operator-(const zgematrix_small<m,n>& A, const zgematrix_small<m,n>& B)
00352 {VERBOSE_REPORT;
00353 zgematrix_small<m,n> C;
00354 for(int i=0; i<m; i++){
00355 for(int j=0; j<n; j++){
00356 C(i,j)=A(i,j)-B(i,j);
00357 }
00358 }
00359 return C;
00360 }
00361
00362
00363
00364 template<long n>
00365 inline zgematrix_small<n,n> operator-(const zgematrix_small<n,n>& A, const zhematrix_small<n>& B)
00366 {VERBOSE_REPORT;
00367 zgematrix_small<n,n> X;
00368 for(long i=0; i<n; i++){
00369 for(long j=0; j<=i; j++){
00370 X(i,j)=A(i,j)-B(i,j);
00371 }
00372 for(long j=i+1; j<n; j++){
00373 X(i,j)=A(i,j)-B(j,i);
00374 }
00375 }
00376 return X;
00377 }
00378
00379
00380
00381 template<long m, long n>
00382 inline zcovector_small<m> operator*(const zgematrix_small<m,n>& A, const zcovector_small<n>& B)
00383 {VERBOSE_REPORT;
00384 zcovector_small<m> C(0.);
00385 for(long i=0; i<m; i++){
00386 for(long j=0; j<n; j++){
00387 C(i) +=A(i,j)*B(j);
00388 }
00389 }
00390 return C;
00391 }
00392
00393
00394
00395 template<long m, long l, long n>
00396 inline zgematrix_small<m,n> operator*(const zgematrix_small<m,l>& A, const zgematrix_small<l,n>& B)
00397 {VERBOSE_REPORT;
00398 zgematrix_small<m,n> C(0.);
00399 for(int i=0; i<m; i++){
00400 for(int j=0; j<n; j++){
00401 for(int k=0; k<l; k++){
00402 C(i,j) +=A(i,k)*B(k,j);
00403 }
00404 }
00405 }
00406 return C;
00407 }
00408
00409
00410
00411 template<long m, long n>
00412 inline zgematrix_small<m,n> operator*(const zgematrix_small<m,n>& A, const zhematrix_small<n>& B)
00413 {VERBOSE_REPORT;
00414 zgematrix_small<m,n> X(0.);
00415 for(long i=0; i<m; i++){
00416 for(long j=0; j<n; j++){
00417 for(long k=0; k<j; k++){
00418 X(i,j) +=A(i,k)*B(j,k);
00419 }
00420 for(long k=j; k<n; k++){
00421 X(i,j) +=A(i,k)*B(k,j);
00422 }
00423 }
00424 }
00425 return X;
00426 }
00427
00428
00429
00430 template<long m, long n>
00431 inline zgematrix_small<m,n> operator*(const zgematrix_small<m,n>& A, const double& v)
00432 {VERBOSE_REPORT;
00433 zgematrix_small<m,n> C;
00434 for(long i=0; i<m; i++){
00435 for(long j=0; j<n; j++){
00436 C(i,j) =A(i,j)*v;
00437 }
00438 }
00439 return C;
00440 }
00441
00442
00443
00444 template<long m, long n>
00445 inline zgematrix_small<m,n> operator*(const zgematrix_small<m,n>& A, const comple& v)
00446 {VERBOSE_REPORT;
00447 zgematrix_small<m,n> C;
00448 for(long i=0; i<m; i++){
00449 for(long j=0; j<n; j++){
00450 C(i,j) =A(i,j)*v;
00451 }
00452 }
00453 return C;
00454 }
00455
00456
00457
00458 template<long m, long n>
00459 inline zgematrix_small<m,n> operator/(const zgematrix_small<m,n>& A, const double& v)
00460 {VERBOSE_REPORT;
00461 zgematrix_small<m,n> C;
00462 for(long i=0; i<m; i++){
00463 for(long j=0; j<n; j++){
00464 C(i,j) =A(i,j)/v;
00465 }
00466 }
00467 return C;
00468 }
00469
00470
00471
00472 template<long m, long n>
00473 inline zgematrix_small<m,n> operator/(const zgematrix_small<m,n>& A, const comple& v)
00474 {VERBOSE_REPORT;
00475 zgematrix_small<m,n> C;
00476 for(long i=0; i<m; i++){
00477 for(long j=0; j<n; j++){
00478 C(i,j) =A(i,j)/v;
00479 }
00480 }
00481 return C;
00482 }