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

Gradient matrix in Eigen?

Tags: None
(comma "," separated)
vernal
Registered Member
Posts
37
Karma
0

Gradient matrix in Eigen?

Tue Feb 01, 2011 9:54 am
Hi all

does Eigen provide a way to calculate a numerical gradient matrix the way Matlab does with the gradient command?

Matlab sample:
Code: Select all
A=magic(5)
[dAx dAy] = gradient(A)


If not, is there some (clever) implementation of the Matlab diff functionality in Eigen?

Regards
vernal
jitseniesen
Registered Member
Posts
204
Karma
2

Re: Gradient matrix in Eigen?

Tue Feb 01, 2011 2:55 pm
I don't think Eigen has something like Matlab's gradient. However, Matlab's diff can easily be translated into Eigen code:

Code: Select all
dAx = A.rightCols(A.cols()-1) - A.leftCols(A.cols()-1);  // Matlab: dAx = diff(A,1,2)
dAy = A.bottomRows(A.rows()-1) - A.topRows(A.rows()-1);  // Matlab: dAy = diff(A)
vernal
Registered Member
Posts
37
Karma
0

Re: Gradient matrix in Eigen?

Wed Feb 02, 2011 11:31 am
Thank you! Do you know if this formulation in Eigen can be optimized by the compiler (using SSE etc.)?
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: Gradient matrix in Eigen?  Topic is solved

Wed Feb 02, 2011 1:56 pm
If your matrices are dynamic-sized (as in MatrixXf) and large enough, Eigen will vectorize that.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
vernal
Registered Member
Posts
37
Karma
0

Re: Gradient matrix in Eigen?

Thu Feb 03, 2011 4:46 pm
Thank you for that clear statement :-)


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft