Re: [eigen] Using Eigen::Map to use eigen operations on my data

[ Thread Index | Date Index | More Archives ]

2009/10/29 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
> 2009/10/29 Robert Lupton the Good <rhl@xxxxxxxxxxxxxxxxxxx>:
>> I guess I boiled this down too far (boiled it dry?).
>> I'm writing some swig bindings to pass numpy arrays to code that uses Eigen.
>>  I can unpack the data from the numpy arrays, so I have a (float *data, int
>> nx, int ny) tuple.  I'd like to pass that to my routines that expect
>> Eigen::MatrixXf.
>> After Benoit's explanation, it looks as if I need to redo my interface to
>> expect Map<MatrixXf> or (to preserve the option of passing MatrixXf)
>> template them over the argument type --- for type safety, Benoit proposes
>> using MatrixBase<T>.
> Exactly!
>> Fine, I can do that --- although the details of the swig typedefs will be
>> nasty as templates must be explicitly expanded.  I can work on that.
> If you need only MatrixXf and Map<MatrixXf>, you could code these as 2
> separate functions and do without templates. (They could internally
> call a common template function that would be an implementation
> detail).
>> I still think that the manual entry is confusing --- it maps an array and
>> then assigns it to a Matrix2f but all the mapping is doing is initialising
>> the memory.
> Indeed. I'll try to remember to clarify that.

Sorry, I can't find the example you're talking about. Can you show me?
It sounds confusing indeed.


>Note that the docs also talk about:
>     * This class represents a matrix or vector expression mapping an >existing array of data.
>     * It can be used to let Eigen interface without any overhead with >non-Eigen data structures,
>     * such as plain C arrays or structures from other libraries.
> Which is true, but apparently not quite as simple as it might seem.

Here on the other hand, i don't see how this should be changed? The
difficulty in your case didnt come from Eigen, it  rather seems that
you hit generic difficulties in interfacing templated code with
something (swig) that doesn't like templates.


Mail converted by MHonArc 2.6.19+