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

BUG: Fix integer / float scalar promotion #23148

Merged
merged 3 commits into from Feb 2, 2023

Conversation

charris
Copy link
Member

@charris charris commented Feb 2, 2023

Backport of #23079.

Integer true division converted the other type directly to the output. This is correct if both operands are integers, but since the output of integer division is double precision, it is incorrect when the other operand is a float32 or float16.

The solution is that we must convert to the same type (as always) and only the output type is adjusted, but not the inputs.
This means that integer / float will correctly defer to the float which leads to correct promotion.


This fixes an issue found by CuPy in cupy/cupy#7340 (comment)

Integer true division converted the other type directly to the output.
This is correct if both operands are integers, but since the output
of integer division is double precision, it is incorrect when the
other operand is a float32 or float16.

The solution is that we must convert to the same type (as always)
and only the output type is adjusted, but not the inputs.
This means that `integer / float` will correctly defer to the float
which leads to correct promotion.
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels Feb 2, 2023
@charris charris added this to the 1.24.2 release milestone Feb 2, 2023
@charris charris merged commit 8dfa47d into numpy:maintenance/1.24.x Feb 2, 2023
@charris charris deleted the backport-23079 branch February 2, 2023 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 08 - Backport Used to tag backport PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants