diff options
author | Pauli Virtanen <pav@iki.fi> | 2018-05-27 16:56:20 +0200 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2018-05-27 17:31:09 +0200 |
commit | 0350facf1a89103cfab3605e8c67967a650aa704 (patch) | |
tree | f6f49b761192e8e87bbd6bd7d4b47c7f34ea6ba7 /numpy/linalg | |
parent | 09e108dc3453cbca17a80e75f5ec2b941e5b8137 (diff) | |
download | numpy-0350facf1a89103cfab3605e8c67967a650aa704.tar.gz |
TST: linalg: add regression test for gh-8577
Add regression test that checks for certain bugs where results from sdot
change if certain libraries are imported first.
Diffstat (limited to 'numpy/linalg')
-rw-r--r-- | numpy/linalg/tests/test_linalg.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py index 5ed1ff1c0..87dfe988a 100644 --- a/numpy/linalg/tests/test_linalg.py +++ b/numpy/linalg/tests/test_linalg.py @@ -7,6 +7,8 @@ import os import sys import itertools import traceback +import textwrap +import subprocess import pytest import numpy as np @@ -1761,6 +1763,40 @@ def test_xerbla_override(): raise SkipTest('Numpy xerbla not linked in.') +def test_sdot_bug_8577(): + # Regression test that loading certain other libraries does not + # result to wrong results in float32 linear algebra. + # + # There's a bug gh-8577 on OSX that can trigger this, and perhaps + # there are also other situations in which it occurs. + # + # Do the check in a separate process. + + bad_libs = ['PyQt5.QtWidgets', 'IPython'] + + template = textwrap.dedent(""" + import sys + {before} + try: + import {bad_lib} + except ImportError: + sys.exit(0) + {after} + x = np.ones(2, dtype=np.float32) + sys.exit(0 if np.allclose(x.dot(x), 2.0) else 1) + """) + + for bad_lib in bad_libs: + code = template.format(before="import numpy as np", after="", + bad_lib=bad_lib) + subprocess.check_call([sys.executable, "-c", code]) + + # Swapped import order + code = template.format(after="import numpy as np", before="", + bad_lib=bad_lib) + subprocess.check_call([sys.executable, "-c", code]) + + class TestMultiDot(object): def test_basic_function_with_three_arguments(self): |