Skip to content

Commit f89b813

Browse files
committed
add axis==None condition for zero-size array
1 parent cb7e686 commit f89b813

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

dpnp/dpnp_iface_statistics.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,14 @@ def max(a, axis=None, out=None, keepdims=False, initial=None, where=True):
414414
axis = (axis,) if isinstance(axis, int) else axis
415415
for i in range(a.ndim):
416416
if a.shape[i] == 0:
417-
if i not in axis:
418-
indices = [i for i in range(a.ndim) if i not in axis]
419-
res_shape = tuple([a.shape[i] for i in indices])
420-
result = dpnp.empty(res_shape, dtype=a.dtype)
421-
else:
417+
if axis is None or i in axis:
422418
raise ValueError(
423419
"reduction does not support zero-size arrays"
424420
)
421+
else:
422+
indices = [i for i in range(a.ndim) if i not in axis]
423+
res_shape = tuple([a.shape[i] for i in indices])
424+
result = dpnp.empty(res_shape, dtype=a.dtype)
425425
else:
426426
result = dpnp_array._create_from_usm_ndarray(
427427
dpt.max(dpt_array, axis=axis, keepdims=keepdims)
@@ -658,14 +658,14 @@ def min(a, axis=None, out=None, keepdims=False, initial=None, where=True):
658658
# TODO: get rid of this if condition when dpctl supports it
659659
for i in range(a.ndim):
660660
if a.shape[i] == 0:
661-
if i not in axis:
662-
indices = [i for i in range(a.ndim) if i not in axis]
663-
res_shape = tuple([a.shape[i] for i in indices])
664-
result = dpnp.empty(res_shape, dtype=a.dtype)
665-
else:
661+
if axis is None or i in axis:
666662
raise ValueError(
667663
"reduction does not support zero-size arrays"
668664
)
665+
else:
666+
indices = [i for i in range(a.ndim) if i not in axis]
667+
res_shape = tuple([a.shape[i] for i in indices])
668+
result = dpnp.empty(res_shape, dtype=a.dtype)
669669
else:
670670
result = dpnp_array._create_from_usm_ndarray(
671671
dpt.min(dpt_array, axis=axis, keepdims=keepdims)

0 commit comments

Comments
 (0)