Bugzilla – Bug 597
Prune does not work as documented
Last modified: 2013-06-10 13:11:13 UTC
Created attachment 336 [details]
Test code for bugs in prune() method in sparse matrix
Pruning (deleting entries with an absolute value smaller than a threshold) sparse matrices does not work as documented, please see the test code attached.
The problem arises in version 3.1.6 and newer.
The documentation states (taken from current <http://eigen.tuxfamily.org/dox/TutorialSparse.html>):
The second algorithm prunes on the fly the explicit zeros, or the values smaller than a given threshold. It is enabled and controlled through the prune() functions:
sm3 = (sm1 * sm2).prune(); // removes numerical zeros
sm3 = (sm1 * sm2).prune(ref); // removes elements much smaller than ref
sm3 = (sm1 * sm2).prune(ref,epsilon); // removes elements smaller than ref*epsilon
But none of the three methods works, the code does not compile.
The compiler error is "'const Type' has no member named 'prune'" in all three cases.
Moreover, calling the method prune for a SparseMatrix<double> does not work when no argument is specified, at least ref must be given.
The compiler error message is "no matching function for call to 'Eigen::SparseMatrix<double>::prune()'".
I would like to propose to set the default value of ref to 1.0.
Furthermore, prune() seems to only work in-place. Would it be possible to provide also a version for assignment, e.g. "sm2 = sm1.prune();"?
Marked as blocking 3.2.
I guess the not in-place method should be called something like pruned() (cf. transpose() and transposed()).
Furthermore, I find the "removes elements much smaller than ref" behavior somewhat non-intuitive.
I do see the use-case, but I would expect prune(threshold) to prune everything above threshold and not threshold*epsilon. But I guess we can't change that anymore.
(In reply to comment #1)
> I guess the not in-place method should be called something like pruned() (cf.
> transpose() and transposed()).
Please ignore the transpose()/transposed() part ...
But we do have normalize() vs normalized().
This was just a typo in the tutorial. pruned() returns an expression, while prune() works inplace. I guess this close the bug:
Date: 2013-06-10 12:03:55
Summary: Fix bug 598: add explicit cast to Scalar type
oops, the commit is:
Date: 2013-06-10 12:13:31
Summary: fix bug 597: typo in sparse documentation