fix: avoid memory overflow in ensure_no_na() for large sparse matrices with mode="lower" or mode="upper"#2627
Open
fix: avoid memory overflow in ensure_no_na() for large sparse matrices with mode="lower" or mode="upper"#2627
ensure_no_na() for large sparse matrices with mode="lower" or mode="upper"#2627Conversation
…with mode=lower/upper Agent-Logs-Url: https://github.com/igraph/rigraph/sessions/a080274e-c869-44c6-b491-4748a81bfc9c Co-authored-by: schochastics <17147355+schochastics@users.noreply.github.com>
Agent-Logs-Url: https://github.com/igraph/rigraph/sessions/a080274e-c869-44c6-b491-4748a81bfc9c Co-authored-by: schochastics <17147355+schochastics@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix memory overflow in ensure_no_na for large sparse matrices
fix: avoid memory overflow in May 6, 2026
ensure_no_na() for large sparse matrices with mode="lower" or mode="upper"
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.
ensure_no_na()calledupper.tri(x)/lower.tri(x)on sparse matrices, which materializes a full dense n×n logical matrix. For a ~1.2M×1.2M sparse matrix this requires ~5.4 TB of memory, crashing before any actual NA check occurs.Changes
R/utils-assert-args.R—ensure_no_na(): For sparse matrices, useMatrix::tril(x)@x/Matrix::triu(x)@xinstead of the dense triangular extraction. This operates in O(nnz) memory by working only on explicitly stored values.R/adjacency.R—graph.adjacency.sparse(): UseMatrix::nnzero(adjmatrix, na.counted = TRUE)for the early-exit empty-graph check. Without this, a sparse matrix with any NA stored values causesnnzero()to returnNA, which propagates into theifcondition and throws"missing value where TRUE/FALSE needed".tests/testthat/test-adjacency.R: Tests added for sparse matrices with NAs confined to one triangle — the relevant mode should error, the opposite mode should succeed.