This forum has been archived. All content is frozen. Please use KDE Discuss instead.

map use support

Tags: None
(comma "," separated)
stuart-macg
Registered Member
Posts
18
Karma
0
OS

map use support

Wed Nov 10, 2010 8:07 am
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?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: map use support

Wed Nov 10, 2010 8:20 am
stuart-macg wrote: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?


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.

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?


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...
stuart-macg
Registered Member
Posts
18
Karma
0
OS

Re: map use support

Wed Nov 10, 2010 8:57 am
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.


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient