Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reduce bug 2.2 #38478

Merged
merged 1 commit into from
Dec 29, 2021
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 paddle/fluid/operators/reduce_ops/reduce_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,12 @@ class ReduceKernel : public framework::OpKernel<T> {
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<Tensor>("X")->dims().size();
const int& input_dim_size = context.Input<Tensor>("X")->dims().size();
std::set<int> 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;
}
Expand Down
9 changes: 9 additions & 0 deletions python/paddle/fluid/tests/unittests/test_max_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ def test_big_dimension(self):
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):
Expand Down