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

Polish code for _getitem_impl_ #32868

Merged
merged 1 commit into from
May 14, 2021
Merged

Conversation

liym27
Copy link
Contributor

@liym27 liym27 commented May 12, 2021

PR types

Function optimization

PR changes

APIs

Describe

As the title

@paddle-bot-old
Copy link

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

@paddle-bot-old
Copy link

paddle-bot-old bot commented May 12, 2021

✅ This PR's description meets the template requirements!
Please wait for other CI results.

Copy link
Contributor

@zhiqiu zhiqiu left a comment

Choose a reason for hiding this comment

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

LGTM

@liym27 liym27 requested a review from zhhsplendid May 13, 2021 03:56
if contain_var(slice_step):
inputs['StridesTensorList'] = get_new_list_tensor(slice_step)
for i, dim in enumerate(slice_step):
infer_flags = list(1 for i in range(len(axes)))
Copy link
Member

Choose a reason for hiding this comment

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

Would you like to get a list of 1s and the length of the list is same as len(axes)?

If so, you could simply this line as:
infer_flags = list(1 for i in axes)

Copy link
Contributor Author

@liym27 liym27 May 13, 2021

Choose a reason for hiding this comment

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

Thanks. I use infer_flags = [1] * len(axes) to replace it for better readability.

inputs['StridesTensorList'] = get_new_list_tensor(slice_step)
for i, dim in enumerate(slice_step):
infer_flags = list(1 for i in range(len(axes)))
from .layers import utils
Copy link
Member

Choose a reason for hiding this comment

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

Can we import at the beginning of the python file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. Because it will cause a circular reference.

Copy link
Member

Choose a reason for hiding this comment

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

OK to me

}
if (use_strided_slice == True):
if use_strided_slice == True:
Copy link
Member

Choose a reason for hiding this comment

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

Can we write if use_strided_slice: ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Fixed.

@@ -948,7 +884,7 @@ def get_new_list_tensor(old_list):
attrs=attrs)

out = slice_out_var
elif use_strided_slice == True and len(slice_axis) > 0:
elif use_strided_slice == True and len(axes) > 0:
Copy link
Member

Choose a reason for hiding this comment

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

Can we replace elif use_strided_slice == True and len(axes) > 0 with elif use_strided_slice and len(axes) > 0 ?

Usually if a variable x is boolean, we write if x instead of if x is True or if x == True

Reference from official programming recommendations:
https://www.python.org/dev/peps/pep-0008/#programming-recommendations

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done.

Copy link
Member

@zhhsplendid zhhsplendid left a comment

Choose a reason for hiding this comment

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

LGTM

@liym27 liym27 merged commit 096b2f5 into PaddlePaddle:develop May 14, 2021
liym27 added a commit to liym27/Paddle that referenced this pull request Jun 11, 2021
lanxianghit pushed a commit that referenced this pull request Jun 15, 2021
…ist/Tensor/None/Ellipsis/bool (#33528)

* [cherry-pick 2.1] Polish code for _getitem_impl_ (#32868)

* [cherry-pick] Polish code for setitem and getitem (#32911)

* [slice getitem] Support getitem idx is Tensor or List (#33000)

* [getitem] Support index is None for getitem in static mode (#33001)

* [Static getitem] Support static Variable getitem for Ellipsis index (#32876)

* [static getitem]Support index is list bool for getitem in static mode (#33298)
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.

3 participants