Fix numeric type casting in binary matrix read operations#98
Merged
stevevanhooser merged 1 commit intomainfrom Apr 8, 2026
Merged
Conversation
In MATLAB, double * uint32 = uint32, which silently overflows when computing byte offsets for sample numbers exceeding ~2 billion (e.g., sample 15,321,600,000 in long Neuropixels recordings). Cast num_channels, bytes_per_sample, and channel skip counts to double so all intermediate arithmetic stays in double (53-bit mantissa, good to ~9e15). https://claude.ai/code/session_01VLnP9PJcs7q2zxej9aTJAe
Contributor
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #98 +/- ##
=======================================
Coverage 31.98% 31.98%
=======================================
Files 92 92
Lines 4656 4656
=======================================
Hits 1489 1489
Misses 3167 3167 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Summary
This PR adds explicit double-precision type casting to several numeric calculations in the binary matrix file reader to ensure consistent numeric handling and prevent potential type-related issues.
Key Changes
num_channelsto double in total samples calculationnum_channelsto double in bytes per sample calculationImplementation Details
The changes ensure that all intermediate calculations involving channel counts and skip offsets are performed using double-precision floating point arithmetic. This prevents potential issues with integer arithmetic overflow or type mismatches when dealing with large file sizes or channel counts. The explicit casting makes the numeric type handling more robust and consistent throughout the file reading operations.
https://claude.ai/code/session_01VLnP9PJcs7q2zxej9aTJAe