Skip to content

Commit

Permalink
tests: Fix AVX512 detection on Numpy>=1.26 (#2932)
Browse files Browse the repository at this point in the history
The output format of show_config() changed, but the library now provides
and option to return the values in a dictionary.

Signed-off-by: Jan Vesely <[email protected]>
  • Loading branch information
jvesely authored Mar 24, 2024
1 parent 3f1c830 commit f58e2c5
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,25 @@ def mech_wrapper(x):

@pytest.helpers.register
def numpy_uses_avx512():
out = io.StringIO()
with contextlib.redirect_stdout(out):
np.show_config()

return re.search(' found = .*AVX512.*', out.getvalue()) is not None
try:
# numpy >= 1.26 can return config info in a dictionary
config = np.show_config(mode="dicts")

except TypeError:
# Numpy >=1.21 < 1.26 doesn't support 'mode' argument and
# prints CPU extensions in one line per category:
# baseline = ...
# found = ...
# not found = ...
out = io.StringIO()

with contextlib.redirect_stdout(out):
np.show_config()

return re.search(' found = .*AVX512.*', out.getvalue()) is not None
else:
return any(ext.startswith("AVX512") for ext in config['SIMD Extensions']['found'])

@pytest.helpers.register
def expand_np_ndarray(arr):
Expand Down

0 comments on commit f58e2c5

Please sign in to comment.