-
Notifications
You must be signed in to change notification settings - Fork 750
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 6th No.17】为 Paddle 新增 sparse.mask_as API #6663
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.. _cn_api_paddle_sparse_mask_as: | ||
|
||
mask_as | ||
------------------------------- | ||
|
||
.. py:function:: paddle.sparse.mask_as(x, mask, name=None) | ||
|
||
使用稀疏张量 `mask` 的索引过滤输入的稠密张量 `x`,并生成相应格式的稀疏张量。输入的 `x` 和 `mask` 必须具有相同的形状,且返回的稀疏张量具有与 `mask` 相同的索引,即使对应的索引中存在 `零` 值。 | ||
|
||
参数 | ||
::::::::: | ||
- **x** (DenseTensor) - 输入的 DenseTensor。数据类型为 float32,float64,int32,int64,complex64,complex128,int8,int16,float16。 | ||
- **mask** (SparseTensor) - 输入的稀疏张量,是一个 SparseTensor,可以为 SparseCooTensor、SparseCsrTensor。当其为 SparseCsrTensor 时,应该是 2D 或 3D 的形式。 | ||
- **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。 | ||
|
||
返回 | ||
::::::::: | ||
SparseTensor: 其稀疏格式、dtype、shape 均与 `mask` 相同。 | ||
|
||
|
||
代码示例 | ||
::::::::: | ||
|
||
COPY-FROM: paddle.sparse.mask_as |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## [ 参数完全一致 ] torch.Tensor.sparse_mask | ||
|
||
### [torch.Tensor.sparse_mask](https://pytorch.org/docs/stable/generated/torch.Tensor.sparse_mask.html) | ||
|
||
```python | ||
torch.Tensor.sparse_mask(mask) | ||
``` | ||
|
||
### [paddle.sparse.mask_as](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/sparse/mask_as_cn.html) | ||
|
||
```python | ||
paddle.sparse.mask_as(x, mask, name=None) | ||
``` | ||
|
||
两者功能一致,但使用方式不一致,前者可以直接访问方法,后者需要调用方法,具体如下: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 两者功能一致,但调用方式不同,torch通过Tensor类方法调用,而paddle是直接调用函数,具体如下: |
||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ---------- | ------------ | ------------------------------------ | | ||
| - | x | 输入的 DenseTensor。 | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个看下其他的 |
||
| mask | mask | 掩码逻辑的 mask,参数完全一致。 | | ||
|
||
### 转写示例 | ||
|
||
```python | ||
# torch 版本可以直接访问方法 | ||
# torch.sparse_mask(mask) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个要写成类方法: |
||
|
||
# Paddle 版本需要调用 | ||
paddle.sparse.mask_as(x, mask) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是一个 SparseTensor,
这句话多余去掉