diff --git a/paddle/phi/api/yaml/legacy_backward.yaml b/paddle/phi/api/yaml/legacy_backward.yaml index 2050653904d16f5293c65c378659fd6072ab0c96..9810242037bcec02dee243f74a0af434b334440e 100755 --- a/paddle/phi/api/yaml/legacy_backward.yaml +++ b/paddle/phi/api/yaml/legacy_backward.yaml @@ -411,6 +411,16 @@ kernel : func : einsum_grad +- backward_op : elementwise_heaviside_grad + forward : heaviside (Tensor x, Tensor y) -> Tensor(out) + args : (Tensor x, Tensor y, Tensor out_grad, int axis = -1) + output : Tensor(x_grad), Tensor(y_grad) + infer_meta : + func : GeneralBinaryGradInferMeta + param : [x, y] + kernel : + func : elementwise_heaviside_grad + - backward_op : elementwise_pow_grad forward : elementwise_pow(Tensor x, Tensor y) -> Tensor(out) args : (Tensor x, Tensor y, Tensor out_grad, int axis=-1) diff --git a/paddle/phi/api/yaml/legacy_ops.yaml b/paddle/phi/api/yaml/legacy_ops.yaml index b448dadbd58ca2b141b6f752ab8f292c5220365f..3be9cdf371d317a1d671b2bb606d1f1b76f52cba 100755 --- a/paddle/phi/api/yaml/legacy_ops.yaml +++ b/paddle/phi/api/yaml/legacy_ops.yaml @@ -564,6 +564,15 @@ func : einsum backward : einsum_grad +- op : elementwise_heaviside + args : (Tensor x, Tensor y) + output : Tensor + infer_meta : + func : ElementwiseInferMeta + kernel : + func : elementwise_heaviside + backward : elementwise_heaviside_grad + - op : elementwise_pow args : (Tensor x, Tensor y) output : Tensor(out) diff --git a/python/paddle/fluid/tests/unittests/test_elementwise_heaviside_op.py b/python/paddle/fluid/tests/unittests/test_elementwise_heaviside_op.py index d917a6bc33a661c0e448b1a25c22f3a7d3f52935..4e80ef918704d6973cebe843466c999884418b63 100644 --- a/python/paddle/fluid/tests/unittests/test_elementwise_heaviside_op.py +++ b/python/paddle/fluid/tests/unittests/test_elementwise_heaviside_op.py @@ -32,20 +32,21 @@ class TestElementwiseOp(OpTest): self.op_type = "elementwise_heaviside" x = np.random.random((13, 17)).astype("float64") y = np.random.random((13, 17)).astype("float64") + self.python_api = paddle.heaviside self.inputs = {'X': x, 'Y': y} self.outputs = {'Out': np.heaviside(self.inputs['X'], self.inputs['Y'])} def test_check_output(self): - self.check_output() + self.check_output(check_eager=True) def test_check_grad_normal(self): - self.check_grad(['X', 'Y'], 'Out') + self.check_grad(['X', 'Y'], 'Out', check_eager=True) def test_check_grad_ingore_x(self): - self.check_grad(['Y'], 'Out', no_grad_set=set("X")) + self.check_grad(['Y'], 'Out', no_grad_set=set("X"), check_eager=True) def test_check_grad_ingore_y(self): - self.check_grad(['X'], 'Out', no_grad_set=set('Y')) + self.check_grad(['X'], 'Out', no_grad_set=set('Y'), check_eager=True) class TestHeavisideBroadcast(unittest.TestCase): diff --git a/python/paddle/tensor/math.py b/python/paddle/tensor/math.py index 32978bc30dd994aaa2d08c87b988bf1d2a9054ed..81b092f4c38b4e177a47abc496c85ccae79d409c 100644 --- a/python/paddle/tensor/math.py +++ b/python/paddle/tensor/math.py @@ -4857,14 +4857,10 @@ def heaviside(x, y, name=None): # [[0. , 0.20000000, 1. ], # [0. , 1. , 0.30000001]] """ - op_type = 'elementwise_heaviside' - axis = -1 - act = None if in_dygraph_mode(): - return _elementwise_op_in_dygraph( - x, y, axis=axis, act=act, op_name=op_type - ) + return _C_ops.elementwise_heaviside(x, y) else: + op_type = 'elementwise_heaviside' return _elementwise_op(LayerHelper(op_type, **locals()))