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


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

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


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

示例1: extractTripletData

void MathUtilities::extractTripletData( const SparseMatrixsc& matrix, VectorXi& rows, VectorXi& cols, VectorXs& vals )
{
  rows.resize( matrix.nonZeros() );
  cols.resize( matrix.nonZeros() );
  vals.resize( matrix.nonZeros() );
  int flat_index{ 0 };
  for( int outer_index = 0; outer_index < matrix.outerSize(); ++outer_index )
  {
    for( Eigen::SparseMatrix<double>::InnerIterator it( matrix, outer_index ); it; ++it )
    {
      rows( flat_index ) = it.row();
      cols( flat_index ) = it.col();
      vals( flat_index++ ) = it.value();
    }
  }
  assert( flat_index == matrix.nonZeros() );
}
开发者ID:hmazhar,项目名称:scisim,代码行数:17,代码来源:MathUtilities.cpp

示例2: deserialize

// TODO: Use utility class here
void MathUtilities::deserialize( SparseMatrixsc& A, std::istream& stm )
{
  assert( stm.good() );

  VectorXi col_ptr;
  VectorXi row_ind;
  VectorXs val;

  // Read the number of rows in the matrix
  int rows{ -1 };
  stm.read((char*)&rows,sizeof(int));
  assert( rows >= 0 );
  // Read the number of columns in the matrix
  int cols{ -1 };
  stm.read((char*)&cols,sizeof(int));
  assert( cols >= 0 );
  // Read the column pointer array
  col_ptr.resize(cols+1);
  stm.read((char*)col_ptr.data(),col_ptr.size()*sizeof(int));
  // Read the number of nonzeros in the array
  int nnz{ -1 };
  stm.read((char*)&nnz,sizeof(int));
  assert( nnz >= 0 );
  // Read the row-index array
  row_ind.resize(nnz);
  stm.read((char*)row_ind.data(),row_ind.size()*sizeof(int));
  // Read the value array
  val.resize(nnz);
  stm.read((char*)val.data(),val.size()*sizeof(scalar));

  A.resize(rows,cols);
  A.reserve(nnz);

  for( int col = 0; col < cols; ++col )
  {
    A.startVec(col);
    for( int curel = col_ptr(col); curel < col_ptr(col+1); ++curel )
    {
      int row = row_ind(curel);
      scalar curval = val(curel);
      A.insertBack(row,col) = curval;
    }
  }
  A.finalize();
}
开发者ID:hmazhar,项目名称:scisim,代码行数:46,代码来源:MathUtilities.cpp

示例3: extractDataCCS

void MathUtilities::extractDataCCS( const SparseMatrixsc& A, VectorXi& col_ptr, VectorXi& row_ind, VectorXs& val )
{
  col_ptr.resize( A.cols() + 1 );
  row_ind.resize( A.nonZeros() );
  val.resize( A.nonZeros() );

  col_ptr(0) = 0;
  for( int col = 0; col < A.outerSize(); ++col )
  {
    col_ptr(col+1) = col_ptr(col);
    for( SparseMatrixsc::InnerIterator it(A,col); it; ++it )
    {
      const int row{ it.row() };

      val(col_ptr(col+1)) = it.value();
      row_ind(col_ptr(col+1)) = row;
      ++col_ptr(col+1);
    }
  }

  assert( col_ptr( col_ptr.size() - 1 ) == row_ind.size() );
}
开发者ID:hmazhar,项目名称:scisim,代码行数:22,代码来源:MathUtilities.cpp


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