diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2018-05-27 12:36:57 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-27 12:36:57 -0600 |
commit | 331106f57305fca038a567061bb8fe148bc49a87 (patch) | |
tree | df582564f553e10aabfbbcf36cc811f28201d5a4 /numpy | |
parent | d405127e02c3b729a57970f2a9663e628fa4155d (diff) | |
parent | 553c865599116aa20079aaf10142ff60ab8b0ae0 (diff) | |
download | numpy-331106f57305fca038a567061bb8fe148bc49a87.tar.gz |
Merge pull request #11169 from pv/import-sanitycheck
MAINT: add sanity-checks to be run at import time
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/__init__.py | 25 |
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 |