-
Notifications
You must be signed in to change notification settings - Fork 876
【Hackathon 6th No.17】为 Paddle 新增 sparse.mask_as API #6663
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) - 输入的稀疏张量,可以为 SparseCooTensor、SparseCsrTensor。当其为 SparseCsrTensor 时,应该是 2D 或 3D 的形式。 | ||
| - **name** (str,可选) - 具体用法请参见 :ref:`api_guide_Name`,一般无需设置,默认值为 None。 | ||
|
|
||
| 返回 | ||
| ::::::::: | ||
| SparseTensor: 其稀疏格式、dtype、shape 均与 `mask` 相同。 | ||
|
|
||
|
|
||
| 代码示例 | ||
| ::::::::: | ||
|
|
||
| COPY-FROM: paddle.sparse.mask_as |
32 changes: 32 additions & 0 deletions
32
..._convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sparse_mask.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| ``` | ||
|
|
||
| 两者功能一致,但调用方式不同,torch 通过 Tensor 类方法调用,而 paddle 是直接调用函数,具体如下: | ||
|
|
||
| ### 参数映射 | ||
|
|
||
| | PyTorch | PaddlePaddle | 备注 | | ||
| | ---------- | ------------ | ------------------------------------ | | ||
| | - | x | 输入的 DenseTensor。 | | ||
| | mask | mask | 掩码逻辑的 mask,参数完全一致。 | | ||
|
|
||
| ### 转写示例 | ||
|
|
||
| ```python | ||
| # torch 调用 Tensor 类方法 | ||
| x.sparse_mask(mask) | ||
|
|
||
| # paddle 直接调用函数 | ||
| paddle.sparse.mask_as(x, mask) | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
这个看下其他的
类方法转paddle方法的描述话术