From f80f552881c253731184beef987cad7e206f2615 Mon Sep 17 00:00:00 2001 From: Python Infra CI Date: Mon, 2 Nov 2026 20:04:03 +0000 Subject: [PATCH 1/2] perf: hoist unsupported-dtype blacklist out of the scipy.fft interface h --- mkl_fft/interfaces/_float_utils.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mkl_fft/interfaces/_float_utils.py b/mkl_fft/interfaces/_float_utils.py index af0f1dae..57a48c9c 100644 --- a/mkl_fft/interfaces/_float_utils.py +++ b/mkl_fft/interfaces/_float_utils.py @@ -25,6 +25,17 @@ import numpy as np +# Computed once at import time: the set of dtypes mkl_fft cannot handle and +# that `scipy.fft` must therefore reject with NotImplementedError. Whether +# `np.float128`/`np.complex256` exist is fixed by the NumPy build and cannot +# change at runtime, so recomputing this list on every call (as +# `_supported_array_or_not_implemented` used to) is pure per-call overhead. +_UNSUPPORTED_DTYPES = [np.half] +if hasattr(np, "float128"): + _UNSUPPORTED_DTYPES.append(np.float128) +if hasattr(np, "complex256"): + _UNSUPPORTED_DTYPES.append(np.complex256) + def _upcast_float16_array(x): """ @@ -78,11 +89,6 @@ def _supported_array_or_not_implemented(x): or complex128 type or raise NotImplementedError """ _x = np.asarray(x) - black_list = [np.half] - if hasattr(np, "float128"): - black_list.append(np.float128) - if hasattr(np, "complex256"): - black_list.append(np.complex256) - if _x.dtype in black_list: + if _x.dtype in _UNSUPPORTED_DTYPES: raise NotImplementedError return _x From 4704d52acd1a1d2a90c18d047df63a94fa3057bb Mon Sep 17 00:00:00 2001 From: "Harlow, Jordan" Date: Tue, 3 Nov 2026 07:15:10 -0700 Subject: [PATCH 2/2] perf: make the unsupported-dtype check a frozenset lookup Comparing a dtype against np.half/np.float128/np.complex256 with `in` on a list coerces each scalar type to a dtype on every call. Storing np.dtype objects in a frozenset turns it into one hash lookup, roughly doubling the per-call saving of the previous commit on small transforms. --- mkl_fft/interfaces/_float_utils.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/mkl_fft/interfaces/_float_utils.py b/mkl_fft/interfaces/_float_utils.py index 57a48c9c..001e4960 100644 --- a/mkl_fft/interfaces/_float_utils.py +++ b/mkl_fft/interfaces/_float_utils.py @@ -25,16 +25,12 @@ import numpy as np -# Computed once at import time: the set of dtypes mkl_fft cannot handle and -# that `scipy.fft` must therefore reject with NotImplementedError. Whether -# `np.float128`/`np.complex256` exist is fixed by the NumPy build and cannot -# change at runtime, so recomputing this list on every call (as -# `_supported_array_or_not_implemented` used to) is pure per-call overhead. -_UNSUPPORTED_DTYPES = [np.half] -if hasattr(np, "float128"): - _UNSUPPORTED_DTYPES.append(np.float128) -if hasattr(np, "complex256"): - _UNSUPPORTED_DTYPES.append(np.complex256) +# dtypes the scipy.fft interface rejects; np.dtype keys make `in` a hash lookup +_UNSUPPORTED_DTYPES = frozenset( + np.dtype(getattr(np, name)) + for name in ("half", "float128", "complex256") + if hasattr(np, name) +) def _upcast_float16_array(x):