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 py-boolean in indexing #58856

Merged
merged 4 commits into from
Nov 15, 2023

Conversation

zoooo0820
Copy link
Contributor

@zoooo0820 zoooo0820 commented Nov 9, 2023

PR types

New features

PR changes

APIs

Description

Pcard-66985

Support single py-boolean in indexing. The tensor will firstly promote the corresponding dimension, and then the Bool value will be treated as advanced-index.

>>> x = paddle.randn((4,3,2))
>>> x
Tensor(shape=[4, 3, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
       [[[ 0.47239113,  0.56600982],
         [-2.01862693,  1.10056722],
         [-0.65087581,  0.76055008]],

        [[ 0.11856326,  1.35000455],
         [ 0.32557386,  0.86446381],
         [-0.76793766, -0.04744434]],

        [[-0.66354942,  2.03688121],
         [ 1.28386986, -0.19520277],
         [-1.12073815,  1.21294630]],

        [[-1.17965138, -0.35202494],
         [ 1.22328508,  1.34666431],
         [-0.49775603,  0.60246438]]])
>>> x[False]
Tensor(shape=[0, 4, 3, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
       [])

>>> x[True]
Tensor(shape=[1, 4, 3, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
       [[[[ 0.47239113,  0.56600982],
          [-2.01862693,  1.10056722],
          [-0.65087581,  0.76055008]],

         [[ 0.11856326,  1.35000455],
          [ 0.32557386,  0.86446381],
          [-0.76793766, -0.04744434]],

         [[-0.66354942,  2.03688121],
          [ 1.28386986, -0.19520277],
          [-1.12073815,  1.21294630]],

         [[-1.17965138, -0.35202494],
          [ 1.22328508,  1.34666431],
          [-0.49775603,  0.60246438]]]])

@zoooo0820 zoooo0820 changed the title Fix py bool indexing Support py-boolean in indexing Nov 9, 2023
Copy link
Contributor

@jeff41404 jeff41404 left a comment

Choose a reason for hiding this comment

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

LGTM

@jeff41404 jeff41404 merged commit 0b4fd0f into PaddlePaddle:develop Nov 15, 2023
28 checks passed
@zoooo0820 zoooo0820 deleted the fix_py_bool_indexing branch November 15, 2023 03:55
SecretXV pushed a commit to SecretXV/Paddle that referenced this pull request Nov 28, 2023
* fix single Py_Bool indexing and add unittest case

* fix ci error

* complex32 -> complex128
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.

None yet

2 participants