本文整理汇总了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() );
}
示例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();
}
示例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() );
}