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

Lazy variables?

Tags: None
(comma "," separated)
thpbt
Registered Member
Posts
2
Karma
0

Lazy variables?

Fri Jul 24, 2015 12:27 pm
I've just started using Eigen for a project. Very impressed with it, and how well thought out everything is.

But I was wondering - is there any container to hold a lazy temporary expression? It could make code much more readable. Something like:

Code: Select all
long M = 64;
Lazy<VectorXf> n = VectorXf::LinSpaced(M, 0.0f, 1.0f);
VectorXf hannWindow(M);
hannWindow = 0.5f - (1.0f - (2.0f * M_PI * n).cos() );


It wouldn't allow you to restructure in any major way, but it could make writing expressions much clearer to read, without adding any overhead, as n (in the above example) wouldn't be evaluated until it was included in another expression.

Any thoughts? Can you already do this? And if not, would it, conceptually be possible with eigen's internal template structure?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Lazy variables?

Fri Jul 24, 2015 2:13 pm
yes, use the C++11 auto keyword:

auto n = VectorXf::LinSpaced(M, 0.0f, 1.0f);
thpbt
Registered Member
Posts
2
Karma
0

Re: Lazy variables?

Wed Jul 29, 2015 9:56 am
Ingenious. Thanks!


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]