Skip to content

ENH: Take advantage of symmetry in leggauss. #5985

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

Merged
merged 1 commit into from
Jun 20, 2015

Conversation

ajdawson
Copy link
Contributor

The calculation of points and weights for Gauss-Legendre quadrature can take advantage of the symmetry of the companion matrix when computing its eigenvalues. This can significantly speed up the computation even for moderately small values of the input degree.

The calculation of points and weights for Gauss-Legendre quadrature
can take advantage of the symmetry of the companion matrix when
computing its eigenvalues in order to speed up the computation.
@argriffing
Copy link
Contributor

The CI error looks unrelated.

No output has been received in the last 10 minutes, this potentially indicates a stalled build or something wrong with the build itself.

@argriffing
Copy link
Contributor

Looks mostly good to me. The leggauss function calls legcompanion whose docstring recommends using eigvalsh to find the eigenvalues for the basis polynomials, and the leggauss comment says that it uses the fact that the companion matrix is symmetric to get better eigenvalues... so something must have been lost somewhere.

Also, the sort on the next line can be deleted because the values returned by eigvalsh are already sorted (unlike the values returned by eigvals).

@charris
Copy link
Member

charris commented Jun 19, 2015

Oops ;) Might be worth checking the other polynomial types to see if the error is generic.

@charris
Copy link
Member

charris commented Jun 19, 2015

Looks like Laguerre suffers from the same problem.

@charris
Copy link
Member

charris commented Jun 19, 2015

And they all have the extra sort.

EDIT: but the eigvalsh documentation says "not necessarily ordered", so either the documentation is wrong, or the sort is needed.

@charris
Copy link
Member

charris commented Jun 19, 2015

The np.eigvalsh are not necessarily in order, while scipy.linalg.eigvalsh` claims to return them in increasing order. Might be worth a check to see if the numpy documentation is correct.

@argriffing
Copy link
Contributor

oh you're right, I must have been looking at the scipy eigvalsh docs.

@argriffing
Copy link
Contributor

Might be worth a check to see if the numpy documentation is correct.

Well the docs say that _ssyevd and _heevd are used
https://github.com/numpy/numpy/blob/maintenance/1.9.x/numpy/linalg/linalg.py#L943

and those docs both say that the returned eigenvalues are sorted in ascending order
http://www.netlib.org/lapack/explore-html/da/da8/ssyevd_8f.html
http://www.netlib.org/lapack/explore-html/d6/dee/zheev_8f.html

argriffing added a commit that referenced this pull request Jun 20, 2015
ENH: Take advantage of symmetry in leggauss.
@argriffing argriffing merged commit 0514d31 into numpy:master Jun 20, 2015
@argriffing
Copy link
Contributor

Thanks @ajdawson!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants