18 #ifndef la_matrix_coo_h
19 #define la_matrix_coo_h
21 #define ALLOWED_MEM_OVERHEAD 2.e+6 // entries, this corresponds to 32 MB of
33 template<
typename INDT,
typename VALT >
56 template<
typename INDT,
typename VALT >
117 typename MatrixCooVec_::const_iterator itGlobale =
matrixCooVec_.end();
119 typename MatrixCooVec_::const_iterator itSelectb =
matrixCooVec_.begin();
120 typename MatrixCooVec_::const_iterator itSelecte = itSelectb;
124 typename MatrixCooVec_::iterator itStore =
matrixCooVec_.begin();
127 while (itSelectb != itGlobale) {
130 itSelecte = std::upper_bound( itSelectb, itGlobale, *itSelectb, TripleLessThan_( ) );
136 *itStore = tmpTriple;
140 itSelectb = itSelecte;
167 typename MatrixCooVec_::const_iterator iter =
matrixCooVec_.begin();
168 typename MatrixCooVec_::const_iterator itere =
matrixCooVec_.end();
170 for ( ; iter != itere; ++iter ) {
176 if ( row >= low and row < high ) {
181 if ( col >= low and col < high ) {
187 nnzRowsOut[rowLoc]++;
211 typename MatrixCooVec_::iterator tripEraseIter;
212 typename MatrixCooVec_::iterator tripEraseIterE;
216 row, TripleRowIndexLessThan_( ) );
219 tripEraseIterE = std::upper_bound( tripEraseIter,
matrixCooVec_.end(),
220 *tripEraseIter, TripleRowLessThan_( ) );
223 typename MatrixCooVec_::iterator tripEraseIterDiag;
224 tripEraseIterDiag = std::find_if( tripEraseIter, tripEraseIterE, TripleDiagEntry_( ) );
227 for ( ; tripEraseIter != tripEraseIterE; ++tripEraseIter ) {
228 (*tripEraseIter).second =
static_cast< ValueType >( 0.0 );
232 Triple_ tmpTrip = std::make_pair( std::make_pair ( row, row ), factor );
234 if ( tripEraseIterDiag != tripEraseIterE ) {
236 *tripEraseIterDiag = tmpTrip;
259 typename MatrixCooVec_::const_iterator tvIter =
matrixCooVec_.begin();
260 typename MatrixCooVec_::const_iterator tvEnd =
matrixCooVec_.end();
267 rowPtrs.reserve( nr + 1 );
269 int previousRow = -1;
272 for ( ; tvIter != tvEnd; ++tvIter ) {
273 const IndexType row = (*tvIter).first.first;
274 const IndexType col = (*tvIter).first.second;
276 values.push_back( tvIter -> second );
277 colIndices.push_back( col );
278 if ( row == previousRow ) index++;
279 else rowPtrs.push_back( index++ );
284 rowPtrs.push_back( values.size() );
293 bool onlyUpperTriangle =
false )
303 typename MatrixCooVec_::const_iterator tvIter =
matrixCooVec_.begin();
304 typename MatrixCooVec_::const_iterator tvEnd =
matrixCooVec_.end();
311 for ( ; tvIter != tvEnd; ++tvIter ) {
312 const IndexType row = (*tvIter).first.first ;
313 const IndexType col = (*tvIter).first.second ;
315 if ( not onlyUpperTriangle or col >= row ) {
316 values.push_back( (*tvIter).second );
317 rowIndices.push_back( row );
318 colIndices.push_back( col );
337 typename MatrixCooVec_::iterator tripEraseIter =
matrixCooVec_.begin( );
338 typename MatrixCooVec_::iterator tripEraseIterE =
matrixCooVec_.end( );
341 for ( ; tripEraseIter != tripEraseIterE; ++tripEraseIter ) {
342 (*tripEraseIter).second =
static_cast< ValueType >(0.0);
349 std::ostream &
write( std::ostream & out )
355 typename MatrixCooVec_::const_iterator tvIter =
matrixCooVec_.begin();
356 typename MatrixCooVec_::const_iterator tvEnd =
matrixCooVec_.end();
357 for ( ; tvIter != tvEnd; ++tvIter ) {
358 const IndexType row = (*tvIter).first.first;
359 const IndexType col = (*tvIter).first.second;
361 out << row <<
" " << col <<
" "
362 << std::setprecision(12)
363 << (*tvIter).second << std::endl;
379 typename MatrixCooVec_::const_iterator iter =
matrixCooVec_.begin();
380 typename MatrixCooVec_::const_iterator last =
matrixCooVec_.end();
381 for ( ; iter != last; ++iter ) {
382 const IndexType iRow = (*iter).first.first;
383 rowSums[ iRow ] += std::fabs( (*iter).second );
386 return *std::max_element( rowSums.begin(), rowSums.end() );
400 typename MatrixCooVec_::const_iterator iter =
matrixCooVec_.begin();
401 typename MatrixCooVec_::const_iterator last =
matrixCooVec_.end();
402 for ( ; iter != last; ++iter ) {
405 sumOfSquares += val * val;
408 return std::sqrt( sumOfSquares );
439 if ( val > maxVal ) {
444 if ( val < minVal ) {
451 ValueType scalar = ( minVal + maxVal ) / 2.0;
459 typedef std::pair<IndexPair_,ValueType>
Triple_;
497 IndexPair_ firstTripleIndxPair = firstTriple.first;
498 IndexPair_ secondTripleIndxPair = secondTriple.first;
500 return (firstTripleIndxPair < secondTripleIndxPair);
509 IndexType firstRowIndex = firstTriple.first.first;
510 IndexType secondRowIndex = secondTriple.first.first;
512 return (firstRowIndex < secondRowIndex);
521 IndexType tripleRowIndex = triple.first.first;
523 return (tripleRowIndex < row);
532 IndexType tripleRowIndex = triple.first.first;
533 IndexType tripleColIndex = triple.first.second;
535 return (tripleRowIndex == tripleColIndex);
545 for ( ; itb != ite; ++itb) {
546 val += (*itb).second;
549 Triple_ combinedTriple = std::make_pair(tmpPair, val);
551 return combinedTriple;