Skip to content

Commit 27f7037

Browse files
author
Python Infra CI
committed
perf: skip numpy array creation in _compute_fwd_scale scalar path
1 parent 525abaf commit 27f7037

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎mkl_fft/_fft_utils.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ def _compute_fwd_scale(norm, n, shape):
7070
return 1.0
7171

7272
ss = n if n is not None else shape
73-
nn = np.prod(ss)
73+
# The 1-D callers in `_mkl_fft.py` always pass a plain scalar here
74+
# (either `n` or `x.shape[axis]`), so avoid the overhead of wrapping
75+
# it in a 0-d numpy array via `np.prod` on that hot path. Sequences
76+
# (used by the N-D callers via `_nd_fwd_scale`) still go through
77+
# `np.prod`, unchanged.
78+
if isinstance(ss, (int, np.integer)):
79+
nn = ss
80+
else:
81+
nn = np.prod(ss)
7482
fsc = 1 / nn if nn != 0 else 1
7583
if norm == "forward":
7684
return fsc

0 commit comments

Comments
 (0)