当前位置: 首页>>代码示例>>C++>>正文


C++ container_type::resize方法代码示例

本文整理汇总了C++中container_type::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ container_type::resize方法的具体用法?C++ container_type::resize怎么用?C++ container_type::resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在container_type的用法示例。


在下文中一共展示了container_type::resize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

 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];
     }
 }
开发者ID:jeremyfix,项目名称:multivec,代码行数:7,代码来源:vec.hpp

示例2: ts

  /*
   * 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;
  }
开发者ID:tjolsen,项目名称:YAFEL,代码行数:91,代码来源:sparse_bcsr.hpp

示例3: resize

 static void resize( const container_type &x , container_type &dxdt )
 {
     dxdt.resize( x.size1() , x.size2() );
 }
开发者ID:chopki01,项目名称:FunctionEstimation,代码行数:4,代码来源:container_traits_ublas_matrix.hpp


注:本文中的container_type::resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。