未验证 提交 6b5cff54 编写于 作者: 0 0x45f 提交者: GitHub

Add UT for full_like after migration YAML (#41290)

* Add UT for full_like after migration YAML

* rename test class
上级 afadb8c5
...@@ -21,6 +21,7 @@ import paddle.compat as cpt ...@@ -21,6 +21,7 @@ import paddle.compat as cpt
import unittest import unittest
import numpy as np import numpy as np
from op_test import OpTest from op_test import OpTest
from paddle.fluid.framework import convert_np_dtype_to_dtype_
class TestFullOp(unittest.TestCase): class TestFullOp(unittest.TestCase):
...@@ -92,5 +93,45 @@ class TestFullOpError(unittest.TestCase): ...@@ -92,5 +93,45 @@ class TestFullOpError(unittest.TestCase):
dtype='uint4') dtype='uint4')
class TestFullLikeOp1(OpTest):
# test basic
def setUp(self):
self.op_type = "fill_any_like"
self.python_api = paddle.full_like
self.init_data()
x = np.zeros(self.shape)
out = np.full_like(x, self.fill_value, self.dtype)
self.inputs = {'X': x}
self.outputs = {'Out': out}
self.attrs = {
'value': self.fill_value,
'dtype': convert_np_dtype_to_dtype_(self.dtype)
}
def init_data(self):
self.fill_value = 5
self.shape = [10, 10]
self.dtype = np.float32
def test_check_output(self):
self.check_output(check_eager=True)
class TestFullLikeOp2(TestFullLikeOp1):
def init_data(self):
self.fill_value = 1000
self.shape = [1024, 1024]
self.dtype = np.float64
class TestFullLikeOp3(TestFullLikeOp1):
def init_data(self):
self.fill_value = 8888
self.shape = [5000, 5000]
self.dtype = np.int64
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
...@@ -224,7 +224,10 @@ def full_like(x, fill_value, dtype=None, name=None): ...@@ -224,7 +224,10 @@ def full_like(x, fill_value, dtype=None, name=None):
if not isinstance(dtype, core.VarDesc.VarType): if not isinstance(dtype, core.VarDesc.VarType):
dtype = convert_np_dtype_to_dtype_(dtype) dtype = convert_np_dtype_to_dtype_(dtype)
if paddle.in_dynamic_mode(): if in_dygraph_mode():
return _C_ops.final_state_full_like(x, fill_value, dtype, x.place)
if _in_legacy_dygraph():
return _C_ops.fill_any_like(x, 'value', fill_value, 'dtype', dtype) return _C_ops.fill_any_like(x, 'value', fill_value, 'dtype', dtype)
helper = LayerHelper("full_like", **locals()) helper = LayerHelper("full_like", **locals())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册