Eigen3: coefficient-wise multiplication in place
Asked Answered
T

1

13

How can you perform a element-wise multiplication in place using Eigen3?

Does

a = a.cwiseProduct(b);

run in place? Or is

a.array() *= b.array();

the better solution in terms of style and performance?

Transcription answered 15/8, 2014 at 14:53 Comment(0)
W
14

Both expressions should generate the same code (with a reasonably optimizing compiler), so it is more a question of taste.

If you are doing mostly element-wise operations with a and b you should declare them as Eigen::Array (instead of Eigen::Matrix) and just write a*=b;. If you need to access a or b in a matrix-fashion later, you can still use a.matrix().

Wadewadell answered 23/9, 2016 at 13:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.