Skip to content

Fix TypeInferenceMapper.map_floor_div with integral dtypes.#1000

Merged
inducer merged 2 commits intomainfrom
type_inf_mapper_uints_floor_div
Apr 10, 2026
Merged

Fix TypeInferenceMapper.map_floor_div with integral dtypes.#1000
inducer merged 2 commits intomainfrom
type_inf_mapper_uints_floor_div

Conversation

@kaushikcfd
Copy link
Copy Markdown
Collaborator

Closes #999.

Comment thread loopy/type_inference.py
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 thread loopy/type_inference.py
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')

@kaushikcfd kaushikcfd force-pushed the type_inf_mapper_uints_floor_div branch 3 times, most recently from 578f409 to e5dba39 Compare April 10, 2026 08:14
@inducer inducer force-pushed the type_inf_mapper_uints_floor_div branch from e5dba39 to 8ded8c0 Compare April 10, 2026 19:23
@inducer inducer enabled auto-merge (rebase) April 10, 2026 19:23
@inducer
Copy link
Copy Markdown
Owner

inducer commented Apr 10, 2026

Thx!

kaushikcfd and others added 2 commits April 10, 2026 14:26
Avoid div by 0 in TypeInferenceMapper.map_floor_div

basedpyright: add a cast.
@inducer inducer force-pushed the type_inf_mapper_uints_floor_div branch from 8ded8c0 to 7f63aea Compare April 10, 2026 19:26
@inducer inducer merged commit 7991909 into main Apr 10, 2026
17 checks passed
@inducer inducer deleted the type_inf_mapper_uints_floor_div branch April 10, 2026 20:00
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