Skip to content

Commit 23d743f

Browse files
committed
Handle numpy.fft already routed to mkl_fft in --numpy-backend mkl
Skip patch_numpy_fft() when the installed NumPy already routes numpy.fft to mkl_fft, and exit with an error when mkl_fft has no patch_numpy_fft(). Replace a non-ASCII dash in a comment.
1 parent 42503ca commit 23d743f

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎fft_bench.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,19 @@ def valid_dtype(dtype_str):
121121
parser.error(f'--scipy-backend mkl requested but mkl_fft is not '
122122
f'importable in this environment: {e}')
123123

124-
# Route numpy.fft through mkl_fft, failing fast if the patch does not take.
124+
# Route numpy.fft through mkl_fft unless the installed NumPy already does,
125+
# failing fast if routing is not possible.
125126
if args.numpy_backend == 'mkl':
126127
try:
127128
import mkl_fft
128129
except ImportError as e:
129130
parser.error(f'--numpy-backend mkl requested but mkl_fft is not '
130131
f'importable in this environment: {e}')
131-
mkl_fft.patch_numpy_fft()
132+
if not np.fft.fft.__module__.startswith('mkl_fft'):
133+
if not hasattr(mkl_fft, 'patch_numpy_fft'):
134+
parser.error(f'--numpy-backend mkl requested but mkl_fft '
135+
f'{mkl_fft.__version__} has no patch_numpy_fft()')
136+
mkl_fft.patch_numpy_fft()
132137
if not np.fft.fft.__module__.startswith('mkl_fft'):
133138
parser.error(f'--numpy-backend mkl requested but numpy.fft.fft is '
134139
f'still {np.fft.fft.__module__} after patching')
@@ -212,7 +217,7 @@ def valid_dtype(dtype_str):
212217
print(f'TAG: scipy_backend = {effective_backend}')
213218

214219
with backend_ctx:
215-
# threads warm-up — inside the backend context so the warmup path
220+
# threads warm-up, inside the backend context so the warmup path
216221
# matches the timed path exactly (same dispatcher, same planner).
217222
buf = np.empty_like(arr)
218223
np.copyto(buf, arr)

0 commit comments

Comments
 (0)