KEMBAR78
Export torch.newaxis=None for Python Array API/Numpy consistency by foxik · Pull Request #125026 · pytorch/pytorch · GitHub
Skip to content

Conversation

foxik
Copy link
Contributor

@foxik foxik commented Apr 26, 2024

Fixes #65307

For consistency with Python Array API (https://data-apis.org/array-api/latest/API_specification/constants.html) and NumPy (https://numpy.org/devdocs/reference/constants.html), I added torch.newaxis = None.

Note that the consistency is directly mentioned also in the __init__.py, right above the added export.

The torch.newaxis is also mentioned in #110636.

cc @mruberry @rgommers

@pytorch-bot
Copy link

pytorch-bot bot commented Apr 26, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/125026

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 203992f with merge base 3d8585e (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@mikaylagawarecki mikaylagawarecki added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Apr 26, 2024
Copy link
Contributor

@mikaylagawarecki mikaylagawarecki left a comment

Choose a reason for hiding this comment

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

Seems ok per this comment but adding @lezcano just in case

@lezcano lezcano added module: numpy Related to numpy support, and also numpy compatibility of our operators release notes: composability release notes category labels Apr 27, 2024
@lezcano
Copy link
Collaborator

lezcano commented Apr 27, 2024

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Apr 27, 2024
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 1 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@foxik
Copy link
Contributor Author

foxik commented Apr 27, 2024

Sorry, I did not run the lintrunner locally. Installing and running it now.

@foxik
Copy link
Contributor Author

foxik commented Apr 27, 2024

In the end I force-pushed the original commit to keep the merge history clean. The newaxis now also has a None type, hopefully that should be enough.

# NumPy consistency (https://numpy.org/devdocs/reference/constants.html)
from math import e , nan , inf , pi
__all__.extend(['e', 'pi', 'nan', 'inf'])
newaxis: None = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

The type of none is NoneType.

Also, no need to keep the history clean, as we squeeze all the commits on merge

Copy link
Collaborator

Choose a reason for hiding this comment

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

nvm

Note that None as a type hint is a special case and is replaced by type(None).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, no need to keep the history clean, as we squeeze all the commits on merge

Thanks, I did not know 🙏

@lezcano
Copy link
Collaborator

lezcano commented Apr 27, 2024

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

petrex pushed a commit to petrex/pytorch that referenced this pull request May 3, 2024
…orch#125026)

Fixes pytorch#65307

For consistency with Python Array API (https://data-apis.org/array-api/latest/API_specification/constants.html) and NumPy  (https://numpy.org/devdocs/reference/constants.html), I added `torch.newaxis = None`.

Note that the consistency is directly mentioned also in the `__init__.py`, right above the added export.

The `torch.newaxis` is also mentioned in pytorch#110636.

Pull Request resolved: pytorch#125026
Approved by: https://github.com/lezcano
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged module: numpy Related to numpy support, and also numpy compatibility of our operators open source release notes: composability release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[numpy] Add torch.newdim/torch.newaxis

5 participants