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

Inheriting from Array/Matrix?

Tags: None
(comma "," separated)
kp0987
Registered Member
Posts
21
Karma
0

Inheriting from Array/Matrix?

Sat Mar 12, 2011 9:41 pm
I am using Eigen3 Arrays to store Nx2 complex numbers to represent 2 complex series of datapoints vs time. I need to perform some operations (similar to norms, for example) on these arrays (which I can do using a DenseBase plugin), but I also need to store some meta-data information about the arrays (eg they are a time-series so I need to store the time step between datapoints).

To do this I create an Eigen Array and store it in a shared pointer. I then pass this as an argument in the constructor of a class that holds the meta-data as well as the shared pointer. In this way I can work on the Eigen Array directly and avoid needing to provide all the Array accessors, and I can work on the meta-data+array object as well, depending on need. But it's not a great solution as it removes a level of data hiding (I avoid major problems with this by ensuring that the majority of the use of the Array/Meta-data class is via read only const, but it's not ideal).

I am wondering if there is an alternative, such as inheriting from Array, but I notice in http://eigen.tuxfamily.org/dox-devel/To ... Eigen.html that this is really not recommended. Can I ask why this is so? Are there any suggestions for how to implement the above in an improved manner?

Thanks.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Inheriting from Array/Matrix?

Tue Mar 15, 2011 10:07 am
inheriting Array or Matrix is fine as long as you know what you are doing. For instance, is Foo inherit Array, then adding to Foo objects and evaluating them ( (foo0+foo1).eval() ) wont give you a Foo but an Array. That said, in your case, I'm not sure there is any benefit of inheriting Array, instead of having a custom class storing an Array and your additional members but well go as you prefer.
kp0987
Registered Member
Posts
21
Karma
0

Re: Inheriting from Array/Matrix?

Tue Mar 15, 2011 2:26 pm
Thanks. I think it would be valuable to provide a bit more detail in the docs about the implications of inheriting from Matrix. Your description was enough to put me off!


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], q.ignora