[Numpy-discussion] NumPy EIG much slower than MATLAB EIG

Nathaniel Smith njs@pobox....
Mon Apr 2 13:05:40 CDT 2012


On Mon, Apr 2, 2012 at 6:18 PM, Aronne Merrelli
<aronne.merrelli@gmail.com> wrote:
> On Sun, Apr 1, 2012 at 8:28 AM, Kamesh Krishnamurthy <kameshkk@gmail.com> wrote:
>> Hello all,
>>
>> I profiled NumPy EIG and MATLAB EIG on the same Macbook pro, and both were
>> linking to the Accelerate framework BLAS. NumPy turns out to be ~4x slower.
>> I've posted details on Stackoverflow:
>> http://stackoverflow.com/q/9955021/974568
>
> If you just call eig() in MATLAB it only returns eigenvalues (not
> vectors). I think there might be a "shortcut" algorithm if you only
> want the eigenvalues - or maybe it is faster just due to the smaller
> memory requirement. NumPy's eig always computes both. On my Mac OS X
> machine I get this result, showing the two are basically equivalent
> (this is EPD NumPy, so show_config() shows it is built on MKL):
>
> MATLAB:
>>> tic; eig(r); toc
> Elapsed time is 10.594226 seconds.
>>> tic; [V,D] = eig(r); toc
> Elapsed time is 23.767467 seconds.
>
> NumPy
> In [4]: t0=datetime.now(); numpy.linalg.eig(r); print datetime.now()-t0
> 0:00:25.594435
> In [6]: t0=datetime.now(); v,V = numpy.linalg.eig(r); print datetime.now()-t0
> 0:00:25.485411
>
> If you change the MATLAB call, how does it compare?

Or you could alternatively change the numpy call to
np.linalg.eigvals(r), if you're only interested in the eigenvalues.

- N


More information about the NumPy-Discussion mailing list