未验证 提交 dbd6e2df 编写于 作者: C Chen Weihang 提交者: GitHub

add unique yaml and final state api (#41460)

上级 8fba68d3
......@@ -21,6 +21,7 @@ import paddle
import paddle.fluid as fluid
import paddle.fluid.core as core
from paddle.fluid.op import Operator
from paddle.fluid.framework import _test_eager_guard
class TestUniqueOp(OpTest):
......@@ -251,6 +252,12 @@ class TestUniqueAPI(unittest.TestCase):
self.assertTrue((counts.numpy() == np_counts).all(), True)
paddle.enable_static()
def test_dygraph_final_state_api(self):
with _test_eager_guard():
self.test_dygraph_api_out()
self.test_dygraph_api_attr()
self.test_dygraph_attr_dtype()
def test_static_graph(self):
with paddle.static.program_guard(paddle.static.Program(),
paddle.static.Program()):
......
......@@ -1211,11 +1211,16 @@ def unique(x,
else:
axis = [axis]
attr_dtype = convert_np_dtype_to_dtype_(dtype)
if paddle.in_dynamic_mode():
if _non_static_mode():
if in_dygraph_mode():
out, indices, inverse, counts = _C_ops.final_state_unique(
x, return_index, return_inverse, return_counts, axis,
attr_dtype)
if _in_legacy_dygraph():
out, inverse, indices, counts = _C_ops.unique(
x, 'dtype', attr_dtype, 'return_index', return_index,
'return_inverse', return_inverse, 'return_counts', return_counts,
'axis', axis, "is_sorted", True)
'return_inverse', return_inverse, 'return_counts',
return_counts, 'axis', axis, "is_sorted", True)
outs = [out]
if return_index:
outs.append(indices)
......
......@@ -1937,6 +1937,16 @@
func : unfold
backward : unfold_grad
# The `axis` argument of Python API paddle.unique is not vector
- api : unique
args : (Tensor x, bool return_index, bool return_inverse, bool return_counts, int[] axis, DataType dtype=DataType::INT64)
output : Tensor(out), Tensor(indices), Tensor(inverse), Tensor(counts)
infer_meta :
func : UniqueInferMeta
kernel :
func : unique
data_type : x
- api : unsqueeze
args : (Tensor x, IntArray axes)
output : Tensor(xshape), Tensor(out)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册