00001
00003 inline void dssmatrix::clear()
00004 {
00005 #ifdef CPPL_VERBOSE
00006 std::cerr << "# [MARK] dssmatrix::clear()"
00007 << std::endl;
00008 #endif//CPPL_VERBOSE
00009
00010 #ifdef CPPL_DEBUG
00011 std::cerr << "# [NOTE] dssmatrix::clear() "
00012 << " An array at " << Array
00013 << " is going to be cleared." << std::endl;
00014 #endif//CPPL_DEBUG
00015
00016 M =N =CAP =VOL=0;
00017 delete [] Array; Array =NULL;
00018 delete [] Indx; Indx =NULL;
00019 delete [] Jndx; Jndx =NULL;
00020 }
00021
00022
00024 inline void dssmatrix::zero()
00025 {
00026 #ifdef CPPL_VERBOSE
00027 std::cerr << "# [MARK] dssmatrix::zero()"
00028 << std::endl;
00029 #endif//CPPL_VERBOSE
00030
00031 VOL =0;
00032 }
00033
00034
00036 inline void dssmatrix::chsign()
00037 {
00038 #ifdef CPPL_VERBOSE
00039 std::cerr << "# [MARK] dssmatrix::chsign()"
00040 << std::endl;
00041 #endif//CPPL_VERBOSE
00042
00043 for(long i=0; i<VOL; i++){ Array[i] =-Array[i]; }
00044 }
00045
00046
00048 inline void dssmatrix::copy(const dssmatrix& mat)
00049 {
00050 #ifdef CPPL_VERBOSE
00051 std::cerr << "# [MARK] dssmatrix::copy(const dssmatrix&)"
00052 << std::endl;
00053 #endif//CPPL_VERBOSE
00054
00055 #ifdef CPPL_DEBUG
00056 std::cerr << "# [NOTE] dssmatrix::copy(const dssmatrix&) "
00057 << "A dssmatrix at " << Array << " is going to be deleted.";
00058 #endif//CPPL_DEBUG
00059
00060 resize(mat.M, mat.N, mat.CAP);
00061 VOL =mat.VOL;
00062 dcopy_(VOL, mat.Array, 1, Array, 1);
00063 for(long i=0; i<VOL; i++){
00064 Indx[i] =mat.Indx[i];
00065 Jndx[i] =mat.Jndx[i];
00066 }
00067
00068 #ifdef CPPL_DEBUG
00069 std::cerr << " Then, a COPY of a dssmatrix has been cleated at "
00070 << Array << "." << std::endl;
00071 #endif//CPPL_DEBUG
00072 }
00073
00074
00077 inline void dssmatrix::shallow_copy(const _dssmatrix& mat)
00078 {
00079 #ifdef CPPL_VERBOSE
00080 std::cerr << "# [MARK] dssmatrix::shallow_copy(const _dssmatrix&)"
00081 << std::endl;
00082 #endif//CPPL_VERBOSE
00083
00084 #ifdef CPPL_DEBUG
00085 std::cerr << "# [NOTE] dssmatrix:shallow_copy(const _dssmatrix&) "
00086 << "A dssmatrix at " << Array << " is going to be deleted, "
00087 << "and point at " << mat.Array << " instead." << std::endl;
00088 #endif//CPPL_DEBUG
00089
00090 delete [] Array;
00091 delete [] Indx;
00092 delete [] Jndx;
00093 M =mat.M;
00094 N =mat.N;
00095 CAP =mat.CAP;
00096 VOL =mat.VOL;
00097 Array =mat.Array;
00098 Indx =mat.Indx;
00099 Jndx =mat.Jndx;
00100 }
00101
00102
00104 inline void dssmatrix::resize(const long& _m, const long& _n, const long& _c)
00105 {
00106 #ifdef CPPL_VERBOSE
00107 std::cerr << "# [MARK] dssmatrix::resize(const long&, const long&, const long&)"
00108 << std::endl;
00109 #endif//CPPL_VERBOSE
00110
00111 #ifdef CPPL_DEBUG
00112 if( _m<0 || _n<0 || _c<0 ){
00113 std::cerr << "[ERROR] dssmatrix::resize"
00114 << "(const long&, const long&, const long&)"
00115 << std::endl
00116 << "Matrix sizes and the length of arrays "
00117 << "must be positive integers. " << std::endl
00118 << "Your input was (" << _m << "," << _n << "," << _c << ")."
00119 << std::endl;
00120 exit(1);
00121 }
00122 #endif//CPPL_DEBUG
00123
00124 delete [] Array;
00125 M =_m;
00126 N =_n;
00127 CAP =_c;
00128 VOL =0;
00129 Array =new double[CAP];
00130 Indx =new long[CAP];
00131 Jndx =new long[CAP];
00132 }
00133
00134
00136 inline void dssmatrix::expand(const long& dc)
00137 {
00138 #ifdef CPPL_VERBOSE
00139 std::cerr << "# [MARK] dssmatrix::expand(const long&)"
00140 << std::endl;
00141 #endif//CPPL_VERBOSE
00142
00143 #ifdef CPPL_DEBUG
00144 if( dc<0 ){
00145 std::cerr << "[ERROR] dssmatrix::expand(const long&)" << std::endl
00146 << "The argument must be a positive integer. " << std::endl
00147 << "Your input was (" << dc << ")." << std::endl;
00148 exit(1);
00149 }
00150 #endif//CPPL_DEBUG
00151
00152 CAP+=dc;
00153 double* newArray(new double[CAP]);
00154 long *newIndx(new long[CAP]), *newJndx(new long[CAP]);
00155
00156 for(int c=0; c<VOL; c++){
00157 newArray[c] =Array[c];
00158 newIndx[c] =Indx[c];
00159 newJndx[c] =Jndx[c];
00160 }
00161
00162 delete [] Array;
00163 delete [] Indx;
00164 delete [] Jndx;
00165 Array =newArray;
00166 Indx =newIndx;
00167 Jndx =newJndx;
00168 }
00169
00170
00172 inline bool dssmatrix::isListed(const long& i, const long& j)
00173 {
00174 #ifdef CPPL_VERBOSE
00175 std::cerr << "# [MARK] dssmatrix::isListed(const long&, const long&)"
00176 << std::endl;
00177 #endif//CPPL_VERBOSE
00178
00179 #ifdef CPPL_DEBUG
00180 if( i<0 || j<0 || M<=i || N<=j ){
00181 std::cerr << "[ERROR] dssmatrix::isListed(const long&, const long&)"
00182 << std::endl
00183 << "The required component is out of the matrix size."
00184 << std::endl
00185 << "Your input was (" << i << "," << j << ")." << std::endl;
00186 exit(1);
00187 }
00188 #endif//CPPL_DEBUG
00189
00190 for(int c=0; c<VOL; c++){
00191 if(Indx[c]==i && Jndx[c]==j){ return 1; }
00192 }
00193
00194 return 0;
00195 }
00196
00197
00198
00200 inline long dssmatrix::number(const long& i, const long& j)
00201 {
00202 #ifdef CPPL_VERBOSE
00203 std::cerr << "# [MARK] dssmatrix::number(const long&, const long&)"
00204 << std::endl;
00205 #endif//CPPL_VERBOSE
00206
00207 #ifdef CPPL_DEBUG
00208 if( i<0 || j<0 || M<=i || N<=j ){
00209 std::cerr << "[ERROR] dssmatrix::number(const long&, const long&)"
00210 << std::endl
00211 << "The required component is out of the matrix size."
00212 << std::endl
00213 << "Your input was (" << i << "," << j << ")." << std::endl;
00214 exit(1);
00215 }
00216 #endif//CPPL_DEBUG
00217
00218 for(long c=0; c<VOL; c++){
00219 if(Indx[c]==i && Jndx[c]==j){ return c; }
00220 }
00221
00222 return -1;
00223 }
00224
00225
00226
00228 inline void swap(dssmatrix& A, dssmatrix& B)
00229 {
00230 #ifdef CPPL_VERBOSE
00231 std::cerr << "# [MARK] swap(dssmatrix&, dssmatrix&)"
00232 << std::endl;
00233 #endif//CPPL_VERBOSE
00234
00235 long A_M(A.M), A_N(A.N), A_CAP(A.CAP), A_VOL(A.VOL);
00236 double* A_Array(A.Array);
00237 long *A_Indx(A.Indx), *A_Jndx(A.Jndx);
00238 A.M=B.M; A.N=B.N; A.CAP=B.CAP; A.VOL=B.VOL;
00239 A.Array=B.Array; A.Indx=B.Indx; A.Jndx=B.Jndx;
00240 B.M=A_M; B.N=A_N; B.CAP=A_CAP; B.VOL=A_VOL;
00241 B.Array=A_Array; B.Indx=A_Indx; B.Jndx=A_Jndx;
00242 }
00243
00244
00246 inline _dssmatrix _(dssmatrix& mat)
00247 {
00248 #ifdef CPPL_VERBOSE
00249 std::cerr << "# [MARK] _(dssmatrix&)"
00250 << std::endl;
00251 #endif//CPPL_VERBOSE
00252
00253 _dssmatrix newmat;
00254
00255 newmat.M =mat.M;
00256 newmat.N =mat.N;
00257 newmat.CAP =mat.CAP;
00258 newmat.VOL =mat.VOL;
00259 newmat.Array =mat.Array;
00260 newmat.Indx =mat.Indx;
00261 newmat.Jndx =mat.Jndx;
00262
00263 mat.M =0;
00264 mat.N =0;
00265 mat.CAP =0;
00266 mat.VOL =0;
00267 mat.Array =NULL;
00268 mat.Indx =NULL;
00269 mat.Jndx =NULL;
00270
00271 return newmat;
00272 }
00273
00274
00275
00279
00280
00282 inline void dssmatrix::checkup()
00283 {
00284 #ifdef CPPL_VERBOSE
00285 std::cerr << "# [MARK] dssmatrix::checkup()"
00286 << std::endl;
00287 #endif//CPPL_VERBOSE
00288
00290 if(CAP<0){
00291 std::cerr << "[ERROR] dssmatrix::checkup()" << std::endl
00292 << "The cap is not valid." << std::endl
00293 << "CAP was " << CAP << "." << std::endl;
00294 exit(1);
00295 }
00296
00298 if(VOL<0 || VOL>CAP){
00299 std::cerr << "[ERROR] dssmatrix::checkup()" << std::endl
00300 << "The vol is not valid." << std::endl
00301 << "VOL was " << VOL << "while CAP is " << CAP << "."
00302 << std::endl;
00303 exit(1);
00304 }
00305
00307 for(long c=0; c<VOL; c++){
00309 if(Indx[c]<0 || Indx[c]>=M){
00310 std::cerr << "[ERROR] dssmatrix::checkup()" << std::endl
00311 << "The indx of the " << c
00312 << "th element is out of the matrix size." << std::endl
00313 << "Indx[" << c << "] was " << Indx[c] << "." << std::endl;
00314 exit(1);
00315 }
00316
00318 if(Jndx[c]<0 || Jndx[c]>=N){
00319 std::cerr << "[ERROR] dssmatrix::checkup()" << std::endl
00320 << "The jndx of the " << c
00321 << "th element is out of the matrix size." << std::endl
00322 << "Jndx[" << c << "] was " << Jndx[c] << "." << std::endl;
00323 exit(1);
00324 }
00325
00327 for(long C=c+1; C<VOL; C++){
00328 if(Indx[c]==Indx[C] && Jndx[c]==Jndx[C]){
00329 std::cerr << "[ERROR] dssmatrix::checkup()" << std::endl
00330 << "The (" << Indx[c] << ", " << Jndx[c]
00331 << ") component is double-listed at the "
00332 << c << "th and the" << C << "the elements."<< std::endl;
00333 exit(1);
00334 }
00335 }
00336 }
00337
00339 std::cerr << "# [NOTE] dssmatrix::checkup() "
00340 << "This sparse matrix is fine." << std::endl;
00341 }