1 #ifndef la_matrix_coo_h
2 #define la_matrix_coo_h
4 #define ALLOWED_MEM_OVERHEAD 2.e+6 // entries, this corresponds to 32 MB of
16 template<
typename INDT,
typename VALT >
39 template<
typename INDT,
typename VALT >
101 typename MatrixCooVec_::const_iterator itGlobale =
matrixCooVec_.end();
103 typename MatrixCooVec_::const_iterator itSelectb =
matrixCooVec_.begin();
104 typename MatrixCooVec_::const_iterator itSelecte = itSelectb;
108 typename MatrixCooVec_::iterator itStore =
matrixCooVec_.begin();
111 while (itSelectb != itGlobale) {
114 itSelecte = std::upper_bound( itSelectb, itGlobale, *itSelectb, TripleLessThan_( ) );
120 *itStore = tmpTriple;
124 itSelectb = itSelecte;
151 typename MatrixCooVec_::const_iterator iter =
matrixCooVec_.begin();
152 typename MatrixCooVec_::const_iterator itere =
matrixCooVec_.end();
154 for ( ; iter != itere; ++iter ) {
160 if ( row >= low and row < high ) {
165 if ( col >= low and col < high ) {
171 nnzRowsOut[rowLoc]++;
195 typename MatrixCooVec_::iterator tripEraseIter;
196 typename MatrixCooVec_::iterator tripEraseIterE;
200 row, TripleRowIndexLessThan_( ) );
203 tripEraseIterE = std::upper_bound( tripEraseIter,
matrixCooVec_.end(),
204 *tripEraseIter, TripleRowLessThan_( ) );
207 typename MatrixCooVec_::iterator tripEraseIterDiag;
208 tripEraseIterDiag = std::find_if( tripEraseIter, tripEraseIterE, TripleDiagEntry_( ) );
211 for ( ; tripEraseIter != tripEraseIterE; ++tripEraseIter ) {
212 (*tripEraseIter).second =
static_cast< ValueType >( 0.0 );
216 Triple_ tmpTrip = std::make_pair( std::make_pair ( row, row ), factor );
218 if ( tripEraseIterDiag != tripEraseIterE ) {
220 *tripEraseIterDiag = tmpTrip;
243 typename MatrixCooVec_::const_iterator tvIter =
matrixCooVec_.begin();
244 typename MatrixCooVec_::const_iterator tvEnd =
matrixCooVec_.end();
251 rowPtrs.reserve( nr + 1 );
253 int previousRow = -1;
256 for ( ; tvIter != tvEnd; ++tvIter ) {
257 const IndexType row = (*tvIter).first.first;
258 const IndexType col = (*tvIter).first.second;
260 values.push_back( tvIter -> second );
261 colIndices.push_back( col );
262 if ( row == previousRow ) index++;
263 else rowPtrs.push_back( index++ );
268 rowPtrs.push_back( values.size() );
277 bool onlyUpperTriangle =
false )
287 typename MatrixCooVec_::const_iterator tvIter =
matrixCooVec_.begin();
288 typename MatrixCooVec_::const_iterator tvEnd =
matrixCooVec_.end();
295 for ( ; tvIter != tvEnd; ++tvIter ) {
296 const IndexType row = (*tvIter).first.first ;
297 const IndexType col = (*tvIter).first.second ;
299 if ( not onlyUpperTriangle or col >= row ) {
300 values.push_back( (*tvIter).second );
301 rowIndices.push_back( row );
302 colIndices.push_back( col );
321 typename MatrixCooVec_::iterator tripEraseIter =
matrixCooVec_.begin( );
322 typename MatrixCooVec_::iterator tripEraseIterE =
matrixCooVec_.end( );
325 for ( ; tripEraseIter != tripEraseIterE; ++tripEraseIter ) {
326 (*tripEraseIter).second =
static_cast< ValueType >(0.0);
333 std::ostream &
write( std::ostream & out )
339 typename MatrixCooVec_::const_iterator tvIter =
matrixCooVec_.begin();
340 typename MatrixCooVec_::const_iterator tvEnd =
matrixCooVec_.end();
341 for ( ; tvIter != tvEnd; ++tvIter ) {
342 const IndexType row = (*tvIter).first.first;
343 const IndexType col = (*tvIter).first.second;
345 out << row <<
" " << col <<
" "
346 << std::setprecision(12)
347 << (*tvIter).second << std::endl;
363 typename MatrixCooVec_::const_iterator iter =
matrixCooVec_.begin();
364 typename MatrixCooVec_::const_iterator last =
matrixCooVec_.end();
365 for ( ; iter != last; ++iter ) {
366 const IndexType iRow = (*iter).first.first;
367 rowSums[ iRow ] += std::fabs( (*iter).second );
370 return *std::max_element( rowSums.begin(), rowSums.end() );
384 typename MatrixCooVec_::const_iterator iter =
matrixCooVec_.begin();
385 typename MatrixCooVec_::const_iterator last =
matrixCooVec_.end();
386 for ( ; iter != last; ++iter ) {
389 sumOfSquares += val * val;
392 return std::sqrt( sumOfSquares );
423 if ( val > maxVal ) {
428 if ( val < minVal ) {
435 ValueType scalar = ( minVal + maxVal ) / 2.0;
443 typedef std::pair<IndexPair_,ValueType>
Triple_;
481 IndexPair_ firstTripleIndxPair = firstTriple.first;
482 IndexPair_ secondTripleIndxPair = secondTriple.first;
484 return (firstTripleIndxPair < secondTripleIndxPair);
493 IndexType firstRowIndex = firstTriple.first.first;
494 IndexType secondRowIndex = secondTriple.first.first;
496 return (firstRowIndex < secondRowIndex);
505 IndexType tripleRowIndex = triple.first.first;
507 return (tripleRowIndex < row);
516 IndexType tripleRowIndex = triple.first.first;
517 IndexType tripleColIndex = triple.first.second;
519 return (tripleRowIndex == tripleColIndex);
529 for ( ; itb != ite; ++itb) {
530 val += (*itb).second;
533 Triple_ combinedTriple = std::make_pair(tmpPair, val);
535 return combinedTriple;