00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef ZVector_H
00022 #define ZVector_H
00023
00024 #include <iostream>
00025 #include "lapack_wrapper.h"
00026 #include "blas_wrapper.h"
00027
00028 using namespace std;
00029
00030
00035 class ZVector
00036 {
00037 public:
00038 friend class ZMatrix;
00039
00040 private:
00045 int n_1;
00046
00047
00052 complex<double>* pArray;
00053
00054
00059 int lda;
00060
00061 public:
00067 int dim1(){return n_1;}
00068
00074 int size(){return n_1;}
00075
00080 complex<double>* array(){return pArray;}
00081
00088 void allocate(int i)
00089 {
00090 if( n_1 != i )
00091 {
00092 deallocate();
00093
00094 n_1 = i;
00095
00096 if(n_1 >= 1)
00097 {
00098 pArray = new complex<double>[n_1];
00099 }
00100 else
00101 {
00102 n_1 = 0;
00103 pArray = 0;
00104 }
00105 }
00106
00107 lda = 1;
00108 }
00109
00110
00115 void deallocate()
00116 {
00117 if( n_1 > 0 )
00118 {
00119 delete [] pArray;
00120 pArray = 0;
00121
00122 n_1 = 0;
00123 }
00124 }
00125
00126
00131 double Norm()
00132 {
00133 return F77_FUNC(dznrm2,DZNRM2)(&n_1,(double*)pArray,&lda);
00134 }
00135
00140 double AbsoluteSum()
00141 {
00142 return F77_FUNC(dzasum,DZASUM)(&n_1,(double*)pArray,&lda);
00143 }
00144
00149 complex<double> Sum()
00150 {
00151 complex<double> sum=dcmplx(0.0,0.0);
00152 for(int i=0;i<n_1;i++) sum=sum+pArray[i];
00153 return sum;
00154 }
00155
00156
00161 int iMax()
00162 {
00163 return F77_FUNC(izamax,IZAMAX)(&n_1,(double*)pArray,&lda);
00164 }
00165
00166
00171 void operator=(const ZVector & rhs)
00172 {
00173 if(n_1 != rhs.n_1) allocate(rhs.n_1);
00174 F77_FUNC(zcopy,ZCOPY)(&n_1,(double*)rhs.pArray,&lda,(double*)pArray,&lda);
00175 }
00176
00181 void operator=(const double C)
00182 {
00183 for(int i=0; i<n_1; i++)
00184 {
00185 pArray[i] = dcmplx(C,0);
00186 }
00187 }
00188
00193 void operator=(const complex<double> C)
00194 {
00195 for(int i=0; i<n_1; i++)
00196 {
00197 pArray[i] = C;
00198 }
00199 }
00200
00205 complex<double> zdotu(const ZVector & rhs)
00206 {
00207 #ifdef DEBUG
00208 if( n_1 != rhs.n_1 )
00209 {
00210 cerr << "ERROR: incorrect sizes for two ZVector's in ZVector*"
00211 << "ZVector" << endl;
00212 exit(1);
00213 }
00214 if( n_1 <= 0 )
00215 {
00216 cerr << "ERROR: ZVector of size 0 used in ZVector*ZVector" << endl;
00217 exit(1);
00218 }
00219 #endif
00220 return F77_FUNC(zdotu,ZDOTU)(&n_1,(double*)pArray,&lda,(double*)rhs.pArray,&lda);
00221 }
00222
00223 complex<double> zdotc(const ZVector & rhs)
00224 {
00225 #ifdef DEBUG
00226 if( n_1 != rhs.n_1 )
00227 {
00228 cerr << "ERROR: incorrect sizes for two ZVector's in ZVector*"
00229 << "ZVector" << endl;
00230 exit(1);
00231 }
00232 if( n_1 <= 0 )
00233 {
00234 cerr << "ERROR: ZVector of size 0 used in ZVector*ZVector" << endl;
00235 exit(1);
00236 }
00237 #endif
00238 return F77_FUNC(zdotc,ZDOTC)(&n_1,(double*)pArray,&lda,(double*)rhs.pArray,&lda);
00239 }
00240
00245 ZVector operator+( const ZVector & rhs)
00246 {
00247 #ifdef DEBUG
00248 if( n_1 != rhs.n_1 )
00249 {
00250 cerr << "ERROR: incorrect sizes for two ZVector's in ZVector+"
00251 << "ZVector" << endl;
00252 exit(1);
00253 }
00254 if( n_1 <= 0 )
00255 {
00256 cerr << "ERROR: ZVector of size 0 used in ZVector+ZVector" << endl;
00257 exit(1);
00258 }
00259 #endif
00260 ZVector A(n_1);
00261 double d_one=1.0;
00262 F77_FUNC(zcopy,ZCOPY)(&n_1,(double*)pArray,&lda,(double*)A.pArray,&lda);
00263 F77_FUNC(zaxpy,ZAXPY)(&n_1,&d_one,(double*)rhs.pArray,&lda,(double*)A.pArray,&lda);
00264 return A;
00265 }
00266
00267
00272 ZVector operator-( const ZVector & rhs)
00273 {
00274 #ifdef DEBUG
00275 if( n_1 != rhs.n_1 )
00276 {
00277 cerr << "ERROR: incorrect sizes for two ZVector's in ZVector-"
00278 << "ZVector" << endl;
00279 exit(1);
00280 }
00281 if( n_1 <= 0 )
00282 {
00283 cerr << "ERROR: ZVector of size 0 used in ZVector-ZVector" << endl;
00284 exit(1);
00285 }
00286 #endif
00287 ZVector A(n_1);
00288 complex<double> d_m_one(-1.0,0.0);
00289 F77_FUNC(zcopy,ZCOPY)(&n_1,(double*)pArray,&lda,(double*)A.pArray,&lda);
00290 F77_FUNC(zaxpy,ZAXPY)(&n_1,(double*)&d_m_one,(double*)rhs.pArray,&lda,(double*)A.pArray,&lda);
00291 return A;
00292 }
00293
00294
00299 void operator*=(complex<double> C)
00300 {
00301 F77_FUNC(zscal,ZSCAL)(&n_1,(double*)&C,(double*)pArray,&lda);
00302 }
00303
00304
00309 void operator/=(complex<double> C)
00310 {
00311 complex<double> inv=1.0/C;
00312 F77_FUNC(zscal,ZSCAL)(&n_1,(double*)&inv,(double*)pArray,&lda);
00313 }
00314
00315
00320 ZVector(){pArray = 0; n_1 = 0; lda=1;}
00321
00322
00329 ZVector(int i){pArray = 0; n_1 = 0; allocate(i); lda=1; }
00330
00331
00338 ZVector(const ZVector & rhs)
00339 {
00340 n_1 = 0;
00341 pArray = 0;
00342 lda = 1;
00343 allocate(rhs.n_1);
00344 F77_FUNC(zcopy,ZCOPY)(&n_1,(double*)rhs.pArray,&lda,(double*)pArray,&lda);
00345 }
00346
00351 ~ZVector(){deallocate();}
00352
00356 complex<double>& operator()(int i){return pArray[i];}
00357
00362 friend ostream& operator<<(ostream & strm, const ZVector & rhs)
00363 {
00364 for( int i=0; i<rhs.n_1; i++ )
00365 {
00366 strm << rhs.pArray[i] << "\t";
00367 }
00368 strm << endl;
00369 return strm;
00370 }
00371
00372 };
00373
00374 #endif
00375
00376
00377
00378
00379
00380