diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2018-05-27 13:49:28 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-27 13:49:28 -0600 |
commit | 5b3b867eb2cc5002b214901d26e0703206d3ae6c (patch) | |
tree | bb43ed42e6a1712372be6585bac41cf2d1a68e18 | |
parent | 9667d47908cc7f0280fe79e8d74874ba8ab1fbd5 (diff) | |
parent | c2c7cae8dae1004f17e7178d445dd498d0eaab14 (diff) | |
download | numpy-5b3b867eb2cc5002b214901d26e0703206d3ae6c.tar.gz |
Merge pull request #11174 from charris/backport-11169
MAINT: add sanity-checks to be run at import time
-rw-r--r-- | numpy/__init__.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py index db99294bc..25e72ee16 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -197,3 +197,27 @@ else: # 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 |