# How to know which LAPACK's function is used by Scipy's eig function?

As far as I understood, scipy.linalg.eig use wrappers from scipy.lapack to compute the eigenvalues and eigenvectors of a matrix. In order to do that eig test the matrix to select the good LAPACK function. Please correct me if I'm wrong.

When the matrix is singular and the algorithm does not converge Python raises an error and displays the name of the LAPACK function used. I would like to know which algorithm eig uses when I compute the eigenvalues of the matrix. Is there any scipy function or eig option that I am not aware of displaying the LAPACK function used?

## 1 Answer

I don't think there is a way to display the used LAPACK function names natively during runtime using the interfaces provided by scipy.linalg.

Depending on your goals you can:

• read the source code and deduce the logic from there. Unfortunately, this is not a runtime-use scenario, but a human analysis.
• fork your own version of scipy, add custom outputs (to the calls you are interested in monitoring) and use it instead of the shipped one. Since scipy is open-source, with some manual work you can get the desired behavior. Building scipy from sources reference should be useful in this case.

Regarding scipy.linalg.eig: this function is for the general matrices. If you happen to have a symmetric/Hermittian, banded or tridiagonal matrix, you should call scipy.linalg.eigh, scipy.linalg_eig_banded, or scipy.linalg.eigh_tridiagonal, respectively.

You can see that scipy.linalg.eig does not do any chosing of LAPACK functions to use:

geev, geev_lwork = get_lapack_funcs(('geev', 'geev_lwork'), (a1,))


So, scipy.linalg.eig will call the ?geev. I don't think it is physically capable (as of the current implementation) of calling anything else.

On the contrary, scipy.linalg.eigh has more options and flexibility, and actually different LAPACK functions can be called from scipy.

Note, that currently, you are probably seeing the output of scipy.linalg.LinAlgError. This exception is raised in the linear algebra functions wrappers and probably uses the info output from the called LAPACK function.

• Thank you for the answer, very useful. I mainly work on general matrices so I'm stuck with scipy.linalg.eig. Looks like ?geev is testing the matrix itself before selecting dgeev or other LAPACK function to run the calculation. I will try to modify the sources to get what I want later in the year. – user33403 Jan 4 '20 at 15:25