python: Widen int scalars that do not fit in int64 to uint64 - #4365
Closed
vraj00222 wants to merge 2 commits into
Closed
python: Widen int scalars that do not fit in int64 to uint64#4365vraj00222 wants to merge 2 commits into
vraj00222 wants to merge 2 commits into
Conversation
zcbenz
reviewed
Aug 23, 2026
zcbenz
left a comment
Member
There was a problem hiding this comment.
While we do value-dependent semantics and we don't plan to change that any time soon, it is still possible that we would drop it some day (see discussion in #4334 (comment)), supporting uint64 would make it significant more difficult to move away from value-dependent semantics, and as far as I see there is no practical usage for this yet, so I'm closing this as won't fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
uint64 is a fully supported MLX dtype, but (
2^63…2^64−1) is unreachable from Python ints. so every path crashes for value >= 2^63 even when explicit dtype can hold the value :Solution (+63/−3, 4 files)
One shared inline helper in
utils.h(to_int64_or_uint64):nb::try_cast<int64_t>→ fallbackPyLong_AsUnsignedLongLong→ clean error naming the value. The three call sites use it; every current and future scalar consumer by default inherits the fix.question for maintainers: lists do NOT get uint64 widening ,NumPy promotes
[1, 2^63]to float64, silently losing precision above 2^53, which seems wrong to copy. let me know if that needs a follow up PR with same implementationAfter this change (all verified on this machine, cpu+gpu)
AI usage disclosure:
I used Claude Code to help me but every number and error string above is from a run on my machine, and I reviewed and understand every line in this diff.
☑️ I understand it is strictly prohibited to use AI to write PR description