-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[mypyc] Implement float abs primitive #9695
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm the result of
abs(0)
should be of typeint
. Can you check that the return value is not a float here? You may need to add a similar primitive forabs(integer)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is incorrect, it should be
abs(0.0) == 0.0
while the test will pass because it gets interpreted and0 == 0.0
returns True. It should be fixed now.I am not getting what do you mean by adding a primitive for integer? Do you mean a fixture function or a mypyc primitive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean a primitive for
abs(5)
, where the argument is an integer (inint_ops.py
). It can usePyNumber_Absolute
for now, similar to the float op, but the return type would beint
instead offloat
.I think that we may currently use the float variant of the primitive for integer arguments, which doesn't seem right. More generally, it's better for consistency to also cover the int case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I've verified that in the above case,
abs(0)
returns an int by checking the generated code and running the compiled module. So we wouldn't be using float variant for integer arguments.The integer version primitive would better be implemented in a separate PR as it requires casts from
CPyTagged
toPyObject *
if we are going to reusePyNumber_Absolute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing this in a separate PR sounds good. I was worried that we might use the float op with an int argument since int is compatible with float. Thanks for checking that this isn't a real issue.
Implementing the integer variant in IR build would be even better, since it would avoid boxing/unboxing. Can you create a follow-up issue about this (or PR)? However, using
PyNumber_Absolute
would be a reasonable intermediate step.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are on the same track. By building the op in irbuild, we can have a fast path for short ints.