本文整理汇总了C++中SparseMatrixsc::prune方法的典型用法代码示例。如果您正苦于以下问题:C++ SparseMatrixsc::prune方法的具体用法?C++ SparseMatrixsc::prune怎么用?C++ SparseMatrixsc::prune使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparseMatrixsc
的用法示例。
在下文中一共展示了SparseMatrixsc::prune方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: formGeneralizedSmoothFrictionBasis
// TODO: Despecialize from smooth
void FrictionOperator::formGeneralizedSmoothFrictionBasis( const unsigned ndofs, const unsigned ncons, const VectorXs& q, const std::vector<std::unique_ptr<Constraint>>& K, const MatrixXXsc& bases, SparseMatrixsc& D )
{
assert( ncons == K.size() );
const unsigned nambientdims{ static_cast<unsigned>( bases.rows() ) };
const unsigned nsamples{ nambientdims - 1 };
D.resize( ndofs, nsamples * ncons );
auto itr = K.cbegin();
{
VectorXi column_nonzeros( D.cols() );
for( unsigned collision_number = 0; collision_number < ncons; ++collision_number )
{
for( unsigned sample_number = 0; sample_number < nsamples; ++sample_number )
{
assert( nsamples * collision_number + sample_number < column_nonzeros.size() );
column_nonzeros( nsamples * collision_number + sample_number ) = (*itr)->frictionStencilSize();
}
++itr;
}
assert( ( column_nonzeros.array() > 0 ).all() );
assert( itr == K.cend() );
D.reserve( column_nonzeros );
}
itr = K.cbegin();
for( unsigned collision_number = 0; collision_number < ncons; ++collision_number )
{
for( unsigned sample_number = 0; sample_number < nsamples; ++sample_number )
{
const unsigned current_column{ nsamples * collision_number + sample_number };
const VectorXs current_sample{ bases.col( nambientdims * collision_number + sample_number + 1 ) };
assert( fabs( current_sample.dot( bases.col( nambientdims * collision_number ) ) ) <= 1.0e-6 );
(*itr)->computeGeneralizedFrictionGivenTangentSample( q, current_sample, current_column, D );
}
++itr;
}
assert( itr == K.cend() );
D.prune( []( const Eigen::Index& row, const Eigen::Index& col, const scalar& value ) { return value != 0.0; } );
assert( D.innerNonZeroPtr() == nullptr );
}