From 75b6172ddb849b8c2294f02c5934b03411876965 Mon Sep 17 00:00:00 2001 From: smallv0221 <397551318@qq.com> Date: Mon, 11 Oct 2021 13:26:30 +0000 Subject: [PATCH 1/4] add bincount api cn doc --- docs/api/paddle/Overview_cn.rst | 1 + docs/api/paddle/Tensor_cn.rst | 9 +++++++++ docs/api/paddle/bincount_cn.rst | 35 +++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 docs/api/paddle/bincount_cn.rst diff --git a/docs/api/paddle/Overview_cn.rst b/docs/api/paddle/Overview_cn.rst index c4aad96807e..9a9a642b6d8 100755 --- a/docs/api/paddle/Overview_cn.rst +++ b/docs/api/paddle/Overview_cn.rst @@ -233,6 +233,7 @@ tensor线性代数相关 :header: "API名称", "API功能" :widths: 10, 30 + " :ref:`paddle.bincount ` ", "统计输入张量中元素的出现次数" " :ref:`paddle.bmm ` ", "对输入x及输入y进行矩阵相乘" " :ref:`paddle.cholesky ` ", "计算一个对称正定矩阵或一批对称正定矩阵的Cholesky分解" " :ref:`paddle.cross ` ", "计算张量 x 和 y 在 axis 维度上的向量积(叉积)" diff --git a/docs/api/paddle/Tensor_cn.rst b/docs/api/paddle/Tensor_cn.rst index 53e50b60bab..cf9ea6970c2 100755 --- a/docs/api/paddle/Tensor_cn.rst +++ b/docs/api/paddle/Tensor_cn.rst @@ -387,6 +387,15 @@ backward(grad_tensor=None, retain_graph=False) # 3: [4000.] # 4: [5000.] +bincount(weights=None, minlength=0) +::::::::: + +返回:计算后的Tensor + +返回类型:Tensor + +请参考 :ref:`cn_api_tensor_bincount` + bitwise_and(y, out=None, name=None) ::::::::: diff --git a/docs/api/paddle/bincount_cn.rst b/docs/api/paddle/bincount_cn.rst new file mode 100644 index 00000000000..b4785156284 --- /dev/null +++ b/docs/api/paddle/bincount_cn.rst @@ -0,0 +1,35 @@ +.. _cn_api_tensor_bincount: + +bincount +------------------------------- + +.. py:function:: paddle.bincount(x, weights=None, minlength=0): + +统计输入张量中每个元素出现的次数,如果传入weights张量则每次计数加一时会乘以weights张量对应的值 + +参数: + - **x** (Tensor) - 输入Tensor。必须是一维Tensor,其中元素必须大于等于0,数据类型为int32, int64。 + - **weights** (Tensor, 可选) - weights Tensor,代表输入Tensor中每个元素的权重。长度必须与输入Tensor相同。数据类型为int32, int64, float32或float64。 + - **minlength** (int) - 输出Tensor的最小长度,如果大于输入Tensor的长度,则多出的位置补0。该值必须大于等于0。默认为0。 + +返回:Tensor,维度为1。 + +抛出异常: + - ``ValueError`` - 当输入Tensor或weights Tensor的值或形状不合法时。 + - ``IndexError`` - 当输入minlength的值不合法时。 + +**代码示例**: + +.. code-block:: python + + import paddle + + x = paddle.to_tensor([1, 2, 1, 4, 5]) + result1 = paddle.bincount(x) + print(result1) # [0, 2, 1, 0, 1, 1] + + w = paddle.to_tensor([2.1, 0.4, 0.1, 0.5, 0.5]) + result2 = paddle.bincount(x, weights=w) + print(result2) # [0., 2.19999981, 0.40000001, 0., 0.50000000, 0.50000000] + + From f79f26bc7e98947257fd23899f6471df5567532c Mon Sep 17 00:00:00 2001 From: smallv0221 <397551318@qq.com> Date: Tue, 12 Oct 2021 06:51:58 +0000 Subject: [PATCH 2/4] fix cn doc --- docs/api/paddle/bincount_cn.rst | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/api/paddle/bincount_cn.rst b/docs/api/paddle/bincount_cn.rst index b4785156284..acd57893461 100644 --- a/docs/api/paddle/bincount_cn.rst +++ b/docs/api/paddle/bincount_cn.rst @@ -8,17 +8,18 @@ bincount 统计输入张量中每个元素出现的次数,如果传入weights张量则每次计数加一时会乘以weights张量对应的值 参数: - - **x** (Tensor) - 输入Tensor。必须是一维Tensor,其中元素必须大于等于0,数据类型为int32, int64。 - - **weights** (Tensor, 可选) - weights Tensor,代表输入Tensor中每个元素的权重。长度必须与输入Tensor相同。数据类型为int32, int64, float32或float64。 - - **minlength** (int) - 输出Tensor的最小长度,如果大于输入Tensor的长度,则多出的位置补0。该值必须大于等于0。默认为0。 +:::::::::::: -返回:Tensor,维度为1。 + - **x** (Tensor) - 输入Tensor。必须是一维Tensor,其中元素必须大于等于0,数据类型为int32, int64。 + - **weights** (Tensor, 可选) - weights Tensor,代表输入Tensor中每个元素的权重。长度必须与输入Tensor相同。数据类型为int32, int64, float32或float64。默认为None + - **minlength** (int, 可选) - 输出Tensor的最小长度,如果大于输入Tensor的长度,则多出的位置补0。该值必须大于等于0。默认为0。 -抛出异常: - - ``ValueError`` - 当输入Tensor或weights Tensor的值或形状不合法时。 - - ``IndexError`` - 当输入minlength的值不合法时。 +返回: +:::::::::::: +Tensor,维度为1。 -**代码示例**: +代码示例: +:::::::::::: .. code-block:: python @@ -27,7 +28,7 @@ bincount x = paddle.to_tensor([1, 2, 1, 4, 5]) result1 = paddle.bincount(x) print(result1) # [0, 2, 1, 0, 1, 1] - + w = paddle.to_tensor([2.1, 0.4, 0.1, 0.5, 0.5]) result2 = paddle.bincount(x, weights=w) print(result2) # [0., 2.19999981, 0.40000001, 0., 0.50000000, 0.50000000] From ff0db2ab3fa360ff14e3f9adf2384bf41e8019da Mon Sep 17 00:00:00 2001 From: smallv0221 <397551318@qq.com> Date: Fri, 22 Oct 2021 04:50:33 +0000 Subject: [PATCH 3/4] add name --- docs/api/paddle/bincount_cn.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/api/paddle/bincount_cn.rst b/docs/api/paddle/bincount_cn.rst index acd57893461..7f121d086db 100644 --- a/docs/api/paddle/bincount_cn.rst +++ b/docs/api/paddle/bincount_cn.rst @@ -3,7 +3,7 @@ bincount ------------------------------- -.. py:function:: paddle.bincount(x, weights=None, minlength=0): +.. py:function:: paddle.bincount(x, weights=None, minlength=0, name=None): 统计输入张量中每个元素出现的次数,如果传入weights张量则每次计数加一时会乘以weights张量对应的值 @@ -13,6 +13,7 @@ bincount - **x** (Tensor) - 输入Tensor。必须是一维Tensor,其中元素必须大于等于0,数据类型为int32, int64。 - **weights** (Tensor, 可选) - weights Tensor,代表输入Tensor中每个元素的权重。长度必须与输入Tensor相同。数据类型为int32, int64, float32或float64。默认为None - **minlength** (int, 可选) - 输出Tensor的最小长度,如果大于输入Tensor的长度,则多出的位置补0。该值必须大于等于0。默认为0。 + - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回: :::::::::::: From f001b96e77a3dc4f7fe7dacba88d9a6af78447c8 Mon Sep 17 00:00:00 2001 From: smallv0221 <397551318@qq.com> Date: Fri, 12 Nov 2021 08:21:17 +0000 Subject: [PATCH 4/4] fix arg description --- docs/api/paddle/bincount_cn.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/paddle/bincount_cn.rst b/docs/api/paddle/bincount_cn.rst index 7f121d086db..427d0912421 100644 --- a/docs/api/paddle/bincount_cn.rst +++ b/docs/api/paddle/bincount_cn.rst @@ -12,7 +12,7 @@ bincount - **x** (Tensor) - 输入Tensor。必须是一维Tensor,其中元素必须大于等于0,数据类型为int32, int64。 - **weights** (Tensor, 可选) - weights Tensor,代表输入Tensor中每个元素的权重。长度必须与输入Tensor相同。数据类型为int32, int64, float32或float64。默认为None - - **minlength** (int, 可选) - 输出Tensor的最小长度,如果大于输入Tensor的长度,则多出的位置补0。该值必须大于等于0。默认为0。 + - **minlength** (int, 可选) - 输出Tensor的最小长度,如果大于输入Tensor中的最大值,则多出的位置补0。该值必须大于等于0。默认为0。 - **name** (str,可选)- 具体用法请参见 :ref:`api_guide_Name` ,一般无需设置,默认值为None。 返回: