!46253 Add pad operation when padding's length is equal to 0

Merge pull request !46253 from 冯一航/add_pad_null_padding_alpha
This commit is contained in:
i-robot 2022-12-01 07:27:56 +00:00 committed by Gitee
commit 0a56b65ca5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 4 additions and 2 deletions

View File

@ -3,7 +3,7 @@ mindspore.ops.pad
.. py:function:: mindspore.ops.pad(input_x, padding, mode='constant', value=None)
根据参数 `paddings` 对输入进行填充。
根据参数 `padding` 对输入进行填充。
参数:
- **input_x** (Tensor) - 输入Tensorshape为 :math:`(N, *)` :math:`*` 代表任意附加维度。

View File

@ -2399,7 +2399,7 @@ def _check_pad_inputs(padding):
def pad(input_x, padding, mode='constant', value=None):
r"""
Pads the input tensor according to the paddings.
Pads the input tensor according to the padding.
Args:
input_x (Tensor): Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of additional dimensions.
@ -2481,6 +2481,8 @@ def pad(input_x, padding, mode='constant', value=None):
"""
if not isinstance(input_x, Tensor):
raise TypeError(f"For 'pad', the type of 'input_x' must be Tensor, but got {type(input_x)}.")
if (isinstance(padding, (tuple, list)) and not padding) or (isinstance(padding, Tensor) and padding.shape == (0,)):
return input_x
if not isinstance(padding, Tensor):
_check_pad_inputs(padding)
padding = Tensor(padding)