Implement eigenvalue and eigenvector computation #589
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A first implementation of eigenvalue computation in
glam
. Closes #321.I intend to add eigenvector computation as well, but I would like some feedback on how to integrate this with
glam
first. This is a draft PR for two reasons:The question of how to return complex values. Eigenvalues (and eigenvectors) can be complex, which
glam
does not support (and a full implementation of is beyond scope). Right now, I provide two methods for each matrix type: a general case eigenvalue function, which returns two-dimensional vectors storing the real and imaginary components, and a specialized eigenvalue function for symmetric matrices, where all eigenvalues are real. This storage of complex eigenvalues is not ideal, and would be more awkward for returning complex eigenvectors.The question of where to integrate the code with
glam
's types. The computation of eigenvectors, which has not been implemented yet, shares most of the work with the computation of eigenvalues. As such, the simple implementation of a.eigenvalues()
and a.eigenvectors()
method on each matrix type would be computationally inefficient. One option is to have one method which returns both, but eigenvalue computation can be more efficient if eigenvectors are not requested.I have not looked too far into performance optimizations, just primarily correctness. There may be edge cases the current algorithm fails on I haven't encountered yet.