Skip to content

Fix TypeInferenceMapper.map_floor_div with integral dtypes.#1000

Open
kaushikcfd wants to merge 3 commits intomainfrom
type_inf_mapper_uints_floor_div
Open

Fix TypeInferenceMapper.map_floor_div with integral dtypes.#1000
kaushikcfd wants to merge 3 commits intomainfrom
type_inf_mapper_uints_floor_div

Conversation

@kaushikcfd
Copy link
Copy Markdown
Collaborator

Closes #999.

@kaushikcfd kaushikcfd force-pushed the type_inf_mapper_uints_floor_div branch from b8124e1 to 8ee1b9f Compare March 30, 2026 15:55
@kaushikcfd kaushikcfd requested a review from inducer March 30, 2026 15:58
else expr.numerator
)
denom = (
np.empty(0, dtype=d_dtype)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Isn't there a risk here of using a zero denominator in a carried-out calculation?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

What do you think of: 3cdca14?

Comment on lines +443 to +444
if not is_integer(expr.numerator)
else expr.numerator
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Numpy no longer does value-dependent types AFAIK (as of 2.0), so IMO this if isn't necessary. Just use 1/1 unconditionally.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't think we can avoid the conditional.

>>> ary_u64 = np.empty(0, dtype=np.uint64)
>>> (ary_u64 // 2).dtype
dtype('uint64')
>>> (ary_u64 // np.empty(0, np.int32)).dtype  # if we don't use the if.
dtype('float64')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeInferenceMapper.map_floor_div returns incorrect results with np.uint64

2 participants