Skip to content
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
7 changes: 4 additions & 3 deletions src/relay/op/tensor/reduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ inline std::vector<int64_t> GetReduceAxes(const uint32_t indim,
// Get axis under exclude condition.
Array<Integer> GetExcludeAxes(size_t indim,
const Array<Integer>& inaxis) {
CHECK(inaxis.defined()) << "Cannot set exclude when axis=None";
std::vector<bool> axis_flag(indim, true);
for (auto i : inaxis) {
int64_t axis = i->value;
Expand Down Expand Up @@ -137,9 +138,9 @@ Array<Tensor> ReduceCompute(const Attrs& attrs,
auto axes = param->axis;
if (param->exclude) {
axes = GetExcludeAxes(inputs[0]->shape.size(), param->axis);
}
if (axes.size() == 0) {
return { topi::identity(inputs[0]) };
if (axes.size() == 0) {
return { topi::identity(inputs[0]) };
}
}
return { f(inputs[0], axes, param->keepdims, false) };
}
Expand Down
4 changes: 2 additions & 2 deletions tests/python/relay/test_op_level4.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def verify_reduce(funcs, data, axis, keepdims, exclude, output, dtype="float32")
out_type = "int32" if test_func in [relay.argmin, relay.argmax] else dtype
assert zz.checked_type == relay.ty.TensorType(output, out_type)

if all(isinstance(v, tvm.expr.Var) == 1 for v in data) or len(output) == 0:
if all(isinstance(v, tvm.expr.Var) == 1 for v in data):
return

func = relay.Function([x], z)
Expand Down Expand Up @@ -187,7 +187,7 @@ def _wrapper(data, axis=None, keepdims=False):
verify_reduce(func, (2, 3, 4), 1, True, False, (2, 1, 4))
verify_reduce(func, (2, 3, 4), (1,), True, False, (2, 1, 4))
verify_reduce(func, (2, 3, 4), (0, 1, 2), False, False, ())
verify_reduce(func, (4, 4, 3), None, False, True, ())
verify_reduce(func, (4, 4, 3), None, False, False, ())
verify_reduce(func, (4, 4, 3), (0, 2), False, False, (4,))
verify_reduce(func, (128, 24, 128), (0, 1), False, False, (128,))
verify_reduce(func, (128, 24, 128), (0, 2), False, False, (24,))
Expand Down