I have a peculiar phenomenon, though scipy.sparse.linalg.eigs
should be faster for sparse matrices, I get that it runs slower than the normal eigvals
method of scipy
:
In [4]: %timeit m.calc_pde_numerical_jacobian(m.initial_state)
10 loops, best of 3: 41.2 ms per loop
In [5]: %timeit m.calc_pde_analytic_jacobian(m.initial_state)
1000 loops, best of 3: 1.42 ms per loop
In [6]: %timeit m.calc_analytic_pde_eigs(m.initial_state)
1 loop, best of 3: 374 ms per loop
In [7]: %timeit m.calc_numeric_pde_eigs(m.initial_state)
1 loop, best of 3: 256 ms per loop
So the method calc_pde_numerical_jacobian
construct a dense matrix of the Jacobian of my system of equations, and calc_pde_analytic_jacobian
is constructing a sparse matrix of the Jacobian analytically (csc
format). Though the analytical method is working faster in constructing the sparse matrix of the Jacobian, when use the eigenvalue finding methods from scipy, the sparse matrics eigenvalue method is slower. The functions that I use to calculate the eigenvalues are as such:
def calc_numeric_pde_eigs(self,state):
return linalg.eigvals(self.calc_pde_numerical_jacobian(state))
def calc_analytic_pde_eigs(self,state):
return sparse.linalg.eigs(self.calc_pde_analytic_jacobian(state),k=6,which='LR',return_eigenvectors=False)
Anyone knows how this could happen?