-
Notifications
You must be signed in to change notification settings - Fork 53
Proposal: Remove upper
argument from eigh
and eigvalsh
#217
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
Comments
Personally, I am okay with removing this keyword argument from the current specification. I agree that the |
One potential issue here is that the array API specification currently lacks APIs for returning the upper and lower triangular parts of an array. In which case, based on the specification alone, a user would be unable to pack two symmetric matrices (point 4 above). We may want to consider adding those APIs. |
I've opened gh-237 to discuss adding |
I have some concerns about removing |
@leofang The packing part is addressed in point 4. |
No, that's not true, that's why I am concerned 🙂 Point 4 requires computing a temporary array |
This may not be the case if libraries implement That being said, there's also the point that, in PyTorch, we have been returning symmetric gradients for quite a few versions already, and we have not had any issue raised about this. This may indicate that not that many people use this feature. |
It's good to know @lezcano! I look into it more and agree packing two matrices in the same array is more an application-specific optimization strategy, so it may not be widely adopted indeed. |
OK, we discussed about the packing part. How about my other comment?
|
Some functions that accept a symmetric matrix (
eigh
,eighvals
) have anupper=False
kwarg. According to the API:“If
True
, use the upper-triangular part to compute the eigenvalues and eigenvectors. IfFalse
, use the lower-triangular part to compute the eigenvalues and eigenvectors.”.There are a number of reasons why we might want to remove this argument from the API.
cholesky
. In fact,cholesky
has a boolean parameter also namedupper
which does something completely different toeigh
'supper
.It is not clear whether one should assume that the input is symmetric, or that the upper (resp. lower) triangular part of the input matrix input matrix represents a symmetric matrix via the transformation
A.triu() + A.triu(1).T
. This is problematic when computing the gradient, as it is not clear whether the gradient should be symmetric or upper triangular. PyTorch makes the gradient symmetric to be mathematically consistent with the semantics of the operation, rather than with the optimisation that this kwarg suggests, which is semantically wrong but more intuitive. We have not received any issue about this, which hints to the fact that almost no one uses this optimisation to pack two symmetric matrices into one unconstrained matrix (and an extra vector).L1, Q1 = linalg.eigh(A.triu(1) + A.triu(1).T); L2, Q2 = linalg.eigh(A.tril(-1) + A.tril(-1).T)
. Doing this and implementing symmetric gradients (which is what is mathematically correct foreigh
) would give the correct semantics with respect to the upper (resp. lower) part ofA
.eigh
is defined in the API as “Returns the eigenvalues and eigenvectors of a symmetric matrix (or a stack of symmetric matrices) x.”, but this kwarg suggests that x should be a stack of upper (resp. lower) triangular matrices that encode symmetric matrices.In summary, this is a feature that seemed to have made its way from LAPACK into numpy, and a number of other frameworks have implemented it for numpy compatibility. This was certainly the case of PyTorch. It could be of interest to deprecate it, as it is too low level for a generic API, and its behaviour can be implemented in a couple of lines, as described above.
cc @rgommers @mruberry
The text was updated successfully, but these errors were encountered: