Skip to content

Commit

Permalink
Merge pull request #11174 from charris/backport-11169
Browse files Browse the repository at this point in the history
MAINT: add sanity-checks to be run at import time
  • Loading branch information
charris committed May 27, 2018
2 parents 9667d47 + c2c7cae commit 5b3b867
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,27 @@ def pkgload(*packages, **options):
# but do not use them, we define them here for backward compatibility.
oldnumeric = 'removed'
numarray = 'removed'

def _sanity_check():
"""
Quick sanity checks for common bugs caused by environment.
There are some cases (e.g., the wrong BLAS ABI) that cause wrong
results under specific runtime conditions that are not necessarily
achieved during test suite runs, and it is useful to catch those early.
See https://github.com/numpy/numpy/issues/8577 and other
similar bug reports.
"""
try:
x = ones(2, dtype=float32)
if not abs(x.dot(x) - 2.0) < 1e-5:
raise AssertionError()
except AssertionError:
msg = ("The current Numpy installation ({!r}) fails to "
"pass simple sanity checks. This can be caused for example "
"by incorrect BLAS library being linked in.")
raise RuntimeError(msg.format(__file__))

_sanity_check()
del _sanity_check

0 comments on commit 5b3b867

Please sign in to comment.