Repository: numpy/numpy

Issue:
numpy exits if lhs in lstsq(lhs, rhs) contains nan
```
>>> np.linalg.lstsq([[np.nan]]*2, [1]*2)
 ** On entry to DLASCL parameter number  4 had an illegal value
[Inferior 1 (process 21213) exited normally]
(gdb)
```



Discussion:
Probably a xerbla problem with fedora 21 atlas.

is their lapack built with `-Wl,-Bsymbolic-functions`? ubuntu had that issue but fixed it (after I filed a bug)

Don't know, how can I tell? Note that fedora 21 combines all the atlas libraries into two: libsatlas.so and libtatlas.so. The libraries are stripped, but the dynamic symbol tables contain

```
00000000005563a0 T ATL_xerbla
0000000000541360 T cblas_xerbla
000000000052fef4 T xerbla_
000000000040846a T xerbla_array_
```

Which all looks standard enough.

I filed a [bug report](https://bugzilla.redhat.com/show_bug.cgi?id=1172834) with Fedora just in case. We do have a test for xerbla, but it might be disabled or not detecting the problem.

This because multiple numpy shared libraries are linked against atlas:

rpm -ql numpy | grep -F .so | while read so; do ldd $so | grep atlas && echo $so; done
        libsatlas.so.3 => /usr/lib64/atlas/libsatlas.so.3 (0x00007fd169763000)
/usr/lib64/python2.7/site-packages/numpy/core/_dotblas.so
        libsatlas.so.3 => /usr/lib64/atlas/libsatlas.so.3 (0x00007f7135291000)
/usr/lib64/python2.7/site-packages/numpy/linalg/_umath_linalg.so
        libsatlas.so.3 => /usr/lib64/atlas/libsatlas.so.3 (0x00007f67f2df9000)
/usr/lib64/python2.7/site-packages/numpy/linalg/lapack_lite.so

But the xerbla_ override is not in _dotblas.so and that is getting loading first.

Interesting. Development version of numpy does not have `_dotblas`, but the cblas calls are now in multiarray.


Resolving patch:
diff --git a/numpy/core/setup.py b/numpy/core/setup.py
--- a/numpy/core/setup.py
+++ b/numpy/core/setup.py
@@ -839,7 +839,9 @@ def generate_multiarray_templated_sources(ext, build_dir):
     blas_info = get_info('blas_opt', 0)
     if blas_info and  ('HAVE_CBLAS', None) in blas_info.get('define_macros', []):
         extra_info = blas_info
-        multiarray_src.append(join('src', 'multiarray', 'cblasfuncs.c'))
+        multiarray_src.extend([join('src', 'multiarray', 'cblasfuncs.c'),
+                               join('src', 'multiarray', 'python_xerbla.c'),
+                              ])
     else:
         extra_info = {}
 


Test patch:
diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py
--- a/numpy/linalg/tests/test_linalg.py
+++ b/numpy/linalg/tests/test_linalg.py
@@ -1152,6 +1152,8 @@ def test_xerbla_override():
     # and may, or may not, abort the process depending on the LAPACK package.
     from nose import SkipTest
 
+    XERBLA_OK = 255
+
     try:
         pid = os.fork()
     except (OSError, AttributeError):
@@ -1181,15 +1183,16 @@ def test_xerbla_override():
                 a, a, 0, 0)
         except ValueError as e:
             if "DORGQR parameter number 5" in str(e):
-                # success
-                os._exit(os.EX_OK)
+                # success, reuse error code to mark success as
+                # FORTRAN STOP returns as success.
+                os._exit(XERBLA_OK)
 
         # Did not abort, but our xerbla was not linked in.
         os._exit(os.EX_CONFIG)
     else:
         # parent
         pid, status = os.wait()
-        if os.WEXITSTATUS(status) != os.EX_OK or os.WIFSIGNALED(status):
+        if os.WEXITSTATUS(status) != XERBLA_OK:
             raise SkipTest('Numpy xerbla not linked in.')