Repository navigation
1/4: DelayedMatrix backend for layers past the dgCMatrix 2^31 limit - #10494
Open
BenjaminDEMAILLE wants to merge 1 commit into
Open
BenjaminDEMAILLE wants to merge 1 commit into
BenjaminDEMAILLE wants to merge 1 commit into
Conversation
This was referenced Sep 1, 2026
dgCMatrix indexes its non-zeros with 32-bit signed integers, so a matrix stops being representable at 2^31 - 1 entries: invalid class "dgCMatrix" object: 'i' slot is too large as.DelayedMatrix(x, ondisk = FALSE, file = NULL) wraps a matrix for use as a layer. In memory it gets an SVT_SparseMatrix seed, which stores non-zeros in a per-column tree rather than one flat index vector, so a layer can hold more than 2^31 of them and still serialize with saveRDS. On disk it is realized to a 10x-style TENxMatrix, whose indptr dataset is written with an 8-byte native HDF5 type; the test reads that type back rather than assuming it. Backend methods keep the standard pipeline block-wise, mirroring the existing IterableMatrix ones: LogNormalize.DelayedMatrix, VST.DelayedMatrix, .CalcN.DelayedMatrix, as.sparse.DelayedMatrix, and DelayedMatrix branches in RowMeanSparse, RowSumSparse and RowVarSparse. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
BenjaminDEMAILLE
force-pushed
the
feat/delayedmatrix-backend
branch
from
September 8, 2026 16:47
f681216 to
61acbe7
Compare
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.
First of a small series that replaces #10493, split so each piece can be reviewed on its own. Tracking issue with the order and the dependencies: #10498
This PR: 522 lines, 11 files, one idea. It is the whole of the 2^31 fix; the rest of the series is optional on top of it.
Why
dgCMatrixindexes its non-zeros with 32-bit signed integers, so a matrix stops being representable at2^31 - 1entries:Real data already crosses that line: the 10x GEM-X Flex 1M human K562 CRISPR aggregate has 4,355,024,689 non-zeros. Today BPCells is the only way past it, which means a dependency, a specific on-disk format, and objects that stop working when their directory moves.
What it adds
as.DelayedMatrix(x, ondisk = FALSE, file = NULL)wraps a matrix for use as a layer:SVT_SparseMatrixseed (SparseArray), which stores non-zeros in a per-column tree rather than one flat index vector, so a layer can hold more than2^31of them and still serialize withsaveRDS;ondisk = TRUE), it is realized to a 10x-styleTENxMatrix, whoseindptrdataset is written with an 8-byte native HDF5 type, so the same limit is lifted while the data stays out of memory.Backend methods keep the standard pipeline block-wise, mirroring the existing
IterableMatrixones:LogNormalize.DelayedMatrix,VST.DelayedMatrix,.CalcN.DelayedMatrix,as.sparse.DelayedMatrix, andDelayedMatrixbranches inRowMeanSparse,RowSumSparseandRowVarSparse.What it deliberately leaves out
Everything separable, so this PR stays one idea: the materialization warning, the SingleCellExperiment conversion, the
CheckMatrixSizereporter, and object portability are each their own PR in the series. None of them is needed for this one to be useful or correct.Verification
168 lines of tests, including: a matrix round-trips through the backend unchanged;
LogNormalizeandVSTgive the same numbers as thedgCMatrixpath; the on-disk form'sindptrtype is read back from the written file and asserted to be 8 bytes, rather than assumed. Full suite: 1209 passing, the only failures being the two pre-existingRead10X_Imageones that #10492 fixes.🤖 Generated with Claude Code