Re: [eigen] Overloading componentwise binary operators for vectors

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


Hello Marc,

thank you for your answer.

Of course, there's a constructor:

template<typename ScalarType>
Vector<ScalarType>::Vector<ScalarType>(std::size_t size)
: wrapped_(size)
{}

It does not work because I get an error message:


erreur: ambiguous overload for ‘operator+’ (operand types are ‘Vector<double>’ and ‘Vector<double>’)
CPPUNIT_ASSERT_EQUAL(sum, left+right);

Cédric

----- Mail original -----
> De: "Marc Glisse" <marc.glisse@xxxxxxxx>
> À: eigen@xxxxxxxxxxxxxxxxxxx
> Envoyé: Vendredi 2 Octobre 2015 22:53:38
> Objet: Re: [eigen] Overloading componentwise binary operators for vectors
> 
> On Fri, 2 Oct 2015, Cedric Doucet wrote:
> 
> > I try to overload binary operators for a VectorWrapper but I don't manage
> > to do it.
> > My wrapper looks like this :
> >
> > ========================================================
> > template<typename ScalarType>
> > class Vector
> > {
> > public:
> > typedef Eigen::Matrix<ScalarType,Eigen::Dynamic,1> VectorType;
> >
> > private:
> > VectorType wrapped_;
> > };
> > ========================================================
> >
> > Don't worry about names, data structure, etc, or the necessity of wrapping
> > such a thing: it is just an example to illustrate my problem.
> > So, I would like to overload binary operators for Vector class, for example
> > the sum of two vectors.
> > It seems that the classical version:
> >
> > ========================================================
> > template<typename ScalarType>
> > Vector<ScalarType> operator+(Vector<ScalarType> const & lhs,
> > Vector<ScalarType> const & rhs)
> > { return lhs.wrapped_ + right.wrapped_; }
> > ========================================================
> >
> > does not work. I guess it is because an expression template is returned by
> > operator + in Eigen.
> 
> Er, clearly you left some code out, because Vector doesn't have any
> constructor and you construct one from an int in the test (and expect to
> construct one from something convertible to a VectorType in operator+).
> You also failed to mention what "doesn't work" means.
> 
> --
> Marc Glisse
> 
> 
>



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