move fast path code to be after the argument checks
@@ -602,13 +602,6 @@ def pad(array, pad_width, mode='constant', **kwargs):
# Broadcast to shape (array.ndim, 2)
pad_width = _as_pairs(pad_width, array.ndim, as_index=True)
- if mode == 'constant':
- values = kwargs.get('constant_values', 0)
- if isinstance(values, numbers.Number) and values == 0 and (
- array.ndim == 1 or array.size < 4e6):
- # faster path for 1d arrays or small n-dimensional arrays
- return _pad_simple(array, pad_width, 0)[0]
-
if callable(mode):
# Old behavior: Use user-supplied function with numpy.apply_along_axis
function = mode
@@ -657,6 +650,13 @@ def pad(array, pad_width, mode='constant', **kwargs):
)
)
+ if mode == 'constant':
+ values = kwargs.get('constant_values', 0)
+ if isinstance(values, numbers.Number) and values == 0 and (
+ array.ndim == 1 or array.size < 4e6):
+ # faster path for 1d arrays or small n-dimensional arrays
+ return _pad_simple(array, pad_width, 0)[0]
+
stat_functions = {
'maximum': cupy.max,
'minimum': cupy.min,
@@ -672,7 +672,6 @@ def pad(array, pad_width, mode='constant', **kwargs):
axes = range(padded.ndim)
if mode == 'constant':
- values = kwargs.get('constant_values', 0)
values = _as_pairs(values, padded.ndim)
for axis, width_pair, value_pair in zip(axes, pad_width, values):
roi = _view_roi(padded, original_area_slice, axis)
