Re: [eigen] Overloading componentwise binary operators for vectors

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


Hello Christoph,

thank you very much for your answer.

> As Gael already said, your Vector class also needs to have a constructor
> which accepts a DenseBase<Derived> (or a Wrapped::Sum, if you prefer).

Ok, I will try this solution but I don't understand why it would solve the problem of my main example:

Vector sum(3);
sum = lhs + rhs;

First, I construct a vector.
Then, I assign the result of lhs+rhs in sum (operator=).
I would expect the overloading of assignment operator to be called:

Vector & operator=(Sum const & result)
{ 
  wrapped_ = result; 
  return *this; 
}

Of course, the code is not optimal and I will implement Vector::Vector(Sum const &) anyway, in order to be able to write:

Vector sum = lhs + rhs;

But I would really appreciate to understand what is happening here.

> Btw, to me it is still not obvious what you actually want to achieve
> here ...

I could try to explain but it's not obvious to guess what is not obvious to you from your sentence... ;)


Cédric

----- Mail original -----
> De: "Christoph Hertzberg" <chtz@xxxxxxxxxxxxxxxxxxxxxxxx>
> À: eigen@xxxxxxxxxxxxxxxxxxx
> Envoyé: Lundi 5 Octobre 2015 16:39:21
> Objet: Re: [eigen] Overloading componentwise binary operators for vectors
> 
> 
> 
> On 05.10.2015 16:00, Cedric Doucet wrote:
> > Actually, it is very simple to get the best of both worlds if I understand
> > how to overload operator + so that it returns Eigen::CwiseBinaryOp.
> > I just have to add a level of indirection by replacing Eigen::CwiseBinaryOp
> > by a typedef coming from a template:
> >
> > template<typename Wrapped>
> > class Vector;
> >
> > template<typename Wrapped>
> > typename Wrapped::Sum operator+(Vector const & lhs, Vector const & rhs);
> >
> >
> > So, my question is very simple : what am I doing wrong in the code I sent
> > to you?
> 
> 
> As Gael already said, your Vector class also needs to have a constructor
> which accepts a DenseBase<Derived> (or a Wrapped::Sum, if you prefer).
> 
> Btw, to me it is still not obvious what you actually want to achieve
> here ...
> 
> 
> Christoph
> 
> --
>   Dipl. Inf., Dipl. Math. Christoph Hertzberg
> 
>   Universität Bremen
>   FB 3 - Mathematik und Informatik
>   AG Robotik
>   Robert-Hooke-Straße 1
>   28359 Bremen, Germany
> 
>   Zentrale: +49 421 178 45-6611
> 
>   Besuchsadresse der Nebengeschäftstelle:
>   Robert-Hooke-Straße 5
>   28359 Bremen, Germany
> 
>   Tel.:    +49 421 178 45-4021
>   Empfang: +49 421 178 45-6600
>   Fax:     +49 421 178 45-4150
>   E-Mail:  chtz@xxxxxxxxxxxxxxxxxxxxxxxx
> 
>   Weitere Informationen: http://www.informatik.uni-bremen.de/robotik
> 
> 
>



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