Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Eigen matrix out of 2 vectors [closed]

Tags:

c++

eigen

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.

like image 883
Stepan Andreenko Avatar asked Dec 11 '13 09:12

Stepan Andreenko


1 Answers

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.

like image 80
ggael Avatar answered Oct 02 '22 03:10

ggael