8000 TST: linalg: add regression test for gh-8577 · r-devulap/numpy@6644185 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6644185

Browse files
pvcharris
authored andcommitted
TST: linalg: add regression test for numpygh-8577
Add regression test that checks for certain bugs where results from sdot change if certain libraries are imported first.
1 parent 4b40612 commit 6644185

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

numpy/linalg/tests/test_linalg.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import sys
88
import itertools
99
import traceback
10-
import warnings
10+
import textwrap
11+
import subprocess
1112

1213
import numpy as np
1314
from numpy import array, single, double, csingle, cdouble, dot, identity
@@ -1632,6 +1633,40 @@ def test_xerbla_override():
16321633
raise SkipTest('Numpy xerbla not linked in.')
16331634

16341635

1636+
def test_sdot_bug_8577():
1637+
# Regression test that loading certain other libraries does not
1638+
# result to wrong results in float32 linear algebra.
1639+
#
1640+
# There's a bug gh-8577 on OSX that can trigger this, and perhaps
1641+
# there are also other situations in which it occurs.
1642+
#
1643+
# Do the check in a separate process.
1644+
1645+
bad_libs = ['PyQt5.QtWidgets', 'IPython']
1646+
1647+
template = textwrap.dedent("""
1648+
import sys
1649+
{before}
1650+
try:
1651+
import {bad_lib}
1652+
except ImportError:
1653+
sys.exit(0)
1654+
{after}
1655+
x = np.ones(2, dtype=np.float32)
1656+
sys.exit(0 if np.allclose(x.dot(x), 2.0) else 1)
1657+
""")
1658+
1659+
for bad_lib in bad_libs:
1660+
code = template.format(before="import numpy as np", after="",
1661+
bad_lib=bad_lib)
1662+
subprocess.check_call([sys.executable, "-c", code])
1663+
1664+
# Swapped import order
1665+
code = template.format(after="import numpy as np", before="",
1666+
bad_lib=bad_lib)
1667+
subprocess.check_call([sys.executable, "-c", code])
1668+
1669+
16351670
class TestMultiDot(object):
16361671

16371672
def test_basic_function_with_three_arguments(self):

0 commit comments

Comments
 (0)
0