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

How to do in-place transformation efficiently?

Tags: None
(comma "," separated)
zhanxw
Registered Member
Posts
17
Karma
0
Hi,

I am trying to transform each element of matrix A using a function f.
Is this the efficient way to do so?

Code: Select all
A = A.unaryExpr(ptr_fun(f)) ;


When reading Eigen documentation, I am also confused by unaryExpr unaryViewExpr?
(as in this page: http://eigen.tuxfamily.org/dox-devel/classEigen_1_1MatrixBase.html#a2be175e189ac4baa01736f9a4c5a9bc4)
What are the difference scenarios of using them respectively?

Thanks.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
yes, your syntax is good. The operator f will be applied in-place. unaryViewExpr is for read/write operators, i.e., the functor must return a reference. It is used for instance to implement real() and imag().


Bookmarks



Who is online

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