Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Hackathon 4th No.30】为 Paddle 新增 paddle.sparse.sum 稀疏 API #5846

Merged
merged 2 commits into from
May 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docs/api/paddle/sparse/sum_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.. _cn_api_paddle_sparse_sum:

sum
-------------------------------

.. py:function:: paddle.sparse.sum(x, axis=None, dtype=None, keepdim=False, name=None):

计算给定维度 :attr:`axis` 上稀疏张量 :attr:`x` 元素的和。
输入 :attr:`x` 必须为稀疏压缩格式( `SparseCooTensor` 或 `SparseCsrTensor`)。

等式为:

.. math::
out = sum(x, axis, dtype, keepdim)

参数
:::::::::
- **x** (Tensor) - 输入的 Tensor,数据类型为 bool、float16、float32、float64、int32 或 int64。
- **axis** (int|list|tuple,可选) - 沿着哪些维度进行求和操作。如果为 :attr:`None`,则对 :attr:`x` 的所有元素进行求和并返回一个只有一个元素的 Tensor;否则必须在 :math:`[-rank(x), rank(x))` 范围内。如果 :math:`axis[i] < 0`,则要减少的维度是 :math:`rank + axis[i]`。
- **dtype** (str,可选) - 输出 Tensor 的数据类型。默认值为 None,表示与输入 Tensor `x` 数据类型一致。
- **keepdim** (bool,可选) - 是否在输出 Tensor 中保留减少的维度。如果为 True,则结果 Tensor 的维数比 :attr:`x` 少一维,否则与 :attr:`x` 维数一致。默认值为 False。
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。

返回
::::::::::::

``Tensor``,在指定维度上进行求和运算的 Tensor。如果 `x.dtype='bool'` 或 `x.dtype='int32'`,则其数据类型为 `'int64'`,否则数据类型与 `x` 一致。


代码示例
:::::::::

COPY-FROM: paddle.sparse.sum