![]() Registered Member ![]()
|
Hi all,
is SparseVector supposed to have a cwiseMax() ? Compilation of the following
Results in
Would copying the definition from src / Core / DenseBase.h into src/SparseCore/SparseVector.h be the fix, or are there other things I need to take into account ? |
![]() Moderator ![]()
|
There is no such function for sparse objects because it is not clear what should be returned in general, though I agree that mat.cwiseMax(0) might make sense, so 0 would the only acceptable parameter.
|
![]() Registered Member ![]()
|
Probably I'm missing something:
Could SparseVector.cwiseMax(a) return a generator function, which returns max(0, a) for all empty entries ? Currently I'm using this in a weighed-least-quare fit (from the top of my head, so pardon the math-errors):
Where D, E and w are sparse, and quite large. A and b are small and dense. So the cwiseMax() is there to prevent division by zero. |
![]() Moderator ![]()
|
the problem is that rigorously w.cwiseMax(th) should replace all empty coefficient by th (assuming th>0) thus leading to a dense vector. However, you can remove the smallest entries with:
w.prune(1,1e-6); // 1 == a reference non zero value, 1e-6 == the threshold Then, for your use case, I'd currently recommend to "pack" D, and W such that W becomes dense:
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]