Re: [eigen] Expression templates and CwiseBinaryOp |

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

*To*: eigen <eigen@xxxxxxxxxxxxxxxxxxx>*Subject*: Re: [eigen] Expression templates and CwiseBinaryOp*From*: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>*Date*: Wed, 3 Aug 2016 23:24:34 +0200*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=9QkZSrhHiGRxSDOvzevJLBpLQzu82elKK0UUrAumo1k=; b=G2565SltnIa/80RGpLViol+5iqKwc7g0LbZhq1LYSsQ2gGqC1PirOh41DNz/hiJdKd TT9h2jxijVZiH+W+PLD+IijC2kpMUmhFlmTAgRLYta+P7nz8rxazhJ2q9h0KicLtE4a5 f6NMxcthO8zyE+pT/i8N55Lw27XC4l+cq8fitj2i8ryCzJ6FrNGDUvrdfKgQt3MR5bN1 Ca//kBJ3Nnjt7NaxiiUjCsJuY5mw9SKZ+t6bIRMc4Jw0BpigFkJDv3RgYOYTwsmcT51v kv72TOIeSTQ0IFx4kbBw5iWnbHMzMHBQxktaKIZc+2FnvEOjVlZC1pmuj3Rw6TePLsaT I2Cg==

Hi,

I answered your question there: http://stackoverflow.com/questions/38749492/_expression_-templates-in-eigen

you can also find some details there : http://downloads.tuxfamily.org/eigen/eigen_CGLibs_Giugno_Pisa_2013.pdf, starting from slide 40.

gael

On Wed, Aug 3, 2016 at 3:12 PM, Cedric Doucet <cedric.doucet@xxxxxxxx> wrote:

Hello,I would like to understand how _expression_ templates work in Eigen.I understood that the sum of two dynamical double vectors is performed by something which looks like this :CwiseBinaryOp< internal::scalar_sum_op<double>, VectorXd const, VectorXd const > operator+(VectorXd const & lhs, VectorXd const & rhs);I also understood how the difference of two vectors is implemented.I have two questions.1. How does the product of a vector by a scalar work?I have noticed that CwiseBinaryOp< internal::scalar_product_op<double>, VectorXd const, VectorXd const > exists but I have the feeling that it is only designed to perform componentwise operations between two vectors.Does it mean that the product of a vector by a scalar correspond to a unary operator, say CwiseUnaryOp< internal::scalar_product_op<double>, VectorXd const, VectorXd const >?2. Can template expressions be built from mixed operations?For example, in an _expression_ like x = u + 2 * v - w, is it true that these operations are performed in a nested way like this?a. v-w leads to the construction of an instance of CwiseBinaryOp< internal::scalar_difference_op<double>, VectorXd const, VectorXd const > (alias E1)b. 2 * v leads to the construction of an instance of CwiseUnaryOp< internal::scalar_product_op<double>, VectorXd const > (alias E2)c. 2 * v + v- w leads to the construction of an instance of CwiseBinaryOp< internal::scalar_sum_op<double>, E1 const, E2 const > (alias E3)d. u + 2 * v - w leads to the construction of an instance of CwiseBinaryOp< internal::scalar_sum_op<double>, VectorXd const, E3 const > (alias E4)e. x = u + 2 * v -w calls the constructor VectorXd(E4 const &), or the overloading VectorXd & operator=(E4 const &), which evaluate the tree built from the previous steps.Thank you for your help!Cédric

**Follow-Ups**:**Re: [eigen] Expression templates and CwiseBinaryOp***From:*Cedric Doucet

**References**:**[eigen] Expression templates and CwiseBinaryOp***From:*Cedric Doucet

**Messages sorted by:**[ date | thread ]- Prev by Date:
**[eigen] Expression templates and CwiseBinaryOp** - Next by Date:
**Re: [eigen] Expression templates and CwiseBinaryOp** - Previous by thread:
**[eigen] Expression templates and CwiseBinaryOp** - Next by thread:
**Re: [eigen] Expression templates and CwiseBinaryOp**

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