Registered Member
|
The Map class can give a reshaped (as in Matlab reshape) view of a Matrix or Array, but to get a pointer to the data for Map I can only see &m(0,0), or Block(m).data() (details left out).
This all feels a bit dirty. Might it be possible to add direct support for reshape, with size errors etc? The hint in the Map documentation to allow use of placement new to effectively re-run the constructor of a Map gives a really nice feature. Possibly naughty but nice. It relies on Map not requiring its destructor called. It does mean that I can have a class containing/using different views of an aligned data structure (e.g. FFTW multi input and output), and support resize/reshape operations nicely. A default constructor (null pointer, zero size)? would be nice. Any thoughts anyone? |
Moderator
|
Yes this feature has been requested many times, please feel free to add a bug for it: http://eigen.tuxfamily.org/bz To reshape a Matrix object, it's very, and it is just a matter of returning the appropriate Map object. So you could even do it yourself and propose a patch, and/or use the plugin mechanism. This would already cover 95% of the use cases. For general expression, however, it is a bit more tricky to do it right in a general way.
You can still initialize them with: ctor() : map_member(0,0,0), ... because I'm not really convinced that's a good idea to add such a default ctor... |
Registered Member
|
I'll just define a templated view class with a default constructor inheriting from Map. I expect I can use the placement new with the "this" pointer in a method to re-use the map-derived object on new and/or reshaped data, making it a sort of generalised pointer object. The new object could also add overloaded/templated methods to take Array or Matrix objects instead of a data pointer, allowing some sanity checks and makeing the user level code feel cleaner.
A class for doing the PARACOR algorithm for instance could use different shaped matrix views (slices) of common aligned arrays of 3 way data, and be re-sized by the user. Thanks for the quick response. |
Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient