-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds mineig and maxeig methods #2725
Conversation
Find smallest and largest eigenvalues for real eigenvalues Includes specialized method fo SymTridiagonal.
I am not convinced about the utility of these. It would be worth having these, if they did lesser computation than |
Are you going to have special routines in case of banded matrices, where these routines are more efficient that computing all the eigenvalues? |
@@ -67,6 +67,11 @@ eig(m::SymTridiagonal) = LAPACK.stegr!('V', copy(m.dv), copy(m.ev)) | |||
eigvals(m::SymTridiagonal, il::Int, iu::Int) = LAPACK.stebz!('I', 'E', 0.0, 0.0, il, iu, -1.0, copy(m.dv), copy(m.ev))[1] | |||
eigvals(m::SymTridiagonal, vl::Float64, vu::Float64) = LAPACK.stebz!('V', 'E', vl, vu, 0, 0, -1.0, copy(m.dv), copy(m.ev))[1] | |||
eigvals(m::SymTridiagonal) = LAPACK.stebz!('A', 'E', 0.0, 0.0, 0, 0, -1.0, copy(m.dv), copy(m.ev))[1] | |||
|
|||
#Computes largest and smallest eigenvalue | |||
maxeig(m::SymTridiagonal) = eigvals(m, size(m)[1], size(m)[1])[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size(m, 1)
avoids the creation of an array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think size returns a tuple, but we should still do size(m,1)
to avoid the tuple creation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this should be eigvals(m, size(m,1), size(m,1))[1]? I'm assuming the last one can't be helped.
The method for |
I like restricting it to cases where it does something better than the obvious stuff. However, once you get used to this, you will want it to work everywhere. |
@jiahao How about we restrict this only to the cases where there is an optimized version, unless you think otherwise. Also, do update what @andreasnoackjensen pointed out. |
That seems destined to cause headaches in otherwise generic code. |
The computation of the extremal eigenvalues shows up all the time in applications, and this essentially implements what @alanedelman was trying to do in #2267. I'm in favor of providing the generic method, even if purely for convenience. It gives a graceful "obvious" fallback method for the end user, but have it overloaded for |
Even in the sym tridiagonsl case, is it not just picking out the max value from all eigenvalues, or is it actually taking less computational effort when using eigmax instead of eigvals? |
@ViralBShah in both |
In fact for the SymTridiagonal case you can always achieve O(n^2), in good cases even O(n) work |
Thanks for the explanation. Can you rename to eigmax and eigmin? That makes them discoverable with tab completion. Also, let's keep the generic cases too. |
It would be great to get some tests in as well. |
Oops, I meant |
I'm not sure if this needs to be in Base, but introducing a method that is usually an alias for |
Please ignore my previous comment (I did not read the code carefully enough). The current implementation seems to be the optimal one. |
@johnmyleswhite I am not familiar with Julia enough to fully understand what you are proposing, but feel free to implement it if you think it is a good idea ;) |
You've already implemented it. :) I was just advocating your work since it seems like a good example of redefining a function on a special type like |
Ah, I see. I wasn't sure if you were alluding to some more esoteric feature of Julia that I didn't know about. On a related note I was wondering if type promotion was a more elegant approach to implementing +,-,x, etc. on the specialized matrix types, especially when doing things like |
Adds mineig and maxeig methods
Find smallest and largest eigenvalues