00001
00003 inline _dssmatrix operator+(const _dssmatrix& matA, const _dssmatrix& matB)
00004 {
00005 #ifdef CPPL_VERBOSE
00006 std::cerr << "# [MARK] operator+(const _dssmatrix&, const _dssmatrix&)"
00007 << std::endl;
00008 #endif//CPPL_VERBOSE
00009
00010 #ifdef CPPL_DEBUG
00011 if(matA.N!=matB.N || matA.M!=matB.M){
00012 std::cerr << "[ERROR] operator+(const _dssmatrix&, const _dssmatrix&)"
00013 << std::endl
00014 << "These two matrises can not make a summation." << std::endl
00015 << "Your input was (" << matA.M << "x" << matA.N << ") + ("
00016 << matB.M << "x" << matB.N << ")." << std::endl;
00017 exit(1);
00018 }
00019 #endif//CPPL_DEBUG
00020
00021 dssmatrix newmat(matA);
00022
00023 for(long c=0; c<matB.VOL; c++){
00024 newmat.add(matB.Indx[c], matB.Jndx[c], matB.Array[c]);
00025 }
00026
00027 matB.destroy();
00028 return _(newmat);
00029 }
00030
00031
00033 inline _dssmatrix operator-(const _dssmatrix& matA, const _dssmatrix& matB)
00034 {
00035 #ifdef CPPL_VERBOSE
00036 std::cerr << "# [MARK] operator-(const _dssmatrix&, const _dssmatrix&)"
00037 << std::endl;
00038 #endif//CPPL_VERBOSE
00039
00040 #ifdef CPPL_DEBUG
00041 if(matA.N!=matB.N || matA.M!=matB.M){
00042 std::cerr << "[ERROR] operator-(const _dssmatrix&, const _dssmatrix&)"
00043 << std::endl
00044 << "These two matrises can not make a subtraction." << std::endl
00045 << "Your input was (" << matA.M << "x" << matA.N << ") - ("
00046 << matB.M << "x" << matB.N << ")." << std::endl;
00047 exit(1);
00048 }
00049 #endif//CPPL_DEBUG
00050
00051 dssmatrix newmat(matA);
00052
00053 for(long c=0; c<matB.VOL; c++){
00054 newmat.sub(matB.Indx[c], matB.Jndx[c], matB.Array[c]);
00055 }
00056
00057 matB.destroy();
00058 return _(newmat);
00059 }
00060
00061
00063 inline _dssmatrix operator*(const _dssmatrix& matA, const _dssmatrix& matB)
00064 {
00065 #ifdef CPPL_VERBOSE
00066 std::cerr << "# [MARK] operator*(const _dssmatrix&, const _dssmatrix&)"
00067 << std::endl;
00068 #endif//CPPL_VERBOSE
00069
00070 #ifdef CPPL_DEBUG
00071 if(matA.N!=matB.M){
00072 std::cerr << "[ERROR] operator*(const _dssmatrix&, const _dssmatrix&)"
00073 << std::endl
00074 << "These two matrises can not make a product." << std::endl
00075 << "Your input was (" << matA.M << "x" << matA.N << ") * ("
00076 << matB.M << "x" << matB.N << ")." << std::endl;
00077 exit(1);
00078 }
00079 #endif//CPPL_DEBUG
00080
00081 dssmatrix newmat( matA.M, matB.N, 0 );
00082
00083 for(long c=0; c<matA.VOL; c++){
00084 for(long d=0; d<matB.VOL; d++){
00085 if(matA.Jndx[c]==matB.Indx[d]){
00086 newmat.add(matA.Indx[c], matB.Jndx[d], matA.Array[c]*matB.Array[d]);
00087 }
00088 }
00089 }
00090
00091 matA.destroy();
00092 matB.destroy();
00093 return _(newmat);
00094 }