void operator=(VecExpression<E> const& vec) { E const& v = vec; _data.resize(v.size()); for (size_type i = 0; i != v.size(); ++i) { _data[i] = v[i]; } }
/* * Construction from triplets. * This is the main workhorse of the data structure, taking an unordered (potentially uncompressed) * vector of triplets and performing the required sorting to convert it into a sparse_bcsr ordering. * * This function DOES MODIFY the input triplet vector "ts" (by sorting) */ sparse_bcsr(const std::vector<triplet> & _ts) : _brows(0), _bcols(0), _zero(0) { std::vector<triplet> ts(_ts); block_stride = BLOCK*BLOCK; assert(ts.size() > 0 && "Doesn't support empty matrices (yet)"); //sort the triplets into bcsr order using the bcsr_compare struct std::sort(ts.begin(), ts.end(), bcsr_compare()); size_type brows = std::get<0>(*ts.rbegin())/BLOCK+1; brow_ptr.resize(brows+1, size_type(0)); size_type curr_brow = std::get<0>(ts[0])/BLOCK; size_type curr_bcol = std::get<1>(ts[0])/BLOCK; // count number of blocks (single pass thru tuples. saves mem alloc time from push_back calls) size_type nblocks = 1; for(size_type i=1; i<ts.size(); ++i) { if(curr_brow == std::get<0>(ts[i])/BLOCK && curr_bcol == std::get<1>(ts[i])/BLOCK) { } else { ++nblocks; } curr_brow = std::get<0>(ts[i])/BLOCK; curr_bcol = std::get<1>(ts[i])/BLOCK; } // resize storage containers bcol_index.resize(nblocks, size_type(0)); data.resize(nblocks*block_stride, value_type(0)); //construct from triplets curr_brow = std::get<0>(ts[0])/BLOCK; curr_bcol = std::get<1>(ts[0])/BLOCK; //_rows = std::get<0>(ts[0])+1; //_cols = std::get<1>(ts[0])+1; for(size_type r=0; r<=curr_brow; ++r) { brow_ptr[r] = 0; } bcol_index[0] = curr_bcol; data[index(0, std::get<0>(ts[0])%BLOCK, std::get<1>(ts[0])%BLOCK)] = std::get<2>(ts[0]); size_type bidx = 0; for(size_type idx=1; idx<ts.size(); ++idx) { size_type I = std::get<0>(ts[idx])/BLOCK; size_type J = std::get<1>(ts[idx])/BLOCK; size_type i = std::get<0>(ts[idx])%BLOCK; size_type j = std::get<1>(ts[idx])%BLOCK; value_type val = std::get<2>(ts[idx]); //keep track of number of brows, bcols. // not yet sure if I should enforce matrix sizes to be multiples of BLOCK _brows = (I+1)>_brows ? I+1 : _brows; _bcols = (J+1)>_bcols ? J+1 : _bcols; if(I==curr_brow && J==curr_bcol) { data[index(bidx, i, j)] += val; } else { ++bidx; if(curr_brow != I) { for(size_type r=curr_brow+1; r<=I; ++r) { brow_ptr[r] = bidx; } curr_brow = I; } curr_bcol = J; bcol_index[bidx] = J; data[index(bidx, i, j)] += val; } } brow_ptr[_brows] = nblocks; }
static void resize( const container_type &x , container_type &dxdt ) { dxdt.resize( x.size1() , x.size2() ); }