diff --git a/paddle/phi/api/yaml/legacy_api.yaml b/paddle/phi/api/yaml/legacy_api.yaml index 4857603c080fe60992943dbc245bfd95e30bc7d3..018f20a60872910c2de0591ca66615f0b438439e 100755 --- a/paddle/phi/api/yaml/legacy_api.yaml +++ b/paddle/phi/api/yaml/legacy_api.yaml @@ -319,7 +319,7 @@ func : AucInferMeta kernel : func : auc - optional : ins_tag_weight + optional : ins_tag_weight #average_accumulates - api : average_accumulates_ @@ -1785,6 +1785,11 @@ kernel : func : one_hot +- api : ones + args : (IntArray shape, DataType dtype=DataType::FLOAT32, Place place=CPUPlace()) + output : Tensor + invoke : full(shape, 1, dtype, place) + - api : ones_like args : (Tensor x, DataType dtype=DataType::UNDEFINED, Place place={}) output : Tensor @@ -2728,6 +2733,11 @@ optional : gt_score backward : yolov3_loss_grad +- api : zeros + args : (IntArray shape, DataType dtype=DataType::FLOAT32, Place place=CPUPlace()) + output : Tensor + invoke : full(shape, 0, dtype, place) + - api : zeros_like args : (Tensor x, DataType dtype=DataType::UNDEFINED, Place place = {}) output : Tensor diff --git a/python/paddle/fluid/tests/unittests/test_ones_like.py b/python/paddle/fluid/tests/unittests/test_ones_like.py index 31e28fe4787076e2e16b8ba63eaae832437221e4..4c1394caaee044b53340893dfea804339732c649 100644 --- a/python/paddle/fluid/tests/unittests/test_ones_like.py +++ b/python/paddle/fluid/tests/unittests/test_ones_like.py @@ -18,8 +18,10 @@ import unittest import numpy as np import paddle import paddle.fluid as fluid +from paddle import _C_ops from paddle import ones_like from paddle.fluid import core, Program, program_guard +from paddle.fluid.framework import convert_np_dtype_to_dtype_ class TestOnesLikeAPIError(unittest.TestCase): @@ -79,5 +81,22 @@ class TestOnesLikeImpeartive(unittest.TestCase): paddle.enable_static() +class TestOnesAPI(unittest.TestCase): + + def test_api(self): + shape = [3, 4] + place = fluid.CUDAPlace( + 0) if core.is_compiled_with_cuda() else fluid.CPUPlace() + paddle.disable_static(place) + + for dtype in [np.float32, np.float64, np.int32, np.int64]: + out = _C_ops.final_state_ones(shape, + convert_np_dtype_to_dtype_(dtype), + place) + self.assertEqual((out.numpy() == np.ones(shape, dtype)).all(), True) + + paddle.enable_static() + + if __name__ == "__main__": unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_zeros_like_op.py b/python/paddle/fluid/tests/unittests/test_zeros_like_op.py index 13911dff01601e07d82b6839fe4e61ceb16481af..fcd6bba051eac8e3ade125a0ba3a9cc9ea1e192e 100644 --- a/python/paddle/fluid/tests/unittests/test_zeros_like_op.py +++ b/python/paddle/fluid/tests/unittests/test_zeros_like_op.py @@ -18,8 +18,10 @@ import numpy as np import paddle import paddle.fluid as fluid from paddle import zeros_like +from paddle import _C_ops from paddle.fluid import core, Program, program_guard from paddle.fluid.framework import _test_eager_guard +from paddle.fluid.framework import convert_np_dtype_to_dtype_ class TestZerosLikeAPIError(unittest.TestCase): @@ -86,5 +88,23 @@ class TestZerosLikeImpeartive(unittest.TestCase): self.test_out() +class TestZerosAPI(unittest.TestCase): + + def test_api(self): + shape = [3, 4] + place = fluid.CUDAPlace( + 0) if core.is_compiled_with_cuda() else fluid.CPUPlace() + paddle.disable_static(place) + + for dtype in [np.float32, np.float64, np.int32, np.int64]: + out = _C_ops.final_state_zeros(shape, + convert_np_dtype_to_dtype_(dtype), + place) + self.assertEqual((out.numpy() == np.zeros(shape, dtype)).all(), + True) + + paddle.enable_static() + + if (__name__ == '__main__'): unittest.main()