Registered Member
|
There isn't a conservativeResize() for SparseVector. I need to resize while leaving old values untouched. How do I do this for a SparseVector?
Or if copying is the only way to do it, how can i copy a smaller SparseVector to a bigger SparseVector? In any case, I could always copy each element but there could be a better (faster) way. Thanks. |
Moderator
|
You can extend SparseVector via EIGEN_SPARSEVECTOR_PLUGIN (see http://eigen.tuxfamily.org/dox/TopicCus ... Eigen.html), and send us a patch to be included in next releases.
|
Registered Member
|
Thank you. I extended SparseVector as you suggested.
I think this code works good enough.
|
Moderator
|
that's a bit more complicated:
1 - if newSize<m_size, then coefficients above newSize have to be removed. 2 - you should not call m_data.reserve(newSize); as this allocate the amount of memory equivalent to a dense vector. |
Registered Member
|
Thanks for pointing that out. I got confused with nonZero(m_data) size and row size.
From the code, I guess the philosophy is to allocate memory on-demand, so no resizing m_data when newSize>m_size. (though resizeNonZeros can be called after) I tried some quick tests and i think this attempt seems to work.
|
Moderator
|
This version is still broken Anyway, here it is:
https://bitbucket.org/eigen/eigen/commits/528c88972ed4/ Summary: Add SparseVector::conservativeResize() method. |
Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft