From 53ff28b9a1e82c3e45a4ca94de7f6d36fb86d67b Mon Sep 17 00:00:00 2001 From: wangchaochaohu Date: Tue, 25 Aug 2020 22:03:36 +0800 Subject: [PATCH] refine the doc for masked_select test=develop (#2469) --- doc/fluid/api/paddle.rst | 1 + doc/fluid/api/tensor.rst | 1 + doc/fluid/api/tensor/masked_select.rst | 11 +++++ doc/fluid/api_cn/paddle_cn.rst | 1 + doc/fluid/api_cn/tensor_cn.rst | 1 + .../api_cn/tensor_cn/masked_select_cn.rst | 43 +++++++++++++++++++ 6 files changed, 58 insertions(+) create mode 100644 doc/fluid/api/tensor/masked_select.rst create mode 100644 doc/fluid/api_cn/tensor_cn/masked_select_cn.rst diff --git a/doc/fluid/api/paddle.rst b/doc/fluid/api/paddle.rst index 8f9717c1d..9670615d7 100644 --- a/doc/fluid/api/paddle.rst +++ b/doc/fluid/api/paddle.rst @@ -97,6 +97,7 @@ paddle paddle/logical_xor.rst paddle/logsumexp.rst paddle/manual_seed.rst + paddle/masked_select.rst paddle/matmul.rst paddle/max.rst paddle/maximum.rst diff --git a/doc/fluid/api/tensor.rst b/doc/fluid/api/tensor.rst index 82ac61c6e..b79132329 100644 --- a/doc/fluid/api/tensor.rst +++ b/doc/fluid/api/tensor.rst @@ -67,6 +67,7 @@ paddle.tensor tensor/logical_or.rst tensor/logical_xor.rst tensor/math.rst + tensor/masked_select.rst tensor/max.rst tensor/maximum.rst tensor/mean.rst diff --git a/doc/fluid/api/tensor/masked_select.rst b/doc/fluid/api/tensor/masked_select.rst new file mode 100644 index 000000000..b3e0d11be --- /dev/null +++ b/doc/fluid/api/tensor/masked_select.rst @@ -0,0 +1,11 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_search_masked_select: + +masked_select +--------------- + +.. autofunction:: paddle.tensor.search.masked_select + :noindex: + diff --git a/doc/fluid/api_cn/paddle_cn.rst b/doc/fluid/api_cn/paddle_cn.rst index 477822816..2e6632b2b 100644 --- a/doc/fluid/api_cn/paddle_cn.rst +++ b/doc/fluid/api_cn/paddle_cn.rst @@ -96,6 +96,7 @@ paddle paddle_cn/logsumexp_cn.rst paddle_cn/log_cn.rst paddle_cn/manual_seed_cn.rst + paddle_cn/masked_select_cn.rst paddle_cn/matmul_cn.rst paddle_cn/max_cn.rst paddle_cn/maximum_cn.rst diff --git a/doc/fluid/api_cn/tensor_cn.rst b/doc/fluid/api_cn/tensor_cn.rst index 99212feda..2faa62d9b 100644 --- a/doc/fluid/api_cn/tensor_cn.rst +++ b/doc/fluid/api_cn/tensor_cn.rst @@ -92,6 +92,7 @@ paddle.tensor tensor_cn/logical_or_cn.rst tensor_cn/logical_xor_cn.rst tensor_cn/logsumexp_cn.rst + tensor_cn/masked_select_cn.rst tensor_cn/math_cn.rst tensor_cn/matmul_cn.rst tensor_cn/max_cn.rst diff --git a/doc/fluid/api_cn/tensor_cn/masked_select_cn.rst b/doc/fluid/api_cn/tensor_cn/masked_select_cn.rst new file mode 100644 index 000000000..cecffda2c --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/masked_select_cn.rst @@ -0,0 +1,43 @@ +.. _cn_api_tensor_masked_select: + +masked_select +------------------------------- + +.. py:function:: paddle.masked_select(x, mask, name=None) + + + +该OP返回一个1-D 的Tensor, Tensor的值是根据 ``mask`` 对输入 ``x`` 进行选择的, ``mask`` 的数据类型是bool 。 + +参数: + - **x** (Tensor) - 输入Tensor, 数据类型为float32, float64,int32 或者int64。 + - **mask** (Tensor) - 用于索引的二进制掩码的Tensor,数据类型维bool。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 + +返回:返回一个根据 ``mask`` 选择的的Tensor + + +抛出异常: + - ``TypeError``: - 如果 ``x`` 不是 Tensor 或者 ``x`` 是Tensor的时候的数据类型不是 float32, float64, int32, int64其中之一。 + - ``TypeError``: - 如果 ``mask`` 不是 Tensor 或者 ``mask`` 是Tensor的时候的数据类型不是 bool。 + +**代码示例**: + +.. code-block:: python + + import paddle + import numpy as np + + paddle.disable_static() + data = np.array([[1.0, 2.0, 3.0, 4.0], + [5.0, 6.0, 7.0, 8.0], + [9.0, 10.0, 11.0, 12.0]]).astype('float32') + + mask_data = np.array([[True, False, False, False], + [True, True, False, False], + [True, False, False, False]]).astype('bool') + x = paddle.to_tensor(data) + mask = paddle.to_tensor(mask_data) + out = paddle.masked_select(x, mask) + #[1.0 5.0 6.0 9.0] + -- GitLab