Skip to content

Commit 331106f

Browse files
authored
Merge pull request numpy#11169 from pv/import-sanitycheck
MAINT: add sanity-checks to be run at import time
2 parents d405127 + 553c865 commit 331106f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

numpy/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,28 @@ def pkgload(*packages, **options):
194194
from numpy.testing._private.pytesttester import PytestTester
195195
test = PytestTester(__name__)
196196
del PytestTester
197+
198+
199+
def _sanity_check():
200+
"""
201+
Quick sanity checks for common bugs caused by environment.
202+
There are some cases e.g. with wrong BLAS ABI that cause wrong
203+
results under specific runtime conditions that are not necessarily
204+
achieved during test suite runs, and it is useful to catch those early.
205+
206+
See https://github.com/numpy/numpy/issues/8577 and other
207+
similar bug reports.
208+
209+
"""
210+
try:
211+
x = ones(2, dtype=float32)
212+
if not abs(x.dot(x) - 2.0) < 1e-5:
213+
raise AssertionError()
214+
except AssertionError:
215+
msg = ("The current Numpy installation ({!r}) fails to "
216+
"pass simple sanity checks. This can be caused for example "
217+
"by incorrect BLAS library being linked in.")
218+
raise RuntimeError(msg.format(__file__))
219+
220+
_sanity_check()
221+
del _sanity_check

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy