Smittii
Smittii

Reputation: 187

Array of user defined struct in Eigen

I wonder whether it is possible to adapt an array with more complex data to be used as an vector or matrix in Eigen.

example:

struct data
{
    /* some members...*/
    double numericValue;
    /* more members...*/
};
std::vector<data*> dataset;

is it possible to tell eigen how to access the numericValue member and use dataset for calculations? I found the map class in the docs but not the required functionality. Any ideas?

Upvotes: 0

Views: 1980

Answers (1)

Jakob
Jakob

Reputation: 2380

I am not sure if I understand you question correctly, but that you have structured data, in which you have interleaved elements, that you would like to combine into a Vector or Matrix in order to perform Eigen Operations on it.

If this is what you are interested in, indeed the Map type is your friend. The following expression should give you what you want (untested):

typedef Map<VectorXd, 0, InnerStride<sizeof(data)/sizeof(double)> > MyMap;
MyMap map( &dataset[0].numericValue, dataset.size() );

now you can e.g. do something like

map *= 2.0;

in order multiply all your numericValue members by 2.0.

Upvotes: 1

Related Questions