00001
00004 inline zgbmatrix& zgbmatrix::operator=(const zgbmatrix& mat)
00005 {
00006 #ifdef CPPL_VERBOSE
00007 std::cerr << "# [MARK] zgbmatrix::operator=(const zgbmatrix&)"
00008 << std::endl;
00009 #endif//CPPL_VERBOSE
00010
00011 if(Array!=mat.Array){
00012 copy(mat);
00013 }
00014 return *this;
00015 }
00016
00020
00021
00024 inline zgbmatrix& zgbmatrix::operator+=(const zgbmatrix& mat)
00025 {
00026 #ifdef CPPL_VERBOSE
00027 std::cerr << "# [MARK] zgbmatrix::operator+=(const zgbmatrix&)"
00028 << std::endl;
00029 #endif//CPPL_VERBOSE
00030
00031 #ifdef CPPL_DEBUG
00032 if(N!=mat.N || M!=mat.M){
00033 std::cerr << "[ERROR] zgbmatrix::operator+=(zgbmatrix&)" << std::endl
00034 << "These two matrises can not make a summation." << std::endl
00035 << "Your input was"
00036 << "(" << M <<"x"<< N <<","<< KL <<":"<< KU << ") "<< "+="
00037 << "("<< mat.M <<"x"<< mat.N <<","<< mat.KL <<":"<< mat.KU <<") "
00038 << std::endl;
00039 exit(1);
00040 }
00041 #endif//CPPL_DEBUG
00042
00043 if(KL>=mat.KL && KU>=mat.KU){
00044 for(long i=0; i<M; i++){
00045 for(long j=max(0,i-mat.KL); j<min(N,i+mat.KU+1); j++){
00046 operator()(i,j)+=mat(i,j);
00047 }
00048 }
00049
00050 return *this;
00051 }
00052
00053 else{
00054 zgbmatrix newmat(M,N,max(KL,mat.KL),max(KU,mat.KU));
00055 newmat.zero();
00056 for(long i=0; i<M; i++){
00057 for(long j=max(0,i-KL); j<min(N,i+KU+1); j++){
00058 newmat(i,j)+=operator()(i,j);
00059 }
00060 for(long j=max(0,i-mat.KL); j<min(mat.N,i+mat.KU+1); j++){
00061 newmat(i,j)+=mat(i,j);
00062 }
00063 }
00064
00065 swap(*this,newmat);
00066 return *this;
00067 }
00068 }
00069
00070
00073 inline zgbmatrix& zgbmatrix::operator-=(const zgbmatrix& mat)
00074 {
00075 #ifdef CPPL_VERBOSE
00076 std::cerr << "# [MARK] zgbmatrix::operator-=(const zgbmatrix&)"
00077 << std::endl;
00078 #endif//CPPL_VERBOSE
00079
00080 #ifdef CPPL_DEBUG
00081 if(N!=mat.N || M!=mat.M){
00082 std::cerr << "[ERROR] zgbmatrix::operator-=(zgbmatrix&)" << std::endl
00083 << "These two matrises can not make a subtraction." << std::endl
00084 << "Your input was"
00085 << "(" << M <<"x"<< N <<","<< KL <<":"<< KU << ") "<< "-="
00086 << "("<< mat.M <<"x"<< mat.N <<","<< mat.KL <<":"<< mat.KU <<") "
00087 << std::endl;
00088 exit(1);
00089 }
00090 #endif//CPPL_DEBUG
00091
00092 if(KL>=mat.KL && KU>=mat.KU){
00093 for(long i=0; i<M; i++){
00094 for(long j=max(0,i-mat.KL); j<min(N,i+mat.KU+1); j++){
00095 operator()(i,j)-=mat(i,j);
00096 }
00097 }
00098
00099 return *this;
00100 }
00101
00102 else{
00103 zgbmatrix newmat(M,N,max(KL,mat.KL),max(KU,mat.KU));
00104 newmat.zero();
00105 for(long i=0; i<M; i++){
00106 for(long j=max(0,i-KL); j<min(N,i+KU+1); j++){
00107 newmat(i,j)+=operator()(i,j);
00108 }
00109 for(long j=max(0,i-mat.KL); j<min(mat.N,i+mat.KU+1); j++){
00110 newmat(i,j)-=mat(i,j);
00111 }
00112 }
00113
00114 swap(*this,newmat);
00115 return *this;
00116 }
00117 }
00118
00119
00121 inline zgbmatrix& zgbmatrix::operator*=(const zgbmatrix& mat)
00122 {
00123 #ifdef CPPL_VERBOSE
00124 std::cerr << "# [MARK] zgbmatrix::operator*=(const zgbmatrix&)"
00125 << std::endl;
00126 #endif//CPPL_VERBOSE
00127
00128 #ifdef CPPL_DEBUG
00129 if(N!=mat.M){
00130 std::cerr << "[ERROR] zgbmatrix::operator*=(zgbmatrix&)" << std::endl
00131 << "These two matrises can not make a product." << std::endl
00132 << "Your input was (" << M << "x" << N << ") * ("
00133 << mat.M << "x" << mat.N << ")." << std::endl;
00134 exit(1);
00135 }
00136 #endif//CPPL_DEBUG
00137
00138 zgbmatrix newmat( M, mat.N, KU+mat.KL-1, KL+mat.KU+1 );
00139 newmat.zero();
00140
00141 for(long i=0; i<newmat.M; i++){
00142 for(long j=max(0,i-newmat.kl); j<min(newmat.n,i+newmat.ku+1); j++){
00143 for(long k=max( max(0,i-KL), max(0,j-mat.KU) );
00144 k< min( min(N,i+KU+1), min(mat.M,j+mat.KL+1) ); k++){
00145 newmat(i,j)+= operator()(i,k)*mat(k,j);
00146 }
00147 }
00148 }
00149
00150 swap(*this,newmat);
00151 return *this;
00152 }
00153
00157
00158
00160 inline _zgbmatrix operator+(const zgbmatrix& matA, const zgbmatrix& matB)
00161 {
00162 #ifdef CPPL_VERBOSE
00163 std::cerr << "# [MARK] operator+(const zgbmatrix&, const zgbmatrix&)"
00164 << std::endl;
00165 #endif//CPPL_VERBOSE
00166
00167 #ifdef CPPL_DEBUG
00168 if(matA.N!=matB.N || matA.M!=matB.M){
00169 std::cerr << "[ERROR] operator+(zgbmatrix&, zgbmatrix&)" << std::endl
00170 << "These two matrises can not make a summation." << std::endl
00171 << "Your input was (" << matA.M << "x" << matA.N << ") + ("
00172 << matB.M << "x" << matB.N << ")." << std::endl;
00173 exit(1);
00174 }
00175 #endif//CPPL_DEBUG
00176
00177 zgbmatrix newmat(matA.M,matA.N,max(matA.KL,matB.KL),max(matA.KU,matB.KU));
00178 newmat.zero();
00179
00180 for(long i=0; i<matA.M; i++){
00181 for(long j=max(0,i-matA.KL); j<min(matA.N,i+matA.KU+1); j++){
00182 newmat(i,j)+=matA(i,j);
00183 }
00184 for(long j=max(0,i-matB.KL); j<min(matB.N,i+matB.KU+1); j++){
00185 newmat(i,j)+=matB(i,j);
00186 }
00187 }
00188
00189 return _(newmat);
00190 }
00191
00192
00194 inline _zgbmatrix operator-(const zgbmatrix& matA, const zgbmatrix& matB)
00195 {
00196 #ifdef CPPL_VERBOSE
00197 std::cerr << "# [MARK] operator-(const zgbmatrix&, const zgbmatrix&)"
00198 << std::endl;
00199 #endif//CPPL_VERBOSE
00200
00201 #ifdef CPPL_DEBUG
00202 if(matA.N!=matB.N || matA.M!=matB.M){
00203 std::cerr << "[ERROR] operator-(zgbmatrix&, zgbmatrix&)" << std::endl
00204 << "These two matrises can not make a subtraction." << std::endl
00205 << "Your input was (" << matA.M << "x" << matA.N << ") - ("
00206 << matB.M << "x" << matB.N << ")." << std::endl;
00207 exit(1);
00208 }
00209 #endif//CPPL_DEBUG
00210
00211 zgbmatrix newmat(matA.M,matA.N,max(matA.KL,matB.KL),max(matA.KU,matB.KU));
00212 newmat.zero();
00213
00214 for(long i=0; i<matA.M; i++){
00215 for(long j=max(0,i-matA.KL); j<min(matA.N,i+matA.KU+1); j++){
00216 newmat(i,j)+=matA(i,j);
00217 }
00218 for(long j=max(0,i-matB.KL); j<min(matB.N,i+matB.KU+1); j++){
00219 newmat(i,j)-=matB(i,j);
00220 }
00221 }
00222
00223 return _(newmat);
00224 }
00225
00226
00228 inline _zgbmatrix operator*(const zgbmatrix& matA, const zgbmatrix& matB)
00229 {
00230 #ifdef CPPL_VERBOSE
00231 std::cerr << "# [MARK] operator*(const zgbmatrix&, const zgbmatrix&)"
00232 << std::endl;
00233 #endif//CPPL_VERBOSE
00234
00235 #ifdef CPPL_DEBUG
00236 if(matA.N!=matB.M){
00237 std::cerr << "[ERROR] operator*(zgbmatrix&, zgbmatrix&)" << std::endl
00238 << "These two matrises can not make a product." << std::endl
00239 << "Your input was (" << matA.M << "x" << matA.N << ") * ("
00240 << matB.M << "x" << matB.N << ")." << std::endl;
00241 exit(1);
00242 }
00243 #endif//CPPL_DEBUG
00244
00245 zgbmatrix newmat( matA.M, matB.N, matA.KU+matB.KL-1, matA.KL+matB.KU+1 );
00246 newmat.zero();
00247
00248 long i, j, k;
00249 #pragma omp parallel for private(j,k)
00250 for(i=0; i<newmat.m; i++){
00251 for(j=max(0,i-newmat.kl); j<min(newmat.n,i+newmat.ku+1); j++){
00252 for(k=max( max(0,i-matA.KL), max(0,j-matB.KU) );
00253 k< min( min(matA.N,i+matA.KU+1), min(matB.M,j+matB.KL+1) ); k++){
00254 newmat(i,j)+= matA(i,k)*matB(k,j);
00255 }
00256 }
00257 }
00258
00259 return _(newmat);
00260 }