[eigen] Being able to use Eigen::Map<Eigen::Matrix< ... > > everywhere you can use a Eigen::Matrix |

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: [eigen] Being able to use Eigen::Map<Eigen::Matrix< ... > > everywhere you can use a Eigen::Matrix*From*: Malcolm Reynolds <malcolm.reynolds@xxxxxxxxx>*Date*: Mon, 18 Feb 2013 21:05:16 +0000*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:from:date:message-id:subject:to :content-type; bh=2pKHB/XTksZMCAntsJ0si9WFIhvzfjaWJRwItbgyz3o=; b=0rG/qj9pITJUKtq5qn5YNP3i1eKViLe1z93m/t2rR3M09mH6/dkleFGh83JRYRYxP0 759RjmK78TA67RWeSHsAKIFKGErDVAk8+8JzqlRGfZaA99stKVJ1izsnWWyillSGzP6W GHR70QBcTxzxLanhUOQGCNb7M369NjmcnWDAIJ0CaFk7wFyBptntRhoQ2yzbdMBjY0Gr 2Ug4v+75Wuf6Bh1RCRz140y29CoxYYofZDJMlMzk3W9dlIY9qYExo686QblO8WJMGwTm 6R5U/KW4mZLuGQ/xY5yL8AiqfJeav+rGl9iZ6NqOHaKIKyoU1IZvIlEL0F0fR0HXAage SPKQ==

Hi everyone,

First post to this list, apologise if this is something really obvious but I'm having a bit of trouble using Eigen::Map. As I understand, it allows me to declare an Eigen matrix which reuses some memory already allocated (in my cases I'm gettin the data pointer from Numpy matrices), and then use this value everywhere I can use a regular Eigen matrix? I'm having trouble getting this to work, and potentially what I want to do isn't possible, but I haven't found any explanation in the docs. Please bear in mind I am far from a C++ pro!

I have a function which I'd already written with the signature

predict(const MatrixXd & features, MatrixXd * const labels_out)

following the good practice (afaik) of using const refs for parameters that don't need to be modified, and pointers otherwise. Anyway I'd like to pass in Eigen::Maps for both arguments of this function, as I'm writing a python interface for my library. I'm constructing the maps and storing them in shared_ptrs, then dereferencing the shared pointer for the ref argument and simply passing the pointer for the second argument. Looks a bit like this...

// Get the data from Numpy into Eigen::Maps

boost::shared_ptr<const Eigen::Map<MatrixXd> > features( new Eigen::Map<double>((double*) PyArray_DATA(features_np)));

boost::shared_ptr<Eigen::Map<MatrixXd> > labels( new Eigen::Map<double>((double*) PyArray_DATA(labels_np)));

// call the function

predict(*features, labels.get())

This gives a compiler error about the second argument, saying cannot initialize a parameter of type

'label_mtx<double> *' (aka 'Eigen::Matrix<double, -1, -1, 0, -1, -1> *') with an rvalue of type

'Eigen::Map<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 0, Eigen::Stride<0, 0> > *'

predict(*features, predict_mean_out.get());

(label_mtx<T> is just a templated typedef I've made for Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>)

I don't understand why what I've done is valid for the first argument but not for the second argument? It seems like both of them are passing in a Map<MatrixXd> to

a function that expects a MatrixXd, so on some level the compiler understands the equivalence of Maps with normal matrices. Given that, why does the first case work and the second one not? Is it to do with the pointer / ref difference, or to do with the const-ness?

Any advice that anyone has would be greatly appreciated! Also have to say a big thankyou to the authors of the library, only been using it for a few weeks but the productivity improvement over ublas is huge.

Malcolm

**Follow-Ups**:

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] SuperLU include directories** - Next by Date:
**Re: [eigen] Being able to use Eigen::Map<Eigen::Matrix< ... > > everywhere you can use a Eigen::Matrix** - Previous by thread:
**Re: [eigen] SuperLU include directories** - Next by thread:
**Re: [eigen] Being able to use Eigen::Map<Eigen::Matrix< ... > > everywhere you can use a Eigen::Matrix**

Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |