Re: [eigen] is MAP oneway ? (urgent)

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


On 24 Jun, Gael Guennebaud wrote:
> On Wed, Jun 24, 2009 at 2:13 PM, Helmut
> Jarausch<jarausch@xxxxxxxxxxxxxxxxxxx> wrote:

>> Is there something like "overlaying" an Eigen-Vector onto some raw
>> C-array?
> 
> this is exactly what Map do, however you have to deal with Map object
> directly, e.g.
> 
> double* c_like_data = whatever;
> 
> Eigen::Map<VectorXd> v(c_like_data, size);
> 
> then you can use "v" just like any other Eigen matrix/vector:
> 
> v *= 10;
> 
> is equivalent to:
> for (int i=0; i<size; ++i)
>  c_like_data[i] *= 10;
> 

But now, I have the ugly problem with reference types 
#include <iostream>
using std::cerr;  using std::endl;
#include <Eigen/Core>
// import most common Eigen types 
USING_PART_OF_NAMESPACE_EIGEN

void process(VectorXd& DATA);

int main() {
  double data[4] = {1, 2, 3, 4};
  
  Eigen::Map<VectorXd> D(data,4);
  process(D); // ERROR! invalid initialization of reference 
              // of type 'Eigen::VectorXd& ....
  cerr << "D before : " << D << endl;
  data[1]= 7;
  cerr << "D after  : " << D << endl;  // nothing has changed
  D[1]= 17;
  cerr << "data[1] now: " << data[1] << endl;
}

Since I have no time to wait for a compiler implementing the new
reference types of C++ 2010, is there a nice solution?

-- 
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany



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