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
6 changes: 6 additions & 0 deletions paddle/phi/kernels/funcs/reduce_functor.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ struct AMaxOrAMinGradFunctor {
mask.sum(axis).reshape(dy->dimensions()).broadcast(dim);
return;
}

if (rank == 0) {
dx->device(place) = dy->broadcast(dim) * mask;
return;
}

// axis is list, HANDLE_AXIS_DIM(broadcast_dim_size, rank)
HANDLE_AXIS_DIM(3, 2);
HANDLE_AXIS_DIM(4, 2);
Expand Down
27 changes: 27 additions & 0 deletions test/legacy_test/test_max_min_amax_amin_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,33 @@ def _test_dygraph(func):
# test two minimum or maximum elements


class TestMaxMinAmaxAminAPI_AxisWithOne1(TestMaxMinAmaxAminAPI):
def init_case(self):
self.x_np = np.random.randn(1, 5, 10).astype(np.float32)
self.shape = [1, 5, 10]
self.dtype = 'float32'
self.axis = 0
self.keepdim = False


class TestMaxMinAmaxAminAPI_AxisWithOne2(TestMaxMinAmaxAminAPI):
def init_case(self):
self.x_np = np.random.randn(1, 5, 10).astype(np.float32)
self.shape = [1, 5, 10]
self.dtype = 'float32'
self.axis = 0
self.keepdim = True


class TestMaxMinAmaxAminAPI_AxisWithOne3(TestMaxMinAmaxAminAPI):
def init_case(self):
self.x_np = np.random.randn(1, 1, 10).astype(np.float32)
self.shape = [1, 1, 10]
self.dtype = 'float32'
self.axis = (0, 1)
self.keepdim = False


class TestMaxMinAmaxAminAPI_ZeroDim(TestMaxMinAmaxAminAPI):
def init_case(self):
self.x_np = np.array(0.5)
Expand Down