Registered Member
|
Dear Eigen community,
I new to c++ and to Eigen. I writing some code that need huge matrices and vectors. I am a bit confused about the scalar product: complex_scalar = v.adjoint() * b where both b and v are vectors of N complex elements. Does Eigen create a temporary space for a vector v.adjoint() and then multiplies by b, consuming both memory and CPU, or is it implemented as I would in C: std::complex<double>sum(0,0); for(i = 0; i < N;i++) sum += std::conj(v(i)) * b(i); If it needs more temporary memory there are any other way of doing this operation without requiring more memory? There are any difference if both b and v are matrices (v(M,N) and b(N,L) --> result (M,L) )? Thanks in advance João |
Moderator
|
Most operations in Eigen are lazy, so no temporary for v.adjoint() and Eigen does generate a code similar to one you wrote but with explicit vectorization and improved pipelining (assuming v and b are vector at compile-time, e.g., VectorXcd).
If both b and v are matrices, then the only difference is that a temporary will be create for the result to avoid any aliasing issue, but you can avoid it with: res.noalias() = v.adjoint() * b; |
Registered Member
|
Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient