Skip to content

BUG: Fix integer / float scalar promotion#23079

Merged
mattip merged 3 commits intonumpy:mainfrom
seberg:fix-int-truediv-promotion
Jan 25, 2023
Merged

BUG: Fix integer / float scalar promotion#23079
mattip merged 3 commits intonumpy:mainfrom
seberg:fix-int-truediv-promotion

Conversation

@seberg
Copy link
Copy Markdown
Member

@seberg seberg commented Jan 24, 2023

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.
@seberg seberg added 00 - Bug 09 - Backport-Candidate PRs tagged should be backported labels Jan 24, 2023
@seberg seberg added this to the 1.24.2 release milestone Jan 24, 2023
@seberg seberg force-pushed the fix-int-truediv-promotion branch 5 times, most recently from 10fb61a to 5514ec4 Compare January 24, 2023 14:10
@seberg seberg force-pushed the fix-int-truediv-promotion branch 2 times, most recently from 47f42b2 to ec3e307 Compare January 24, 2023 14:34
@mattip
Copy link
Copy Markdown
Member

mattip commented Jan 25, 2023

Makes sense, and new tests pass. Thanks @seberg

@mattip mattip merged commit 9caf184 into numpy:main Jan 25, 2023
@charris charris removed this from the 1.24.2 release milestone Feb 2, 2023
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants