I often want to have a reshaped view of an existing array or matrix. For example, view a 3xK matrix as a 3K x 1 vector to perform a linear operation on the vertices of a model. This can be achieved with the Eigen::Map object, but is rather verbose. It would be great, if eigen had a .reshape(h,w) function which would return an Eigen::Map with a new view on the data. Could this be implemented? Do other people also need this funcitonality? I believe, that it is quite common, when you are coming from a matlab mindset. kind regards, Brian
After working a bit more on my problem, I see that it would really be best to get as the return a reshape expression, not an Eigen::Map, as the reshape might happen on a non-evaluated expression. How complicated is it to implement this?
I think basically you can implement it the same way as Block is implemented -- of course with different index calculations.
Thank you for the feedback. I currently have no spare time to dig into this, is anyone willing to take it up?
Would anyone be willing to walk me through this. The Eigen code is quite complex, but if there is someone holding my hand I think I could make the necessary adaptations without breaking anything. Christoph maybe?
OK, the quick hack would be to copy Eigen/src/Core/Block.h and literally search and replace all Block by Reshape, then adapt all index calculations and the constructors. Most likely you also need forward-declarations in Eigen/src/Core/util/ForwardDeclarations.h and then include the new file somewhere from Eigen/Core. Next and final step is to implement some reshape member functions -- also similar to the way the block member functions are implemented (Eigen/src/plugin/BlockMethods.h) -- and add them to Eigen/src/Core/DenseBase.h. This solution will most likely not break anything, so have no fear *g*. Overall, this solution will result in a lot of code duplication, so I guess the cleaner solution would be to make the Block-class more general, maybe also fixing bug 58, by making Map essentially be a (trivial) Block. W.r.t Eigen's code complexity, I guess it is more a problem of the poor internal documentation (see bug 138).
Hello Christoph, so after looking at Block.h I feel a bit intimidated. Can you explain the purpose and way of functioning of the template specialization at the end? And will I need to change anything inside the traits block? How about the packet access, how does that work, what do I have to keep in mind while tinkling with it? thank you, Brian
+1. reshape() with a vec() specialization would be greatly appreciated. Perhaps a more general "View" interface which implements block(), diagonal(), diagonalize(), reshape() and vec() would be the way to go.
@Brian: Sorry for not responding (for very long). I may have time between the years to look into that. @Hilton: Yes, Bug 712 will basically fall of this feature, using (size(), 1) as parameters. Generally, I think a clean solution should return something equivalent to a Map if possible. However, things like MatrixXd M; M.topLeftCorner(...,...).reshape(...,...); will have changing inner strides, so they could not be represented by a map -- and of course it only works for DirectAccess types.
Hi all :) I am new to the eigen project. I have done some work about this issue. It works basically. Except the specialization of the "direct access". I currently have no idea what that is. https://bitbucket.org/eigen/eigen/pull-request/41/reshape/diff Please give me any suggestion if I done anything wrong. thanks in advance.
Merged in PR 301: https://bitbucket.org/eigen/eigen/pull-requests/301
-- GitLab Migration Automatic Message -- This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/437.