Eigen3: in-place multiplication factor

How can you do multiplication by type with Eigen3?

whether

a = a.cwiseProduct(b);

      

run locally? Or

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

      

the best solution in terms of style and performance?

+3


source to share


1 answer


Both expressions should generate the same code (with a sensibly optimizing compiler), so this is more of a matter of taste.



If you are doing mostly rudimentary operations with a

and b

, you should declare them as Eigen::Array

(instead of Eigen::Matrix

) and just write a*=b;

. If you need access to a

or b

in matrix form later, you can still use a.matrix()

.

+1


source







All Articles