summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2018-05-27 19:02:03 +0200
committerPauli Virtanen <pav@iki.fi>2018-05-27 19:27:20 +0200
commit553c865599116aa20079aaf10142ff60ab8b0ae0 (patch)
treedf582564f553e10aabfbbcf36cc811f28201d5a4
parentd405127e02c3b729a57970f2a9663e628fa4155d (diff)
downloadnumpy-553c865599116aa20079aaf10142ff60ab8b0ae0.tar.gz
MAINT: add sanity-checks to be run at import time
This checks for potential BLAS issues, which are useful to catch early.
-rw-r--r--numpy/__init__.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py
index d10a1ecd3..d250ed5ac 100644
--- a/numpy/__init__.py
+++ b/numpy/__init__.py
@@ -194,3 +194,28 @@ else:
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