/*! _zssmatrix-_zgbmatrix operator */ inline _zgematrix operator-(const _zssmatrix& matA, const _zgbmatrix& matB) { #ifdef CPPL_VERBOSE std::cerr << "# [MARK] operator-(const _zssmatrix&, const _zgbmatrix&)" << std::endl; #endif//CPPL_VERBOSE #ifdef CPPL_DEBUG if(matA.N!=matB.N || matA.M!=matB.M){ std::cerr << "[ERROR] operator+(const _zssmatrix&, const _zgbmatrix&)" << std::endl << "These two matrises can not make a summation." << std::endl << "Your input was (" << matA.M << "x" << matA.N << ") + (" << matB.M << "x" << matB.N << ")." << std::endl; exit(1); } #endif//CPPL_DEBUG zgematrix newmat(matA); for(long i=0; i<matB.M; i++){ for(long j=max(0,i-matB.KL); j<min(matB.N,i+matB.KU+1); j++){ newmat(i,j)-=matB(i,j); } } matA.destroy(); matB.destroy(); return _(newmat); }
/*! _zssmatrix*_zgbmatrix operator */ inline _zgematrix operator*(const _zssmatrix& matA, const _zgbmatrix& matB) { #ifdef CPPL_VERBOSE std::cerr << "# [MARK] operator*(const _zssmatrix&, const _zgbmatrix&)" << std::endl; #endif//CPPL_VERBOSE #ifdef CPPL_DEBUG if(matA.N!=matB.M){ std::cerr << "[ERROR] operator*(const _zssmatrix&, const _zgbmatrix&)" << std::endl << "These two matrises can not make a product." << std::endl << "Your input was (" << matA.M << "x" << matA.N << ") * (" << matB.M << "x" << matB.N << ")." << std::endl; exit(1); } #endif//CPPL_DEBUG zgematrix newmat( matA.M, matB.N ); newmat.zero(); for(long c=0; c<matA.VOL; c++){ for(long k=max(0,matA.Jndx[c]-matB.KU); k<min(matB.M,matA.Jndx[c]+matB.KL+1); k++){ newmat(matA.Indx[c],k) += matA.Array[c]*matB(matA.Jndx[c],k); } } matA.destroy(); matB.destroy(); return _(newmat); }
/*! zhematrix*_zgbmatrix operator */ inline _zgematrix operator*(const zhematrix& matA, const _zgbmatrix& matB) { #ifdef CPPL_VERBOSE std::cerr << "# [MARK] operator*(const zhematrix&, const _zgbmatrix&)" << std::endl; #endif//CPPL_VERBOSE #ifdef CPPL_DEBUG if(matA.N!=matB.M){ std::cerr << "[ERROR] operator*(zhematrix&, _zgbmatrix&)" << std::endl << "These two matrises can not make a product." << std::endl << "Your input was (" << matA.N << "x" << matA.N << ") * (" << matB.M << "x" << matB.N << ")." << std::endl; exit(1); } #endif//CPPL_DEBUG zgematrix newmat( matA.N, matB.N ); newmat.zero(); long i, j, k; for(i=0; i<newmat.m; i++){ for(j=0; j<newmat.n; j++){ for(k=max(0,j-matB.KU); k<min(matB.M,j+matB.KL+1); k++){ newmat(i,j)+=matA(i,k)*matB(k,j); } } } matB.destroy(); return _(newmat); }
/*! _zrovector*_zgbmatrix operator */ inline _zrovector operator*(const _zrovector& vec, const _zgbmatrix& mat) { #ifdef CPPL_VERBOSE std::cerr << "# [MARK] operator*(const _zrovector&, const _zgbmatrix&)" << std::endl; #endif//CPPL_VERBOSE #ifdef CPPL_DEBUG if(vec.L!=mat.M){ std::cerr << "[ERROR] operator*(const zrovector&, const _zgbmatrix&)" << std::endl << "These vector and matrix can not make a product." << std::endl << "Your input was (" << vec.L << ") * (" << mat.M << "x" << mat.N << ")." << std::endl; exit(1); } #endif//CPPL_DEBUG zrovector newvec(mat.N); zgbmv_( 'T', mat.M, mat.N, mat.KL, mat.KU, std::complex<double>(1.0,0.0), mat.Array, mat.KL+mat.KU+1, vec.Array, 1, std::complex<double>(0.0,0.0), newvec.array, 1 ); vec.destroy(); mat.destroy(); return _(newvec); }
/*! _zgematrix*_zgbmatrix operator */ inline _zgematrix operator*(const _zgematrix& matA, const _zgbmatrix& matB) {VERBOSE_REPORT; #ifdef CPPL_DEBUG if(matA.n!=matB.m){ ERROR_REPORT; std::cerr << "These two matrises can not make a product." << std::endl << "Your input was (" << matA.m << "x" << matA.n << ") * (" << matB.m << "x" << matB.n << ")." << std::endl; exit(1); } #endif//CPPL_DEBUG zgematrix newmat( matA.m, matB.n ); newmat.zero(); for(long i=0; i<newmat.m; i++){ for(long j=0; j<newmat.n; j++){ for(long k=std::max(long(0),j-matB.ku); k<std::min(matB.m,j+matB.kl+1); k++){ newmat(i,j)+=matA(i,k)*matB(k,j); } } } matA.destroy(); matB.destroy(); return _(newmat); }
/*! zgematrix constructor to cast _zgbmatrix */ inline zgematrix::zgematrix(const _zgbmatrix& mat) : m(M), n(N), array(Array), darray(Darray) { #ifdef CPPL_VERBOSE std::cerr << "# [MARK] zgematrix::zgematrix(const _zgbmatrix&)" << std::endl; #endif//CPPL_VERBOSE //////// initialize //////// M =mat.M; N =mat.N; Array =new std::complex<double>[M*N]; Darray =new std::complex<double>*[N]; for(int i=0; i<N; i++){ Darray[i] =&Array[i*M]; } //////// copy //////// zero(); for(long i=0; i<mat.M; i++){ for(long j=max(0,i-mat.KL); j<min(N,i+mat.KU+1); j++){ operator()(i,j) =mat(i,j); } } mat.destroy(); #ifdef CPPL_DEBUG std::cerr << "# [NOTE] zgematrix::zgematrix(const zgbmatrix&) " << "A new matrix at " << Array << " has been made." << std::endl; #endif//CPPL_DEBUG }
/*! _zgbmatrix-_zhematrix operator */ inline _zgematrix operator-(const _zgbmatrix& matA, const _zhematrix& matB) {VERBOSE_REPORT; #ifdef CPPL_DEBUG if(matA.m!=matB.n || matA.n!=matB.n){ ERROR_REPORT; std::cerr << "These two matrises can not make a summation." << std::endl << "Your input was (" << matA.m << "x" << matA.n << ") + (" << matB.n << "x" << matB.n << ")." << std::endl; exit(1); } #endif//CPPL_DEBUG zgematrix newmat(matB.n, matB.n); for(long i=0; i<newmat.m; i++){ for(long j=0; j<newmat.n; j++){ newmat(i,j)=-matB(i,j); } for(long j=std::max(long(0),i-matA.kl); j<std::min(matA.n,i+matA.ku+1); j++){ newmat(i,j)+=matA(i,j); } } matA.destroy(); matB.destroy(); return _(newmat); }
/*! return its conjugate transposed zgbmatrix */ inline _zgbmatrix conjt(const _zgbmatrix& mat) {VERBOSE_REPORT; zgbmatrix newmat(mat.n, mat.m, mat.ku, mat.kl); for(long i=0; i<newmat.m; i++){ for(long j=std::max(long(0),i-newmat.kl); j<std::min(newmat.n,i+newmat.ku+1); j++){ newmat(i,j) =std::conj(mat(j,i)); } } mat.destroy(); return _(newmat); }
/*! _zgbmatrix*zcovector operator */ inline _zcovector operator*(const _zgbmatrix& mat, const zcovector& vec) {VERBOSE_REPORT; #ifdef CPPL_DEBUG if(mat.n!=vec.l){ ERROR_REPORT; std::cerr << "These matrix and vector can not make a product." << std::endl << "Your input was (" << mat.m << "x" << mat.n << ") * (" << vec.l << ")." << std::endl; exit(1); } #endif//CPPL_DEBUG zcovector newvec(mat.m); zgbmv_( 'n', mat.m, mat.n, mat.kl, mat.ku, comple(1.0,0.0), mat.array, mat.kl+mat.ku+1, vec.array, 1, comple(0.0,0.0), newvec.array, 1 ); mat.destroy(); return _(newvec); }
/*! zgsmatrix*_zgbmatrix operator */ inline _zgematrix operator*(const zgsmatrix& matA, const _zgbmatrix& matB) { VERBOSE_REPORT; #ifdef CPPL_DEBUG if(matA.n!=matB.m) { ERROR_REPORT; std::cerr << "These two matrises can not make a product." << std::endl << "Your input was (" << matA.m << "x" << matA.n << ") * (" << matB.m << "x" << matB.n << ")." << std::endl; exit(1); } #endif//CPPL_DEBUG zgematrix newmat( matA.m, matB.n ); newmat.zero(); for(std::vector<zcomponent>::const_iterator it=matA.data.begin(); it!=matA.data.end(); it++) { for(long j=std::max(0l,long(it->j)-matB.kl); j<std::min(matB.n,long(it->j)+matB.ku+1); j++) { newmat(it->i,j) += it->v*matB(it->j,j); } } matB.destroy(); return _(newmat); }
/*! _zgbmatrix*zhematrix operator */ inline _zgematrix operator*(const _zgbmatrix& matA, const zhematrix& matB) {VERBOSE_REPORT; #ifdef CPPL_DEBUG if(matA.n!=matB.m){ ERROR_REPORT; std::cerr << "These two matrises can not make a product." << std::endl << "Your input was (" << matA.m << "x" << matA.n << ") * (" << matB.m << "x" << matB.n << ")." << std::endl; exit(1); } #endif//CPPL_DEBUG zgematrix newmat( matA.m, matB.n ); newmat.zero(); for(long c=0; c<matB.vol; c++){ for(long i=max(0,matB.indx[c]-(matA.ku+1)); i<min(matA.m,matB.indx[c]+matA.kl); i++){ newmat(i,matB.jndx[c]) += matA(i,matB.indx[c])*matB.array[c]; } } matA.destroy(); return _(newmat); }