Re: [eigen] Overloading componentwise binary operators for vectors

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



On Fri, Oct 2, 2015 at 10:25 PM, Cedric Doucet <cedric.doucet@xxxxxxxx> wrote:
========================================================
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..

This should work if your Vector class has a template constructor from an Eigen::DenseBase<Derived>. Of course, this way you will loose the benefits of Eigen's _expression_ templates.


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

Please show what are the multiple versions of operator+ found by the compiler.

Anyways, instead of writing a wrapper, maybe extending MatrixBase<> to add compatibility methods or inherit Matrix<> could work for you? See:
http://eigen.tuxfamily.org/dox-devel/TopicCustomizingEigen.html

gael





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