[Numpy-discussion] svd error checking vs. speed

Sebastian Berg sebastian at sipsolutions.net
Sat Feb 15 16:56:08 EST 2014


On Sa, 2014-02-15 at 16:37 -0500, alex wrote:
> Hello list,
> 
> Here's another idea resurrection from numpy github comments that I've
> been advised could be posted here for re-discussion.
> 
> The proposal would be to make np.linalg.svd more like scipy.linalg.svd
> with respect to input checking.  The argument against the change is
> raw speed; if you know that you will never feed non-finite input to
> svd, then np.linalg.svd is a bit faster than scipy.linalg.svd.  An
> argument for the change could be to avoid issues reported on github
> like crashes, hangs, spurious non-convergence exceptions, etc. from
> the undefined behavior of svd of non-finite input.
> 

+1, unless this is a huge speed penalty, correctness (and decent error
messages) should come first in my opinion, this is python after all. If
this is a noticable speed difference, a kwarg may be an option (but
would think about that some more).

- Sebastian

> """
> [...] the following numpy code hangs until I `kill -9` it.
> 
> ```
> $ python runtests.py --shell
> $ python
> Python 2.7.5+
> [GCC 4.8.1] on linux2
> >>> import numpy as np
> >>> np.__version__
> '1.9.0.dev-e3f0f53'
> >>> A = np.array([[1e3, 0], [0, 1]])
> >>> B = np.array([[1e300, 0], [0, 1]])
> >>> C = np.array([[1e3000, 0], [0, 1]])
> >>> np.linalg.svd(A)
> (array([[ 1.,  0.],
>        [ 0.,  1.]]), array([ 1000.,     1.]), array([[ 1.,  0.],
>        [ 0.,  1.]]))
> >>> np.linalg.svd(B)
> (array([[ 1.,  0.],
>        [ 0.,  1.]]), array([  1.00000000e+300,   1.00000000e+000]),
> array([[ 1.,  0.],
>        [ 0.,  1.]]))
> >>> np.linalg.svd(C)
> [hangs forever]
> ```
> """
> 
> Alex
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> 





More information about the NumPy-Discussion mailing list