I have 2 vectors and a matrix:
VectorXd A;
VectorXd B;
MatrixXd C;
How should I efficiently (without explicit loops and working fast) compute matrix C values so that
C(i,k) = A(i) * B(k);
Assume that matrix C already has appropriate dimensions.
IMPORTANT: I only need help in using built-in Eigen syntax. Please no CUDA/MKL/BLAS suggestions. Thank you.
You are looking for an outer product which is just a standard matrix product:
C = A * B.transpose();
Since the destination c
does not alias with the operand of the product you can save one temporary with:
C.noalias() = A * B.transpose();
noalias
makes sense for matrix products only.
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