00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef ZMatrix_H
00023 #define ZMatrix_H
00024 #if HAVE_CONFIG
00025 #include <config.h>
00026 #endif
00027
00028 #include <iostream>
00029 #include "ZVector.h"
00030 #include "lapack_wrapper.h"
00031 #include "blas_wrapper.h"
00032
00033
00034 using namespace std;
00035
00036
00043 class ZMatrix
00044 {
00045 private:
00050 int n_1;
00051
00052
00057 int n_2;
00058
00063 complex<double>* pArray;
00064
00069 complex<double>* tmpArray;
00070
00074 complex<double> temp;
00075
00079 int one;
00080
00081 public:
00087 int dim1(){return n_1;}
00088
00094 int dim2(){return n_2;}
00095
00101 int size(){return n_1*n_2;}
00102
00107 complex<double>* array(){return pArray;}
00108
00113 void transpose()
00114 {
00115 if(n_1 !=n_2)
00116 {
00117 cerr << " Transpose only for square matrix ! " << endl;
00118 exit(1);
00119 }
00120 for(int i=0;i<n_1;i++)
00121 for(int j=0;j<i;j++)
00122 {
00123 temp=pArray[j+i*n_1];
00124 pArray[j+i*n_1]=pArray[i+j*n_1];
00125 pArray[i+j*n_1]=temp;
00126 }
00127 }
00128
00136 void allocate(int i, int j)
00137 {
00138 if( n_1 != i || n_2 != j )
00139 {
00140 deallocate();
00141
00142 n_1 = i;
00143 n_2 = j;
00144
00145 if(n_1 >= 1 && n_2 >= 1)
00146 pArray = new complex<double> [n_1*n_2];
00147 else
00148 pArray = 0;
00149 }
00150 }
00151
00156 void deallocate()
00157 {
00158 if(n_2>0 && n_1>0)
00159 {
00160 delete [] pArray;
00161 }
00162 pArray = 0;
00163
00164 n_1 = 0;
00165 n_2 = 0;
00166 }
00167
00168
00173 void operator=(const ZMatrix & rhs)
00174 {
00175 int tot=n_1*n_2;
00176 #ifdef DEBUG
00177 if(n_1 != rhs.n_1 || n_2 != rhs.n_2) allocate(rhs.n_1,rhs.n_2);
00178 #endif
00179
00180 F77_FUNC(zcopy,ZCOPY)(&tot,(double*)rhs.pArray,&one,(double*)pArray,&one);
00181 }
00182
00183
00188 void operator=(const complex<double> C)
00189 {
00190 for(int i=0; i<n_1*n_2;i++) pArray[i] = C;
00191 }
00192
00197 void operator=(const double C)
00198 {
00199 for(int i=0; i<n_1*n_2;i++) pArray[i] = dcmplx(C,0);
00200 }
00201
00207 void operator*=(complex<double> C)
00208 {
00209 int tot=n_1*n_2;
00210 F77_FUNC(zscal,ZSCAL)(&tot,(double*)&C,(double*)pArray,&one);
00211 }
00212
00217 void operator/=(const complex<double> C)
00218 {
00219 int tot=n_1*n_2;
00220 complex<double> inv=dcmplx(1.0,0.0)/C;
00221 F77_FUNC(zscal,ZSCAL)(&tot,(double*)&inv,(double*)pArray,&one);
00222 }
00223
00224
00229 ZMatrix(){pArray = 0; n_1 = 0; n_2 = 0; one = 1;}
00230
00231
00239 ZMatrix(int i, int j) {pArray = 0; n_1 = 0; n_2 = 0; one=1; allocate(i,j);}
00240
00241
00248 ZMatrix( const ZMatrix & rhs)
00249 {
00250 n_1 = 0;
00251 n_2 = 0;
00252 pArray = 0;
00253 allocate(rhs.n_1,rhs.n_2);
00254 int tot=n_1*n_2;
00255 one=1;
00256 F77_FUNC(zcopy,ZCOPY)(&tot,(double*)rhs.pArray,&one,(double*)pArray,&one);
00257 }
00258
00259
00264 ~ZMatrix(){deallocate();}
00265
00269 complex<double> SumAll()
00270 {
00271 complex<double> sum=0;
00272 for(int i=0;i<n_1*n_2;i++) sum+=pArray[i];
00273 return sum;
00274 }
00275
00279 complex<double> Trace()
00280 {
00281 #ifdef DEBUG
00282 if(n_1 !=n_2)
00283 {
00284 cerr << " Trace only for Squared ZMatrix ! " << endl;
00285 exit(1);
00286 }
00287 #endif
00288 complex<double> sum=0;
00289 for(int i=0;i<n_1;i++) sum+=pArray[i*n_1+i];
00290 return sum;
00291 }
00292
00296 void setrow(int irow,ZVector &vector)
00297 {
00298 #ifdef DEBUG
00299 if(vector.n_1!=n_2 || irow>=n_1)
00300 {
00301 cerr << " ERROR! dimension array copying row! " << endl;
00302 exit(1);
00303 }
00304 #endif
00305 F77_FUNC(zcopy,ZCOPY)(&n_2,(double*)vector.pArray,&one,(double*)(pArray+irow),&n_1);
00306 }
00307
00329
00360
00378
00393
00409
00425
00440
00476
00491
00511
00528
00545
00563
00585
00613
00641
00659