Aurora int16 safety#213
Open
lgarrison wants to merge 3 commits into
Open
Conversation
For consistent [u]int16 semantics.
Just trying to get ahead of any downstream 16-bit int overflow/wraparound issues.
for more information, see https://pre-commit.ci
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.
Addressing the 16-bit int issue found by @deisenstein and @xjka (I think).
In Daniel's words:
Hopefully, this was "just" the behavior change between NumPy 1 & 2 when mixing int16 with Python int. That should be fixed here by requiring NumPy 2.
But there's always a more general risk of downstream users tripping on int overflow or unsigned int wraparound, especially in 16 bits. So here we're also promoting [u]int16 and uint32 to int32 (with an overflow check as needed). It costs a bit of memory, but is probably worth the safety.
I changed any "math-able" fields:
dist_binandcount(for healstruct), andmult,timestep,mult_sec,length(for maplog). I left bitflag fields alone. PID has 3 uint16 and is kind of a middle ground since the Lagrangian indices are technically math-able, but I left it unpromoted. I can imagine a lot of applications want to key off, or sort by, PID, and a 96-bit key would genuinely hurt performance.