Manually set lower bound for CompressedMatrix zero value
It's useful when performing functions on a CompressedMatrix to be able to "prune" close-to-zero values from it. After a few operations my CompressedMatrix is effectively becoming dense due to the large number of close-to-zero values. Being able to define a threshold and manually prune values from CompressedMatrices would reduce this problem.
Comments (5)
-
-
reporter Thank you Klaus for your response. I look forward to this being implemented. Is there an IRC channel or forums to discuss blaze further with you?
-
-
assigned issue to
-
assigned issue to
-
- changed status to open
-
- changed status to resolved
Summary
The feature has been implemented, tested, optimized and documented as required. It is immediately available via cloning the Blaze repository and will be officially released in Blaze 3.1.
Sparse Vectors
The interface of all sparse vectors (
CompressedVector
and all sparse vector views) has been extended by two additionalerase()
member functions, which accept an unary predicate:template< typename Pred, typename = DisableIf_< IsIntegral<Pred> > > void erase( Pred predicate ); template< typename Pred > void erase( Iterator first, Iterator last, Pred predicate );
Via these functions it is for instance possible to erase all elements with values smaller than a certain threshold:
blaze::CompressedVector<double> a; // ... Resizing and initialization a.erase( []( double value ){ return value < 1E-8; } );
Note: The predicate is required to be pure, i.e. to produce deterministic results for elements with the same value. The attempt to use an impure predicate leads to undefined behavior!
Sparse Matrices
The interface of all sparse matrices (
CompressedMatrix
, all adaptors, and all sparse matrix views) has been extended by two additionalerase()
member functions, which accept an unary predicate:template< typename Pred > void erase( Pred predicate ); template< typename Pred > void erase( size_t i, Iterator first, Iterator last, Pred predicate );
Via these functions it is for instance possible to erase all elements with values smaller than a certain threshold:
blaze::CompressedMatrix<double,blaze::rowMajor> A; // ... Resizing and initialization A.erase( []( double value ){ return value < 1E-8; } );
Note: The predicate is required to be pure, i.e. to produce deterministic results for elements with the same value. The attempt to use an impure predicate leads to undefined behavior!
- Log in to comment
Hi!
Thanks a lot for the good proposal. We will add the functionality as soon as possible. Until we have decided on the final interface for the feature and finished the implementation, you can use the following function to prune close-to-zero elements from a
CompressedMatrix
:Best regards,
Klaus!