File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed
include/graphblas/reference Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -412,16 +412,18 @@ namespace grb {
412412 );
413413 #pragma omp parallel for num_threads( nThreads )
414414 for ( size_t i = 0 ; i < A.n ; ++i ) {
415- const auto index_it = std::find (
416- ccs.row_index + ccs.col_start [ i ],
417- ccs.row_index + ccs.col_start [ i + 1 ],
418- i
419- );
420- if ( !std::is_void< InputType >::value ) {
421- const size_t index = std::distance ( ccs.row_index , index_it );
422- std::swap ( ccs.values [ index ], ccs.values [ ccs.col_start [ i ] ] );
415+ const auto start = ccs.row_index + ccs.col_start [ i ];
416+ const auto end = ccs.row_index + ccs.col_start [ i + 1 ];
417+ const auto index_it = std::find ( start, end, i );
418+ if ( index_it == end ) {
419+ throw std::runtime_error ( " No diagonal element present" );
420+ } else if ( index_it != start ) {
421+ if ( !std::is_void< InputType >::value ) {
422+ const size_t index = std::distance ( ccs.row_index , index_it );
423+ std::swap ( ccs.values [ index ], ccs.values [ ccs.col_start [ i ] ] );
424+ }
425+ std::swap ( *index_it, ccs.row_index [ ccs.col_start [ i ] ] );
423426 }
424- std::swap ( *index_it, ccs.row_index [ ccs.col_start [ i ] ] );
425427 }
426428 }
427429 } else {
You can’t perform that action at this time.
0 commit comments