Registered Member
|
If A is a MatrixXd of size 3x4 and b is a VectorXd of length 4. How can I multiple A and b, element-wise, with b broadcast to every row of A? Something like A.rowwise().cwiseProduct(b) but apparently this doesn't compile.
|
Moderator
|
You are looking for a diagonal product:
A * b.asDiagonal() An alternative is: a.array().rowwise() * b.array() |
Registered Member
|
Thanks for the suggestions.
For the first one, would there be performance penalty than simply looping over A's rows (e.g., for (int i = 0; i < A.rows(); ++i) A.row(i).array() *= b.array();)? For the 2nd one, I got compiling errors: no match for ‘operator*’ in ... Eigen::DenseBase<Derived>::rowwise [...]() * Eigen::MatrixBase<Derived>::array() [...]()’
|
Moderator
|
Diagonal products are fully optimized and vectorized. There is no overhead.
The second version is indeed for the devel version only. |
Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]