[SciPy-dev] Comments on API for Matlab's eigs equivalent (computing a few eigenvalues only)

David Cournapeau david@silveregg.co...
Thu Feb 4 00:27:57 CST 2010


I have played a bit with adding support for computing a few eigenvalues 
of full symmetric matrices. I would like some comments on the current API:

import numpy as np
from scipy.linalg import eigs
x = np.random.randn(10, 10)
x = np.dot(x.T, x)
# Retrieve the 3 biggest eigenvalues
eigs(x, 3)[0]
# Retrieve the 3 smallest eigenvalues
eigs(x, -3)[0]
# Retrieve the 3 biggest eigenvalues
eigs(x, [0, 3], mode="index")[0]
# Retrieve the 2nd and 3rd biggest
eigs(x, [1, 3], mode="index")[0]
# Retrieve all the eigenvalues in the range [1.5, 3.5[
eigs(x, [1.5, 3.5], mode="range")[0]

One thing which does not feel right is that that the range in the 
"index" mode is exactly inverted compared to the output (i.e. if you ask 
for the range [0, 3], you get the last three items from what you would 
get if you asked for the full range [0, 10]), but this is because I kept 
compatibility with Octave (always showing from biggest to smallest). It 
would be easy to always do the contrary (from smallest to biggest) - 
besides consistency, it has the advantages that it is the actual order 
you get back from the underlying LAPACK function.

Also, I needed to modify the f2py file for the related LAPACK functions, 
effectively changing their API in a backward incompatible way. Are the 
low-level f2py wrappers considered public API ?



More information about the SciPy-Dev mailing list