Re: [eigen] Strange issue with Array of Array3f

[ Thread Index | Date Index | More Archives ]


the last line already compiles fine in the default branch. The main problem for the first failing example is that in:

 m + (-Array3f(5.0f))

operator+ is called with an _expression_ object, not an Array3f. Therefore, it follows the wrong overload of operator+ that is trying to add the coefficients of 'm' with the coefficients of 'Array3f(5.0f)'. This triggers a scalar mismatch (Array3f versus float), and also a size mismatch (2x2 versus 3x1). You would have the same issue whenever the scalar is an _expression_, like:

m + 2*v

The general workaround consists in evaluating the _expression_ into an Array3f, e.g.:

m + (2*v).eval()


m + Array3f(2*v)

I'm not sure this can be properly fixed on our side.



On Fri, Sep 4, 2015 at 2:54 PM, Wenzel Jakob <wenzel@xxxxxxxxxxxxxxxxxxxx> wrote:
Hi everyone,

I wanted to point your attention to a strange issue my colleague Wojciech Jarosz has encountered when working with Arrays of RGB color data (encoded using as Array3f).

This is a minimal snippet of code illustrating the issue.

#include <Eigen/Core>

using namespace Eigen;

int main(void)
    typedef Array<Array3f, Dynamic, Dynamic> MyArray;
    MyArray m(2,2);

    // all of the following should have the same mathematical effect

    Array3f v = -Array3f(5.0f);             // this compiles

    MyArray a = m + v;                      // this compiles
    MyArray b = m + Array3f(-5.0f);         // this compiles
    MyArray c = m + (-Array3f(5.0f));       // this doesn't compile
    MyArray d = m - Array3f(5.0f);          // this doesn't compile

Any thoughts or suggestions would be greatly appreciated.

Thank you,

Mail converted by MHonArc 2.6.19+