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

When to use "eval()"

Tags: None
(comma "," separated)
Akkawe
Registered Member
Posts
35
Karma
0
OS

When to use "eval()"

Fri Mar 29, 2013 2:17 pm
Hello,
I don't understand the use of the function .eval() in the case of both dense and sparse matrix.
Is it use to avoid aliasing?
When must I use it and when is it not required?

Thanks
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: When to use "eval()"

Fri Mar 29, 2013 6:47 pm
eval() permits to explicitly introduce a temporary in an expression. It's extremely rare to have to use it. With dense matrices, you can use to deal with an aliasing issues. Sometime it's also needed to send the result of an expression to a function expecting a raw pointer to the data, e.g. with OpenGL:

glVertex4fv((a+b).eval().data());
Akkawe
Registered Member
Posts
35
Karma
0
OS

Re: When to use "eval()"

Sat Mar 30, 2013 9:30 am
it is still not so clear to me.
I wrote this functions for summing sparse matrices:

Code: Select all
void Analysis::sumMatr(std::vector<SubDomain *> const &pSubD, SparseMatrix<complex<double> > &result){
   SparseMatrix<complex<double> > KMDsum(dimSys,dimSys);
   vector <SubDomain *>::const_iterator iter=pSubD.begin();;
   while (iter != pSubD.end()){
      KMDsum = (KMDsum + *((*iter++)->getKdyn())).eval();
   }
   result=KMDsum;
}


and

Code: Select all
void Analysis::sumMatr(SparseMatrix<complex<double> K, SparseMatrix<complex<double> M, SparseMatrix<complex<double> > &result){
   result=K+M;
}


in the first case I use .eval() while it is not required in the secondo case.

Are they both correct?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: When to use "eval()"

Sat Mar 30, 2013 10:05 pm
even in the first case, it should not be needed. What's the type returned by getKdyn() ?
Akkawe
Registered Member
Posts
35
Karma
0
OS

Re: When to use "eval()"

Sun Mar 31, 2013 3:33 pm
ggael wrote:even in the first case, it should not be needed. What's the type returned by getKdyn() ?

it is SparseMatrix<complex<double> >.
It is simply a summing of sparse complex matrices


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]