Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[Numpy] Fix axis=-1 bug in max #17016

Merged
merged 1 commit into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/operator/numpy/np_broadcast_reduce_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ inline bool NumpyReduceAxesNoDTypeShape(const nnvm::NodeAttrs& attrs,
if (param.axis.has_value()) {
const mxnet::Tuple<int>& axes = param.axis.value();
for (int i = 0; i < axes.ndim(); ++i) {
if (ishape[axes[i]] == 0) {
if ((axes[i] >= 0) && (ishape[axes[i]] == 0)) {
is_all_reducded_axes_not_zero = false;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/python/unittest/test_numpy_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def get_grad(axis, func_name):
elif axis == 2:
temp[:,:,index,:] = 1
return temp
elif axis == 3:
elif (axis == 3 or axis == -1):
temp[:,:,:,index] = 1
return temp
elif not axis:
Expand All @@ -549,7 +549,7 @@ def _test_np_exception(func, shape, dim):
for func in ['max', 'min']:
for hybridize in [False, True]:
for keepdims in [True, False]:
for axis in ([i for i in range(in_data_dim)] + [(), None]):
for axis in ([i for i in range(in_data_dim)] + [(), None] + [-1]):
for itype in ['float16', 'float32', 'float64', 'int']:
# test gluon
if func == 'max':
Expand Down