Skip to content

Conversation

@zyfncg
Copy link
Contributor

@zyfncg zyfncg commented Nov 17, 2021

PR types

New features

PR changes

OPs

Describe

Slice索引增加了对切片部分维度为0的功能支持,即允许切片索引结果为空(之前会进行检测并报错)。

Example:

Before this PR:

>>> x = paddle.to_tensor([[1, 2, 3], [4, 5, 6]])
>>> print(x[:, 0:0])
#  ValueError: (InvalidArgument) When step > 0, end should be greater than start, but received end = 0, start = 0.
#  [Hint: Expected end > start, but received end:0 <= start:0.]

Now:

>>> x = paddle.to_tensor([[1, 2, 3], [4, 5, 6]])
>>> print(x[:, 0:0])
# Tensor(shape=[2, 0], dtype=int64, place=CUDAPlace(0), stop_gradient=True,
#              [[],
#               []])

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Copy link
Contributor

@chenwhql chenwhql left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@MingMingShangTian MingMingShangTian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zyfncg zyfncg merged commit e788c7b into PaddlePaddle:develop Nov 22, 2021
@zyfncg zyfncg deleted the slice_zero_shape branch November 22, 2021 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants