This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Memory usage

Tags: None
(comma "," separated)
jlopes
Registered Member
Posts
3
Karma
0

Memory usage

Mon Apr 25, 2016 5:45 pm
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
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Memory usage  Topic is solved

Mon Apr 25, 2016 8:11 pm
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;
jlopes
Registered Member
Posts
3
Karma
0

Re: Memory usage

Mon Apr 25, 2016 9:30 pm
Thanks ggael! Good to know!


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient