I am doing this a lot:
auto f_conj = f.conjugate(); //f is a MatrixXcf, so is C;
for(n=0;n<X.cols();++n)
C.col(n) = X.col(n).cwiseProduct(f_conj);
Am I not supposed to be able to do something like
C.colwise() = X.colwise().cwiseProduct(f_conj)
instead?
What you are really doing is a diagonal product, so I'd recommend you the following expression:
C = f.conjugate().asDiagonal() * X;
If you want to use a colwise() expression, then do not put it on the left hand side:
C = X.colwise().cwiseProduct(f.conjugate());
Moreover, let me warn you about the use of the auto keyword. Here, let me emphasize that f_conj
is not a VectorXcf
, but an expression of the conjugate of a VectorXcf
. So using f_conj
or f.conjugate()
is exactly the same. Since multiplying two complexes or one complex and one conjugate complex amount to the same cost, in this precise case it's ok to use the auto keyword. However, if f_conj
would be for instance: auto f_conj = (f+g).conjugate()
, then f+g
would be recomputed many times in your for loop. Doing (f+g).conjugate().asDiagonal() * X
is perfectly fine though, because Eigen knows what to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With