Repository navigation
Check VCS index bounds in one parallel pass - #69
Merged
Merged
Conversation
The constructor validated indices with indices.min() and indices.max(): two single-threaded passes over the whole array. On the IBD cohort file (3.6 billion int32 indices, 14.6 GB) that took ~1.2 s of every load, after the indices had already been decoded in parallel. Arrays of at least 2**20 signed-integer indices are now checked by one parallel numba pass; smaller or non-signed arrays keep the numpy path. Behavior is unchanged: an out-of-range index still raises before any narrowing. load_packed on the IBD file: 5.30 s -> 3.50 s. Claude-Session: https://claude.ai/code/session_01QBeTZy6BKKGKGJ7fwvkWgM
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
_VCSBase.__init__checks that every index is in[0, n_minor)withindices.min()andindices.max(): two single-threaded passes over the whole array. On large files that is a large share of the load time, spent after the indices were already decoded in parallel._ops.indices_in_bounds()checks arrays of at least 2²⁰ signed-integer indices with one parallel numba pass. Smaller or unsigned arrays keep the numpymin/maxpath.ValueErrorbefore the dtype narrowing, so it can't wrap silently.Results
full_IBD_cohort(1.19M cells, 3.6 billion indices = 14.6 GB ofint32), warm cache:min0.6 s +max0.6 s)load_packedWhat's left is mostly decoding the packed indices (~2.9 s).
Notes
uint16would halve the memory, but it would break theint32-minimum index policy from Fix/dtype narrowing #29 that the kernels rely on, so I left it out.Test plan
test_parallel_bounds_check: the parallel path agrees withmin/maxforint32/int64arrays with no bad index, a negative index, one too large, and2**31 - 1.test_large_out_of_bounds_index_raises: the constructor raises when the parallel check finds a bad index (VCSC and VCSR).ruff check,ruff format --check,codespellandty checkare clean; vulture, radon and xenon report nothing new.https://claude.ai/code/session_01QBeTZy6BKKGKGJ7fwvkWgM