00001
00002
00003 inline _dgbmatrix operator+(const _dgbmatrix& matA, const dgbmatrix& matB)
00004 {VERBOSE_REPORT;
00005 #ifdef CPPL_DEBUG
00006 if(matA.n!=matB.n || matA.m!=matB.m){
00007 ERROR_REPORT;
00008 std::cerr << "These two matrises can not make a summation." << std::endl
00009 << "Your input was (" << matA.m << "x" << matA.n << ") + (" << matB.m << "x" << matB.n << ")." << std::endl;
00010 exit(1);
00011 }
00012 #endif//CPPL_DEBUG
00013
00014 if(matA.kl>=matB.kl && matA.ku>=matB.ku){
00015 for(long i=0; i<matB.m; i++){
00016 for(long j=std::max(long(0),i-matB.kl); j<std::min(matB.n,i+matB.ku+1); j++){
00017 matA(i,j)+=matB(i,j);
00018 }
00019 }
00020
00021 return matA;
00022 }
00023
00024 else{
00025 dgbmatrix newmat(matA.m,matA.n,std::max(matA.kl,matB.kl),std::max(matA.ku,matB.ku));
00026 newmat.zero();
00027
00028 for(long i=0; i<matA.m; i++){
00029 for(long j=std::max(long(0),i-matA.kl); j<std::min(matA.n,i+matA.ku+1); j++){
00030 newmat(i,j)+=matA(i,j);
00031 }
00032 for(long j=std::max(long(0),i-matB.kl); j<std::min(matB.n,i+matB.ku+1); j++){
00033 newmat(i,j)+=matB(i,j);
00034 }
00035 }
00036
00037 matA.destroy();
00038 return _(newmat);
00039 }
00040 }
00041
00042
00043
00044 inline _dgbmatrix operator-(const _dgbmatrix& matA, const dgbmatrix& matB)
00045 {VERBOSE_REPORT;
00046 #ifdef CPPL_DEBUG
00047 if(matA.n!=matB.n || matA.m!=matB.m){
00048 ERROR_REPORT;
00049 std::cerr << "These two matrises can not make a subtraction." << std::endl
00050 << "Your input was (" << matA.m << "x" << matA.n << ") - (" << matB.m << "x" << matB.n << ")." << std::endl;
00051 exit(1);
00052 }
00053 #endif//CPPL_DEBUG
00054
00055 if(matA.kl>=matB.kl && matA.ku>=matB.ku){
00056 for(long i=0; i<matB.m; i++){
00057 for(long j=std::max(long(0),i-matB.kl); j<std::min(matB.n,i+matB.ku+1); j++){
00058 matA(i,j)-=matB(i,j);
00059 }
00060 }
00061
00062 return matA;
00063 }
00064
00065 else{
00066 dgbmatrix newmat(matA.m,matA.n,std::max(matA.kl,matB.kl),std::max(matA.ku,matB.ku));
00067 newmat.zero();
00068
00069 for(long i=0; i<matA.m; i++){
00070 for(long j=std::max(long(0),i-matA.kl); j<std::min(matA.n,i+matA.ku+1); j++){
00071 newmat(i,j)+=matA(i,j);
00072 }
00073 for(long j=std::max(long(0),i-matB.kl); j<std::min(matB.n,i+matB.ku+1); j++){
00074 newmat(i,j)-=matB(i,j);
00075 }
00076 }
00077
00078 return _(newmat);
00079 }
00080 }
00081
00082
00083
00084 inline _dgbmatrix operator*(const _dgbmatrix& matA, const dgbmatrix& matB)
00085 {VERBOSE_REPORT;
00086 #ifdef CPPL_DEBUG
00087 if(matA.n!=matB.m){
00088 ERROR_REPORT;
00089 std::cerr << "These two matrises can not make a product." << std::endl
00090 << "Your input was (" << matA.m << "x" << matA.n << ") * (" << matB.m << "x" << matB.n << ")." << std::endl;
00091 exit(1);
00092 }
00093 #endif//CPPL_DEBUG
00094
00095 dgbmatrix newmat( matA.m, matB.n, std::min(matA.kl+matB.kl,matA.m-1), std::min(matA.ku+matB.ku,matB.n-1) );
00096 newmat.zero();
00097
00098 for(long i=0; i<newmat.m; i++){
00099 for(long j=std::max(long(0),i-newmat.kl); j<std::min(newmat.n,i+newmat.ku+1); j++){
00100 for(long k=std::max( std::max(long(0),i-matA.kl), std::max(long(0),j-matB.ku) );
00101 k< std::min( std::min(matA.n,i+matA.ku+1), std::min(matB.m,j+matB.kl+1) ); k++){
00102 newmat(i,j)+= matA(i,k)*matB(k,j);
00103 }
00104 }
00105 }
00106
00107 matA.destroy();
00108 return _(newmat);
00109 }