feat: u32 -> integer64, rename scan_na to check, catch unsigned wraps#196
Merged
Conversation
Two related changes:
1. Materialize `ui32` buffers as `bit64::integer64` instead of base
`integer`. R's signed int32 has no headroom for `ui32` values
`>= 2^31` — they previously wrapped to negative integers silently
(except for the single `INT_MIN` bit pattern, which became `NA` and
was caught by `scan_na`). `integer64` has 53 bits of headroom over
`ui32`'s range, so every value round-trips losslessly.
2. Rename `scan_na` to `check`, broaden it to also detect unsigned wrap.
`check = TRUE` now errors when device -> host materialization yields:
* An `NA` for `i32` / `i64` (the `INT_MIN` / `INT64_MIN` NA collision),
* A negative `integer64` for `ui32` / `ui64` (which can only happen
for `ui64 >= 2^63`; `ui32` is now lossless and never produces one).
The C++ `raw_to_array_impl` template's "integer64 storage" path now
matches `uint32_t` alongside `int64_t` / `uint64_t`, and dispatch in
`impl_raw_to_array` routes `ui32` through REALSXP. The R-side
`value.PJRTArrayPromise` extends its integer64 classing list to include
`ui32`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ui32 is materialized as integer64 with 53 bits of headroom over the unsigned-32 range, so it can never produce a wrapped or NA value — the check for ui32 was dead. Limit the negativity check to ui64 only and update the docstring. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
No description provided.