Skip to content

Commit

Permalink
MAINT: add sanity-checks to be run at import time
Browse files Browse the repository at this point in the history
This checks for potential BLAS issues, which are useful to catch early.
  • Loading branch information
pv committed May 27, 2018
1 parent d405127 commit 553c865
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,28 @@ def pkgload(*packages, **options):
from numpy.testing._private.pytesttester import PytestTester
test = PytestTester(__name__)
del PytestTester


def _sanity_check():
"""
Quick sanity checks for common bugs caused by environment.
There are some cases e.g. with 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 553c865

Please sign in to comment.