Repository navigation
Return type-stable empty graphs from all samplers - #53
Merged
Merged
Conversation
sample_sparse() built an empty directed matrix from explicit zeros at 1:n and 1:d, which errors whenever n != d, breaking sample_sparse(), sample_igraph() and sample_tidygraph() on rectangular models with no sampled edges. Build empty matrices from zero-length index vectors instead, and make the empty undirected case symmetric like the non-empty one. sample_edgelist() returned a 0-row base matrix of doubles when no edges were sampled; it now returns a tibble with integer from/to columns, matching non-empty edgelists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the NEWS.md conflict with #57's bullets by keeping both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the NEWS.md conflict by keeping both sides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
alexpghayes
marked this pull request as ready for review
November 17, 2026 22:43
alexpghayes
added a commit
that referenced
this pull request
Nov 17, 2026
main now has #53, which returns an integer tibble for empty edgelists. Keep that tibble and collapse it with collapse_multiedges() when multigraph = FALSE, so empty graphs are type-stable either way. Keep both sides of the R/utils.R helpers and NEWS.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
sample_sparse()built an empty directed adjacency matrix from explicit zeros at1:nand1:d. Whenn != dthose index vectors have different lengths, sosparseMatrix()errors. That brokesample_sparse(),sample_igraph()andsample_tidygraph()on rectangular directed models whenever no edges are sampled.sample_edgelist()returned a 0-row basematrixof doubles, not a tibble of integers.sample_sparse()returned adgCMatrix, not a symmetricdsCMatrix.Fix
symmetric = TRUEfor undirected models.tibble(from = integer(0), to = integer(0))from the empty branch ofsample_edgelist.matrix().For undirected, directed square and directed rectangular models, with Poisson and Bernoulli edges,
sample_edgelist(),sample_sparse()andsample_igraph()now return the same class, column types and attributes for empty and non-empty graphs.Tests
tests/testthat/test-empty-graphs.Rcovers empty rectangular graphs in all three samplers and checks that classes and column types match between empty and non-empty graphs. Full suite: 199 passed, 0 failed.Merge note
#49 (
multigraphargument) also edits the empty branch ofsample_edgelist.matrix(). When resolving the conflict, keep the integer tibble from this PR and applycollapse_multiedges()to it whenmultigraph = FALSE.🤖 Generated with Claude Code