diff --git a/paddle/fluid/operators/reduce_ops/reduce_op.h b/paddle/fluid/operators/reduce_ops/reduce_op.h index 74d68572a3e419011e65848d32c7e5b6286d9f6f..0c6cb3e05eedc13fb46ae8e180f6f6d459369c4c 100644 --- a/paddle/fluid/operators/reduce_ops/reduce_op.h +++ b/paddle/fluid/operators/reduce_ops/reduce_op.h @@ -241,11 +241,12 @@ class ReduceKernel : public framework::OpKernel { framework::proto::VarType::Type cast_out_dtype; // The dims has full dim, set the reduce_all is True - const auto& input_dim_size = context.Input("X")->dims().size(); + const int& input_dim_size = context.Input("X")->dims().size(); std::set dims_set(dims.begin(), dims.end()); bool full_dim = true; - for (auto i = 0; i < input_dim_size; i++) { - if (dims_set.find(i) == dims_set.end()) { + for (int i = 0; i < input_dim_size; i++) { + if (dims_set.find(i) == dims_set.end() && + dims_set.find(i - input_dim_size) == dims_set.end()) { full_dim = false; break; } diff --git a/python/paddle/fluid/tests/unittests/test_max_op.py b/python/paddle/fluid/tests/unittests/test_max_op.py index caee7d9e5c2bab577f6c48a64325c22be3c8c7e7..5e413e80d7143b7dda2ffbc7cb79f1aee3dd507c 100644 --- a/python/paddle/fluid/tests/unittests/test_max_op.py +++ b/python/paddle/fluid/tests/unittests/test_max_op.py @@ -98,6 +98,15 @@ class ApiMaxTest(unittest.TestCase): self.assertEqual((np_z1 == z_expected).all(), True) self.assertEqual((np_z2 == z_expected).all(), True) + def test_all_negative_axis(self): + paddle.disable_static() + x = paddle.rand(shape=[2, 2]) + np_x = x.numpy() + z1 = paddle.max(x, axis=(-2, -1)) + np_z1 = z1.numpy() + z_expected = np.array(np.max(np_x, axis=(0, 1))) + self.assertEqual((np_z1 == z_expected).all(), True) + class TestOutDtype(unittest.TestCase): def test_max(self):