#include <EmcLSSMatrix.h>
Public Member Functions | |
int * | column (const int &rowind=0) const |
int * | column (const int &rowind=0) const |
EmcLSSMatrix (const EmcLSSMatrix &m1) | |
EmcLSSMatrix (int rows, int nonzero_col, int MsgFlag) | |
EmcLSSMatrix (int rows, int nonzero_col) | |
EmcLSSMatrix () | |
EmcLSSMatrix (const EmcLSSMatrix &m1) | |
EmcLSSMatrix (int rows, int nonzero_col, int MsgFlag) | |
EmcLSSMatrix (int rows, int nonzero_col) | |
EmcLSSMatrix () | |
double * | matrix (const int &rowind=0) const |
double * | matrix (const int &rowind=0) const |
const int & | num_cols () const |
const int & | num_cols () const |
int | num_filled_cols (const int row) const |
int | num_filled_cols (const int row) const |
int | num_filled_rows (const int col) const |
int | num_filled_rows (const int col) const |
long int | num_nonZeros () |
long int | num_nonZeros () |
const int & | num_rows () const |
const int & | num_rows () const |
double & | operator() (int row, int col) |
double & | operator() (int row, int col) |
void | print_NonZeros () |
void | print_NonZeros () |
void | print_row (int rownr) |
void | print_row (int rownr) |
void | readIn (istream &In) |
void | readIn (istream &In) |
bool | reduce_Matrix (int *xRef_list) |
bool | reduce_Matrix (int *xRef_list) |
void | reset () |
void | reset () |
int * | row () const |
int * | row () const |
void | set_verbose (bool setting) |
void | set_verbose (bool setting) |
const long & | size () const |
const long & | size () const |
void | writeOut (ostream &Out) |
void | writeOut (ostream &Out) |
~EmcLSSMatrix () | |
~EmcLSSMatrix () | |
Protected Member Functions | |
long int | find (int row, int col) |
long int | find (int row, int col) |
Private Attributes | |
int * | _columns |
int * | _columns |
double * | _matrix |
double * | _matrix |
int | _MsgFlag |
double * | _nothing |
double * | _nothing |
const int | _nrcol |
const int | _nrrows |
int * | _rows |
int * | _rows |
const long | _size |
bool | _verb |
Per row only the nonzero elements are stored together with their column indices. (the storiage of the row index is a tribute to SLAP which needs it)
|
00044 : _size(0), _nrrows(0), _nrcol(0), _matrix(0), _columns(0), _rows(0), 00045 _nothing(0),_verb(false) 00046 { 00047 }
|
|
00050 : _size(rows * nonzero_col), 00051 _nrrows(rows), 00052 _nrcol(nonzero_col) 00053 { 00054 _matrix = new double[_size]; 00055 _rows = new int[_size]; 00056 _columns = new int[_size]; 00057 for (int i=0; i<_size;i++) 00058 { 00059 _matrix[i] =0.; 00060 _rows[i] = -1; 00061 _columns[i] = -1; 00062 } 00063 _nothing = new double; 00064 _verb = false; 00065 00066 _MsgFlag =0; 00067 }
|
|
00070 : _size(rows * nonzero_col), 00071 _nrrows(rows), 00072 _nrcol(nonzero_col) 00073 { 00074 _matrix = new double[_size]; 00075 _rows = new int[_size]; 00076 _columns = new int[_size]; 00077 for (int i=0; i<_size;i++) 00078 { 00079 _matrix[i] =0.; 00080 _rows[i] = -1; 00081 _columns[i] = -1; 00082 } 00083 _nothing = new double; 00084 _verb = false; 00085 00086 _MsgFlag = MsgFlag; 00087 }
|
|
00090 : _size(m1._size), 00091 _nrrows(m1._nrrows), 00092 _nrcol(m1._nrcol) 00093 00094 { 00095 _matrix = new double[_size]; 00096 _rows = new int[_size]; 00097 _columns = new int[_size]; 00098 _nothing = m1._nothing; 00099 _verb = m1._verb; 00100 00101 for ( long int i=0;i<_size;i++) 00102 { 00103 _matrix[i] = m1._matrix[i]; 00104 _rows[i] = m1._rows[i]; 00105 _columns[i] = m1._columns[i]; 00106 }; 00107 }
|
|
00112 { 00113 if ( 0 != _matrix) 00114 { 00115 delete [] _matrix; 00116 _matrix = 0; 00117 } 00118 if ( 0 != _rows) 00119 { 00120 delete [] _rows; 00121 _rows = 0; 00122 } 00123 if ( 0 != _columns) 00124 { 00125 delete [] _columns; 00126 _columns = 0; 00127 } 00128 if ( 0 != _nothing) 00129 { 00130 delete _nothing; 00131 _nothing = 0; 00132 } 00133 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
00296 { 00297 int* here=0; 00298 00299 if (rowind < _nrrows) 00300 { 00301 here = (_columns+(rowind*_nrcol)); 00302 } 00303 else 00304 { 00305 00306 if (_MsgFlag <= 5) { 00307 std::cout <<"EmcLSSMatrix::ERROR " 00308 << "EmcLSSMatrix.column: Error " 00309 << "- larger row index than existing requested !" 00310 << endl; 00311 } 00312 here = 0; 00313 } 00314 return here; 00315 }
|
|
|
|
00165 { 00166 int smaller,larger; 00167 00168 00169 if ( col > row ) 00170 { 00171 smaller = row; 00172 larger = col; 00173 } 00174 else 00175 { 00176 smaller = col; 00177 larger = row; 00178 } 00179 00180 int* col_p; 00181 int* row_p; 00182 double* matr_p; 00183 double* matr_row_max; 00184 00185 if (larger < 0 || larger > _nrrows || smaller < 0 || smaller > _nrrows ) 00186 { 00187 if (_MsgFlag <= 5) { 00188 std::cout <<"EmcLSSMatrix::ERROR" 00189 << "!!! ERROR in bound check of EmcLSSMatrix !!!" 00190 << "!!! Return zero !!!" 00191 << endl; 00192 } 00193 matr_p = 0; 00194 } 00195 else 00196 { 00197 col_p = (_columns + (larger * _nrcol)); 00198 row_p = (_rows + (larger * _nrcol)); 00199 matr_p = (_matrix + (larger * _nrcol)); 00200 matr_row_max = (matr_p + _nrcol); 00201 00202 while ( matr_p < matr_row_max ) { 00203 00204 if (_MsgFlag <= 1) { 00205 std::cout <<"EmcLSSMatrix::VERBOSE" 00206 << "C: " << larger << " " << smaller << " " 00207 << col_p << " " << *col_p << " " 00208 << matr_p << " " << *matr_p << " " 00209 << (_matrix+(matr_p-_matrix)) << " " 00210 << *(_matrix+(matr_p-_matrix)) << endl; 00211 } 00212 /* 00213 cout<< "C: " << larger << " " << smaller << " " 00214 << col_p << " " << *col_p << " " 00215 << matr_p << " " << *matr_p << " " 00216 << (_matrix+(matr_p-_matrix)) << " " 00217 << *(_matrix+(matr_p-_matrix)) <<endl; 00218 */ 00219 if ( matr_p == (matr_row_max-1) ) 00220 { 00221 if (_MsgFlag <= 4) { 00222 std::cout <<"EmcLSSMatrix::WARNING " 00223 << "!! WARNING: Reached maximum number of columns " 00224 << "in LSSMatrix when searching for row " 00225 << larger << " column " << smaller << " !!" 00226 << endl 00227 << "!! Return zero pointer !! " << endl; 00228 } 00229 matr_p = 0; 00230 break; 00231 } 00232 00233 //if row does already exist 00234 if ( *col_p == smaller ) 00235 { 00236 break; 00237 } 00238 00239 //if at the end of the list, use this as new element 00240 if ( (*matr_p == 0.) ) 00241 { 00242 *col_p = smaller; 00243 *row_p = larger; 00244 // if (*row_p == 1616 ) { 00245 // nun=(row_p-(_rows + (larger * _nrcol))); 00246 //if (_MsgFlag <= 2) { 00247 // std::cout <<"EmcLSSMatrix::DEBUG " 00248 // << nun << " " << larger << " " << smaller << " " 00249 // << *row_p << " " << *col_p << " " << *matr_p << endl; 00250 //} 00251 // } 00252 break; 00253 } 00254 00255 matr_p++; 00256 col_p++; 00257 row_p++; 00258 00259 } 00260 } 00261 00262 long int diff = matr_p-_matrix; 00263 00264 if (matr_p == 0) 00265 { 00266 diff = -1; 00267 } 00268 00269 return (diff); 00270 }
|
|
|
|
00274 { 00275 double* here=0; 00276 00277 if (rowind < _nrrows) 00278 { 00279 here = (_matrix+(rowind*_nrcol)); 00280 } 00281 else 00282 { 00283 if (_MsgFlag <= 5) { 00284 std::cout <<"EmcLSSMatrix::ERROR " 00285 << "EmcLSSMatrix::matrix: Error " 00286 << "- larger row index than existing requested !" 00287 << endl; 00288 } 00289 here = 0; 00290 } 00291 return here; 00292 }
|
|
00078 { return _nrcol ; }
|
|
00078 { return _nrcol ; }
|
|
|
|
00319 { 00320 double * search_i = _matrix + ( row * _nrcol ); 00321 double * max_i = search_i + _nrcol; 00322 int nonZeroCol=0; 00323 00324 while ( (*search_i != 0.) && (search_i < max_i) ) 00325 { 00326 nonZeroCol++; 00327 search_i++; 00328 } 00329 return nonZeroCol; 00330 }
|
|
|
|
00334 { 00335 int nonZeroRows = 0; 00336 for ( long int i=0; i<_size; i++ ) 00337 { 00338 if ( (_matrix[i] != 0.) && (_columns[i] == col) ) 00339 { 00340 nonZeroRows++; 00341 } 00342 } 00343 00344 return nonZeroRows; 00345 }
|
|
|
|
00350 { 00351 int* col_p = _columns; 00352 double* ele_p = _matrix; 00353 double* mat_max_p = (_matrix + _size); 00354 long int nrele = 0; 00355 00356 while ( ele_p < mat_max_p ) 00357 { 00358 if ( *ele_p != 0.) nrele++; 00359 col_p++; 00360 ele_p++; 00361 } 00362 00363 return nrele; 00364 }
|
|
00075 { return _nrrows; }
|
|
00075 { return _nrrows; }
|
|
|
|
00139 { 00140 00141 long int found = find( row, col ); 00142 00143 00144 if ( -1 == found ) 00145 { 00146 if (_MsgFlag <= 5) { 00147 std::cout << "EmcLSSMatrix:: ERROR " 00148 << "EmcLSSMatrix: matrix element not found !!" << endl 00149 << "EmcLSSMatrix: Return zero !" << endl; 00150 } 00151 _nothing = 0; 00152 return *_nothing; 00153 } 00154 00155 return (*(_matrix+found)); 00156 }
|
|
|
|
00461 { 00462 int* col_p = _columns; 00463 int* row_p = _rows; 00464 double* ele_p = _matrix; 00465 double* mat_max_p = (_matrix + _size); 00466 long int wo = 0; 00467 long int nrele = 0; 00468 00469 00470 if (_MsgFlag <= 2) { 00471 std::cout <<"EmcLSSMatrix::DEBUG " 00472 <<"List of nonzero Matrix elements (Matrix size: " 00473 << _size << " ) : " << endl; 00474 } 00475 00476 while ( ele_p < mat_max_p ) 00477 { 00478 if ( *ele_p != 0. ) 00479 { 00480 nrele++; 00481 if (_MsgFlag <= 2) { 00482 std::cout <<"EmcLSSMatrix::DEBUG " 00483 << "nr: " << nrele 00484 << " M( " << *row_p << " , " << *col_p 00485 << " ): " << *ele_p 00486 << " array index: " << wo << endl; 00487 } 00488 /* 00489 cout<< "nr: " << nrele 00490 << " M( " << *row_p << " , " << *col_p 00491 << " ): " << *ele_p 00492 << " array index: " << wo << endl; 00493 */ 00494 } 00495 wo++; 00496 col_p++; 00497 row_p++; 00498 ele_p++; 00499 } 00500 00501 }
|
|
|
|
00506 { 00507 int* col_p = _columns+(_nrcol*rownr); 00508 int* row_p = _rows+(_nrcol*rownr); 00509 double* ele_p = _matrix+(_nrcol*rownr); 00510 double* mat_max_p = (ele_p + _nrcol); 00511 long int wo = 0; 00512 long int nrele = 0; 00513 00514 if (_MsgFlag <= 2) { 00515 std::cout <<"EmcLSSMatrix::DEBUG " 00516 <<"row length: " << num_filled_cols(rownr) << endl; 00517 } 00518 while ( ele_p < mat_max_p ) 00519 { 00520 if ( *ele_p != 0. ) 00521 { 00522 nrele++; 00523 if (_MsgFlag <= 2) { 00524 std::cout <<"EmcLSSMatrix::DEBUG " 00525 << "nr: " << nrele 00526 << " M( " << *row_p << " , " << *col_p 00527 << " ): " << *ele_p 00528 << " array index: " << wo << endl; 00529 } 00530 /* 00531 cout<< "nr: " << nrele 00532 << " M( " << *row_p << " , " << *col_p 00533 << " ): " << *ele_p 00534 << " array index: " << wo << endl; 00535 */ 00536 } 00537 wo++; 00538 col_p++; 00539 row_p++; 00540 ele_p++; 00541 } 00542 00543 }
|
|
|
|
00581 { 00582 // long int nonz = num_nonZeros(); 00583 long int nonz = 0; 00584 In >> nonz; 00585 00586 cout<<"nonz="<<nonz<<endl; 00587 00588 int theRow; 00589 int theCol; 00590 long int index; 00591 double theEle; 00592 00593 00594 for (long int i=0; i<nonz; i++ ) 00595 { 00596 In >> theRow >> theCol >> theEle; 00597 index = find (theRow,theCol); 00598 /* 00599 cout<<"index = "<<index 00600 <<"row="<<theRow 00601 <<"col="<<theCol<<endl; 00602 */ 00603 if ( -1 != index ) 00604 { 00605 _matrix[index] += theEle; 00606 if (_verb) 00607 { 00608 if ( i < 50 || i > (nonz-10) ) 00609 { 00610 if (_MsgFlag <= 2) { 00611 std::cout <<"EmcLSSMatrix::DEBUG " 00612 << "M: " << _rows[index] << " " << _columns[index] 00613 << " " << _matrix[index] << " " << index << endl; 00614 } 00615 } 00616 } 00617 } 00618 } 00619 00620 if (_verb) 00621 { 00622 if (_MsgFlag <= 2) { 00623 std::cout <<"EmcLSSMatrix::DEBUG " 00624 << "Have read in " << nonz 00625 << " non zero matrix elements from file !!!" << endl; 00626 } 00627 } 00628 }
|
|
|
|
00383 { 00384 bool successful = true; 00385 00386 //delete all zero elements in matrix 00387 //save only non zero elements 00388 00389 long int _newIndx = 0; 00390 00391 00392 for ( long int _arrayIndx = 0; 00393 _arrayIndx < _size; _arrayIndx++) 00394 { 00395 00396 //add 1 to matrix indices because SLAP wants indices 1..N, 00397 //but Xtals counting in geometry starts with 0 00398 00399 if ( _matrix[_arrayIndx] > 0. ) 00400 { 00401 00402 if ( (xRef_list[(_rows[_arrayIndx])]) >= 0 00403 && (xRef_list[(_columns[_arrayIndx])]) >= 0 ) 00404 { 00405 _matrix[_newIndx] = _matrix[_arrayIndx]; 00406 _rows[_newIndx] = ((xRef_list[(_rows[_arrayIndx])])+1); 00407 _columns[_newIndx] = ((xRef_list[(_columns[_arrayIndx])])+1); 00408 _newIndx++; 00409 } 00410 else 00411 { 00412 00413 //int indxtal; 00414 if (xRef_list[(_rows[_arrayIndx])] < 0 ) 00415 { 00416 if (_MsgFlag <= 5) { 00417 std::cout <<"EmcLSSMatrix::ERROR " 00418 << "EmcLSSMatrix: Xtal index " 00419 << _rows[_arrayIndx] 00420 << " appears in matrix, " 00421 << "but not in vector !!! " 00422 << _rows[_arrayIndx] << " " 00423 << _columns[_arrayIndx] 00424 << endl; 00425 } 00426 } 00427 else 00428 { 00429 00430 if (_MsgFlag <= 5) { 00431 std::cout <<"EmcLSSMatrix::ERROR " 00432 << "EmcLSSMatrix: Xtal index " 00433 << _columns[_arrayIndx] 00434 << " appears in matrix, " 00435 << "but not in vector !!! " 00436 << _rows[_arrayIndx] << " " 00437 << _columns[_arrayIndx] 00438 << endl; 00439 } 00440 } 00441 successful=false; 00442 } 00443 } 00444 } 00445 00446 if (_verb) 00447 { 00448 if (_MsgFlag <= 2) { 00449 std::cout <<"EmcLSSMatrix::DEBUG " 00450 << "Reduced LSSMatrix !!! Number of non zeros: " 00451 << _newIndx << endl; 00452 } 00453 } 00454 00455 return successful; 00456 }
|
|
|
|
00371 { 00372 for (int i=0; i<_size;i++) 00373 { 00374 _matrix[i] =0.; 00375 _rows[i] = -1; 00376 _columns[i] = -1; 00377 } 00378 00379 }
|
|
00084 { return _rows; }
|
|
00084 { return _rows; }
|
|
00111 { _verb = setting; }
|
|
00111 { _verb = setting; }
|
|
00081 { return _size; }
|
|
00081 { return _size; }
|
|
|
|
00547 { 00548 int* col_p = _columns; 00549 int* row_p = _rows; 00550 double* ele_p = _matrix; 00551 double* mat_max_p = (_matrix + _size); 00552 // long int nrele = 0; 00553 00554 long int nonz = num_nonZeros(); 00555 Out << nonz << " "; 00556 00557 while ( ele_p < mat_max_p ) 00558 { 00559 if ( *ele_p != 0.) 00560 { 00561 Out<< *row_p << " " 00562 << *col_p << " " 00563 << *ele_p << " "; 00564 } 00565 col_p++; 00566 row_p++; 00567 ele_p++; 00568 } 00569 00570 if (_MsgFlag <= 2) { 00571 std::cout <<"EmcLSSMatrix::DEBUG " 00572 << "Wrote " << nonz 00573 << " non zero matrix elements to file !!!" << endl; 00574 } 00575 00576 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|