# [Numpy-svn] r3479 - trunk/numpy/linalg

numpy-svn at scipy.org numpy-svn at scipy.org
Wed Dec 6 14:48:32 CST 2006

```Author: oliphant
Date: 2006-12-06 14:48:30 -0600 (Wed, 06 Dec 2006)
New Revision: 3479

Modified:
trunk/numpy/linalg/linalg.py
Log:
Fix hanging eig computation when inf or nan values are in the array.  This check is already in SciPy.  We need it in NumPy too for some LaPack calls.

Modified: trunk/numpy/linalg/linalg.py
===================================================================
--- trunk/numpy/linalg/linalg.py	2006-12-06 20:29:38 UTC (rev 3478)
+++ trunk/numpy/linalg/linalg.py	2006-12-06 20:48:30 UTC (rev 3479)
@@ -20,7 +20,7 @@
intc, single, double, csingle, cdouble, inexact, complexfloating, \
newaxis, ravel, all, Inf, dot, add, multiply, identity, sqrt, \
maximum, flatnonzero, diagonal, arange, fastCopyAndTranspose, sum, \
-        argsort
+        argsort, isfinite
from numpy.lib import triu, iterable
from numpy.linalg import lapack_lite

@@ -120,6 +120,11 @@
if max(a.shape) != min(a.shape):
raise LinAlgError, 'Array must be square'

+def _assertFinite(*arrays):
+    for a in arrays:
+        if not (isfinite(a).all()):
+            raise LinAlgError, "Array must not contain infs or NaNs"
+
# Linear equations

def tensorsolve(a, b, axes=None):
@@ -340,6 +345,7 @@
def eigvals(a):
_assertRank2(a)
_assertSquareness(a)
+    _assertFinite(a)
t, result_t = _commonType(a)
real_t = _linalgRealType(t)
a = _fastCopyAndTranspose(t, a)
@@ -434,6 +440,7 @@
a, wrap = _makearray(a)
_assertRank2(a)
_assertSquareness(a)
+    _assertFinite(a)
a, t, result_t = _convertarray(a) # convert to double or cdouble type
real_t = _linalgRealType(t)
n = a.shape[0]

```