[SciPy-User] eigsh on sparse tridiagonal matrix: 2 orders of magnitude slower than Octave??
Chong Yidong
cyd@gnu....
Wed Jan 2 06:28:48 CST 2013
I'd like to use scipy.sparse.linalg.eigsh() to solve the standard
tridiagonal matrix from the finite-difference method (2's on the
diagonal, -1's on the off-diagonals). Strangely, it is running MUCH
slower than the equivalent code on GNU Octave---3.8 seconds as opposed
to 0.04 seconds in the following example---and I don't know why.
In the following SciPy code, eigsh takes 3.84 seconds to run:
import scipy.sparse as sp
import scipy.sparse.linalg as lin
import time
Nx = 1500
H = 2.0 * sp.eye(Nx, Nx, format='lil')
Hoff1 = sp.eye(Nx, Nx, k=1, format='lil')
Hoff2 = sp.eye(Nx, Nx, k=-1, format='lil')
H = H - Hoff1 - Hoff2
H = H.tocsr()
t = time.time()
E = lin.eigsh(H, 25, which='SM', return_eigenvectors=False)
print time.time() - t
In the following equivalent Octave code, eigs takes 0.04 seconds:
N = 1500;
f = ones(N-1,1);
H = 2.0 * eye(N) - diag(f,1) - diag(f,-1);
H = sparse(H);
tic; v = eigs(H, 25, 'sm'); toc;
Surely it's the same ARPACK underneath, so how can this be happening?
Anyone have any idea? I'm using SciPy 0.10.1 on Ubuntu x86-64. SciPy
0.9 also had the same problem. Comparison was made with Octave 3.6.2
running on the same machine.
More information about the SciPy-User
mailing list