Repository navigation
Conversation
smallest_index_dtype now returns uint16 for axes up to 2**16, falling back to int32/int64 beyond that. For a gene axis this halves the bytes of indices in memory (4 -> 2 B/nnz); the CUDA path already narrowed to uint16 on device. Measured on lupus (1.01B nnz, 32,738 genes), numba VCSR SpMV, 48 threads: int32 91.8 ms -> uint16 53.6 ms (1 thread: 1.05 s -> 0.91 s).
This branch has not been deployed
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.
What
smallest_index_dtype(n)now returnsuint16for axes up to 65,536 long and keepsint32/int64beyond that. The narrowing already happens in the array constructor (_base.py), so every path that builds an array (from_scipy,load_packed, ops, selections) picks it up. Files written with an olderindices_dtypeattribute are narrowed on read.Why
For single-cell data the minor axis is the gene axis (typically 20k to 60k), and
int32indices spend 4 B/nnz where 2 B suffice. The CUDA path already narrows touint16on device (_index_dtypein_cuda.py); this makes the host arrays match.Measurements
Lupus (1.01B nnz, 32,738 genes),
load_packed:indicesin memory: 4.04 GB (int32) to 2.02 GB (uint16)y = A @ x), best of 5:Output was identical. SpMV on one dataset and one machine, so treat the speedup as indicative.
Tests
tests/test_index_dtypes.py: updated the narrowing assertions fromint32touint16; boundary test now covers 1, 216, 216 + 1, int32 max, and int32 max + 1; added a test that indexn_minor - 1round-trips on both sides of 2**16 for CSR and CSC.tests/test_cuda.py371 passed on an RTX 4090;ruff checkandruff format --checkclean.Review notes
uint16is unsigned, so any code doing signed arithmetic onindices(for exampleindices - k) could wrap. The existing suite, including the property tests, found none, but I only searched by running the tests, not by auditing every kernel.int32, so behaviour there is unchanged.