Skip to content

BUG: Fix integer / float scalar promotion#23148

Merged
charris merged 3 commits intonumpy:maintenance/1.24.xfrom
charris:backport-23079
Feb 2, 2023
Merged

BUG: Fix integer / float scalar promotion#23148
charris merged 3 commits intonumpy:maintenance/1.24.xfrom
charris:backport-23079

Conversation

@charris
Copy link
Copy Markdown
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.

2 participants