Skip to content

Commit a4ad142

Browse files
authored
Merge pull request numpy#27472 from joaoe/defered_evaluation_sve
Make check for SVE support happen on demand and not during module import
2 parents 22c7913 + 2218b2e commit a4ad142

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

numpy/_core/tests/test_multiarray.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
assert_array_equal, assert_raises_regex, assert_array_almost_equal,
3131
assert_allclose, IS_PYPY, IS_WASM, IS_PYSTON, HAS_REFCOUNT,
3232
assert_array_less, runstring, temppath, suppress_warnings, break_cycles,
33-
_SUPPORTS_SVE, assert_array_compare,
33+
check_support_sve, assert_array_compare,
3434
)
3535
from numpy.testing._private.utils import requires_memory, _no_tracing
3636
from numpy._core.tests._locales import CommaDecimalPointLocale
@@ -10119,7 +10119,7 @@ def test_non_c_contiguous(self):
1011910119
assert_array_equal(x.view('<i2'), expected)
1012010120

1012110121

10122-
@pytest.mark.xfail(_SUPPORTS_SVE, reason="gh-22982")
10122+
@pytest.mark.xfail(check_support_sve(), reason="gh-22982")
1012310123
# Test various array sizes that hit different code paths in quicksort-avx512
1012410124
@pytest.mark.parametrize("N", np.arange(1, 512))
1012510125
@pytest.mark.parametrize("dtype", ['e', 'f', 'd'])

numpy/_core/tests/test_scalarmath.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from numpy.testing import (
1717
assert_, assert_equal, assert_raises, assert_almost_equal,
1818
assert_array_equal, IS_PYPY, suppress_warnings, _gen_alignment_data,
19-
assert_warns, _SUPPORTS_SVE,
19+
assert_warns, check_support_sve,
2020
)
2121

2222
types = [np.bool, np.byte, np.ubyte, np.short, np.ushort, np.intc, np.uintc,
@@ -151,7 +151,7 @@ def test_int_float_promotion_truediv(fscalar):
151151

152152

153153
class TestBaseMath:
154-
@pytest.mark.xfail(_SUPPORTS_SVE, reason="gh-22982")
154+
@pytest.mark.xfail(check_support_sve(), reason="gh-22982")
155155
def test_blocked(self):
156156
# test alignments offsets for simd instructions
157157
# alignments for vz + 2 * (vs - 1) + 1

numpy/testing/_private/utils.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
'SkipTest', 'KnownFailureException', 'temppath', 'tempdir', 'IS_PYPY',
4141
'HAS_REFCOUNT', "IS_WASM", 'suppress_warnings', 'assert_array_compare',
4242
'assert_no_gc_cycles', 'break_cycles', 'HAS_LAPACK64', 'IS_PYSTON',
43-
'IS_MUSL', '_SUPPORTS_SVE', 'NOGIL_BUILD',
43+
'IS_MUSL', 'check_support_sve', 'NOGIL_BUILD',
4444
'IS_EDITABLE', 'run_threaded',
4545
]
4646

@@ -1374,21 +1374,24 @@ def rundocs(filename=None, raise_on_error=True):
13741374
raise AssertionError("Some doctests failed:\n%s" % "\n".join(msg))
13751375

13761376

1377-
def check_support_sve():
1377+
def check_support_sve(__cache=[]):
13781378
"""
13791379
gh-22982
13801380
"""
1381-
1381+
1382+
if __cache:
1383+
return __cache[0]
1384+
13821385
import subprocess
13831386
cmd = 'lscpu'
13841387
try:
13851388
output = subprocess.run(cmd, capture_output=True, text=True)
1386-
return 'sve' in output.stdout
1387-
except OSError:
1388-
return False
1389-
1389+
result = 'sve' in output.stdout
1390+
except (OSError, subprocess.SubprocessError):
1391+
result = False
1392+
__cache.append(result)
1393+
return __cache[0]
13901394

1391-
_SUPPORTS_SVE = check_support_sve()
13921395

13931396
#
13941397
# assert_raises and assert_raises_regex are taken from unittest.

0 commit comments

Comments
 (0)