Re: [eigen] Operations involving constants

[ Thread Index | Date Index | More Archives ]

On 22.10.2014 18:30, oz wrote:
So I'm working on my own little test class to learn expression
templates, etc. and have run into a bit of a snag.
I'd appreciate any help in understanding. I'm uncertain how to implement
the following kinds expressions:


It looks like Eigen somehow implements this in the Unary Operators,
which makes sense, but I can't figure it out.

ArrayBase<Derived>::operator*(Scalar) is defined in
it returns a
CwiseUnaryOp<internal::scalar_mult_op<Scalar>, Derived> >.

operator+(Scalar) is defined in ArrayCwiseBinaryOp (but still returns a CwiseUnaryOp object.

I tried encapsulating the constant into a Constant<T> class, and using
the BinaryOps like normal, but that gave me segfaults for some reason.
How would y'all suggest I approach this issue?

See ArrayBase::max(Scalar) (also in ArrayCwiseBinaryOp.h) for an example how to implement a unary operation as a BinaryOp with a Constant.

Is there a reason why we implement operator+(Scalar) as CwiseUnaryOp, but max(Scalar) as CwiseBinaryOp?


Dipl.-Inf., Dipl.-Math. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen

Tel: +49 (421) 218-64252

Mail converted by MHonArc 2.6.19+