// g++ -D _GLIBCPP_NO_TEMPLATE_EXPORT -g testblas.cc testblas2.cc nrutil_modif.cc -L/usr/local/lib/atlas -lstrassen -lf77blas -lcblas -latlas -ltraceback -lbfd -liberty #include #include "la.h" #include "traceback.h" #include "sparsemat.h" #include "matexp.h" #include "fourindex.h" #include "davidson.h" #include "gmres.h" #include "conjgrad.h" extern void test(const NRVec &x); double ad; void f1(const double *c) { ad=*c; } void f2(double *c) { *c=ad; } inline int randind(const int n) { return int(random()/(1.+RAND_MAX)*n); } complex mycident (const complex&x) {return x;} int main() { sigtraceback(SIGSEGV,1); sigtraceback(SIGABRT,1); sigtraceback(SIGBUS,1); sigtraceback(SIGFPE,1); NRVec x(1.,10); NRVec y(2.,10); NRVec z(-2.,10); cout.setf(ios::fixed); cout.precision(12); if(0) test(x); y.axpy(3,x); y+=z; /* cout < a(x); NRVec b; b|=x; NRVec c; c=a; y =10. *y ; int i; for(i=0;i u; u=x+y; cout <<"u= "< aa(0.,3,3); aa[0][0]=aa[1][1]=aa(2,2)=2.; NRMat bb(aa); double *p; aa.copyonwrite(); p= &aa[2][2]; *p=3.; bb.copyonwrite(); bb(0,2)=1.; cout << "aa= " < cc=aa & bb; cout << "aa o+ bb= " << cc <<"\n"; cout << cc.rsum() <<"\n"; cout << cc.csum() <<"\n"; NRVecw(3); w[0]=1; w[1]=2;w[2]=3; NRVec v(0.,3); v.gemv(0.,bb,'n',1.,w); cout << " v= " < bb(1.,n,n); for(int i=0;i amat,bmat,cmat; cin >>amat; cin >>bmat; cmat=amat*bmat; cout< amat(1.,2,2); NRMat bmat(amat); NRMat dmat(amat); //NRMat cmat; cmat=bmat*2.; NRMat cmat(bmat*2); //more efficient dmat.copyonwrite(); dmat[0][0]=0; cout< amat; NRVec avec; cin >>amat; cin >>avec; cout << amat*avec; cout << avec*amat; NRVec avec(0.,10); f1(avec); f2(avec); NRVec uu(3); uu[0]=1; uu[1]=2; uu[2]=3; cout << uu << (uu|uu) <<"\n"; NRSMat sa(0.,3); sa(0,0)=1; sa(0,2)=5; sa(2,2)=10;sa(1,0)=2;sa(1,1)=3; sa(2,1)=-1; NRSMat sb(0.,3); sb(0,0)=-2; sb(0,2)=1; sb(2,2)=2;sb(1,0)=-1;sb(1,1)=7; sb(2,1)=3; cout << "symetr\n" < m10(10.,3,3); cout << "10 + sa" << m10 + sa <<"\n"; */ /* const int dim=256; NRMat big1(dim,dim),big2(dim,dim),big3; for(int i=0;i atest, btest,ctest; { int cc,c1,c2,c3; cin >>cc>>c1>>c2>>c3; atest.s_cutoff(cc,c1,c2,c3); } cin>>atest; cin>>btest; NRMat dtest(atest.nrows(),btest.ncols()); dtest.gemm(0., atest, 't', btest, 'n', 1.); cout << dtest; NRMat etest(atest.nrows(),btest.ncols()); etest.strassen(0., atest, 't', btest, 'n', 1.); cout << etest; */ if(0) { int dim; cin >>dim; NRMat big1(dim,dim),big2(dim,dim),big3,big4(dim,dim); for(int i=0;i a(3,3),b; NRVec v(3); for(int i=0;i<3;i++) for(int j=0;j<3;j++) { a[i][j]= i*i+j; v[i]=10-i;} b=a; b*= sin(1.)+1; cout << a < a(3,3),b; NRVec v(10); v[0]=2;v[1]=3;v[2]=1;v[3]=-3;v[4]=2;v[5]=-1;v[6]=3;v[7]=-2;v[8]=1;v[9]=1; for(int i=0;i<3;i++) for(int j=0;j<3;j++) { a[i][j]= (i+j)/10.; } cout < a(3,3); for(int i=0;i<3;i++) for(int j=0;j<3;j++) { a[i][j]= (i+j)/10.; } NRSMat b(a); NRMat c(b); cout < a(3,3); a[0][0]=1; a[0][1]=2;a[0][2]=3; a[1][0]=4; a[1][1]=-5;a[1][2]=7; a[2][0]=-3;a[2][1]=10;a[2][2]=2; NRMat b(2,3); b[0][0]=1;b[0][1]=2;b[0][2]=3; b[1][0]=2;b[1][1]=4;b[1][2]=6; cout < a(3,3); for(int i=0;i<3;i++) for(int j=0;j<3;j++) { a[i][j]= (i+j)/10.; } NRVec b(3); cout < a(3); NRMatv(3,3); for(int i=0;i<3;i++) for(int j=0;j<3;j++) { a(i,j)= (i+j)/10.; } NRVec b(3); cout <c=(NRMat)a; //nebo NRMatc(a); NRMatd=exp(c); diagonalize(a,b,&v); cout < a; cin >>a ; NRMat b=a.transpose(); NRMat u(a.nrows(),a.nrows()),v(a.ncols(),a.ncols()); NRVecs(a.ncols()); singular_decomposition(a,&u,s,&v); //singular_decomposition(a,NULL,s,NULL); //this does not work when linked with static version of lapack, works with .so.3 version (from suse distrib) cout < a(aa,3,3); NRMat a; cin >>a; cout < u(n,n),v(n,n); NRVecwr(n),wi(n); gdiagonalize(a,wr,wi,&u,&v,0); cout <z=diagofproduct(u,v,1); for(int i=0;i a; cin >>a; cout < > u(n,n),v(n,n); NRVec >w(n); gdiagonalize(a,w,&u,&v); cout < >z=diagofproduct(u,v,1,1); //NRMat > zz=u*v.transpose(1); cout < a(4,4); NRVec v(4); v[0]=1;v[1]=2;v[2]=3;v[3]=4; a=1.; a.copyonwrite(); a.add(3,0,.5); a.add(0,2,.2); a.add(2,1,.1); a.add(3,3,1.); a.add(1,1,-1.); SparseMat c(a); c*=10.; cout <b(c); cout < a(4,4),b(4,4); a=1.; a.copyonwrite(); a.add(3,0,.5); b.add(0,2,.2); b.add(2,1,.1); b.add(3,3,1.); b.add(1,1,-1.); SparseMatc=a+b; cout < a(4,4),b(4,4); a=0.; b=2; a.add(3,0,.5); a.add(0,2,.2); a.add(1,1,1); a.add(1,0,.2); b.add(2,1,.1); b.add(3,3,1.); b.add(1,1,-1.); NRMat aa(a),bb(b); SparseMatc; NRMatcc; //cout << NRMat(c); //cout <(c); cout <<"norms2 "< aa(n,n); cout << "\n\n\ntiming for size "< a(0.,n,n); for(int i=0; i b(exp(a)); //cout <(a); } else { for(int i=0; i bb(exp(aa)); //cout <>n; SparseMat aa(n,n); for(int i=0; i bb=exp(aa); NRVec v(n); for(int i=0; i res1=bb*v; NRVec res2=exptimes(aa,v); cout <<"difference = "<<(res1-res2).norm()< a(4,4),b(4,4),d; a=0.; b=2; a.add(3,0,.5); a.add(0,2,.2); a.add(1,1,1); a.add(1,0,.2); b.add(2,1,.1); b.add(3,3,1.); b.add(1,1,-1.); NRMat aa(a),bb(b),dd; SparseMatc; NRMatcc; c=commutator(a,b); cc=commutator(aa,bb); cout <(c); cout <<"norms2 "< v(10.,10); v+= 5.; cout < a(n,n); for(int i=0;i b; b|=a; NRVec er(n),ei(n); NRMat vr(n,n),vl(n,n); gdiagonalize(b,er,ei,&vl,&vr); cout < u=exp(a*.125); cout <<"norms "<>n; NRMat a(n,n); for(int i=0;i b=exp(a); cout < a,b; cin >>b; int n=b.nrows(); cout <<"difference from identity = "< x(0.,n,n),x0; double r; int i=0; do { x0=x; NRMat y=exp(x*-.5); x+= y*b*y; x-= 1.; x=(x-x.transpose())*.5; cout <<"matrix x\n"<1e-10); cout <<"result\n"< c=log(b); //matrixfunction(a,&mycident,1); cout < d=exp(c); cout <<"exp(log(x))\n"<>n; NRMat a(n,n); for(int i=0;i b=exp(a); NRMat s=exp(a*.5); NRMat y(0.,n,n); NRMat z(0.,n,n); double r; int i=0; y=b;z=1.; cout << "norm = "< tmp=z*y*-1.+3.; NRMat ynew=y*tmp*.5; z=tmp*z*.5; y=ynew; cout <<"iter "<1e-10); } if(0) { int n=3; NRMat a(n,n); a(0,0)=1.; a(0,1)=2.; a(1,0)=2.; a(1,1)=6.; a(2,2)=-4; a(0,2)=1; cout < c=inverse(a,&d); cout < a(3,3); NRMat b=a; for(int i=1; i<4;i++) b=b*b; } if(0) { NRMat a; cin >>a; NRMat b=exp(a); NRMat c=log(b); cout < a; cin >>a; NRMat c=log(a); //matrixfunction(a,&mycident,1); cout < b=exp(c); cout <<"exp(log(x))\n"< a; cin >>a; NRMat aa(a); NRMat b=exp(aa); NRMat c=matrixfunction(a,&exp); cout < h; NRMat t; cin >>h; cin >>t; NRMat r1= exp(-t) * h * exp(t); NRMat r2=BCHexpansion(h,t,30); cout < amat,bmat; cin >>amat; cin >>bmat; NRVec v(amat.nrows()); gendiagonalize(amat,v,bmat,2); cout <>n >>m; NRMat a(n,n); NRVec rr(n); for(int i=0;i aa=a; diagonalize(aa,rr); NRVec r(m); NRVec *eivecs = new NRVec[m]; davidson(a,r,eivecs,m,1); cout <<"Davidson energies " <>n >>m; NRMat a(n,m); NRVec b(n); NRVec x(m); for(int i=0;i bb=b; //cout <aa=a; linear_solve(aa,bb); //cout <