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

Support getitem by ellipsis index in dynamic mode #34267

Merged
merged 4 commits into from
Jul 22, 2021

Conversation

zyfncg
Copy link
Contributor

@zyfncg zyfncg commented Jul 20, 2021

PR types

New features

PR changes

APIs

Describe

Support getitem by ellipsis index in dynamic mode

Example:

x = paddle.to_tensor(np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]).astype(np.float32))
y = x[..., 0]

@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

@wxzylforever wxzylforever 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

@hbwx24 hbwx24 left a comment

Choose a reason for hiding this comment

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

LGTM

continue;
}
slice_axes->push_back(dim);
slice_starts->push_back(start);
slice_ends->push_back(end);
slice_strides->push_back(step);
dim++;
} else if (slice_item == Py_Ellipsis) {
dim += rank - specified_dims;
Copy link
Contributor

@chenwhql chenwhql Jul 21, 2021

Choose a reason for hiding this comment

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

may be adding else branch is better, we can move the error hint into else branch, such as

} else {
    PADDLE_THROW(
        platform::errors::InvalidArgument(
                  "Currently, VarBase.__getitem__() only allows "
                  "indexing by Integers, Slices, Ellipsis, and tuples of "
                  "these types, but received %s in %dth slice item",
                  std::string(Py_TYPE(slice_item)->tp_name), i + 1));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

var_int = paddle.to_tensor(np_int_value)

# test for float32
var = [
Copy link
Contributor

Choose a reason for hiding this comment

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

duplicate code? put the duplicate code in another func?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

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

@chenwhql chenwhql merged commit 82339ed into PaddlePaddle:develop Jul 22, 2021
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