Repository navigation
Conversation
`permute()`, `sample_correlated_gnp()` and `sample_correlated_gnp_pair()` now check a user-supplied permutation in R, before it reaches C. The C core's errors named no argument and differed with the input, and the correlated games silently accepted duplicates and values beyond the vertex count, the latter growing the result by extra vertices. The internal `check_permutation()` checks, in this order, that the permutation is numeric, has one element per vertex, has no missing values, holds whole numbers, stays within `1:n`, and has no duplicates. Each error names the argument and the offending positions or values. Integer and integer-valued double permutations give the same results as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JXnA76zWTu4ZD8BQCSYRpk
krlmlr
added this pull request to stack #2977
October 17, 2026 13:13
Contributor
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if 0834dd2 is merged into claude/series-land-review-brief:
|
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.
Stacked on #2973 (base
claude/series-land-review-brief), the top of stack 2977, and carrying only its own commit.Why
On CRAN igraph 2.3.4, and on
mainwith its C core 0.10.17,permute()leaves invalid permutations to the C core, whose messages name no argument and differ with the input. On a 4-vertex graph,c(-1, 2, 3, 4)gives "Invalid index in permutation vector",c(NA, 2, 3, 4)gives "The value nan is not representable as an integer", andc(1, 1, 2, 3)gives "Duplicate entry in permutation vector".sample_correlated_gnp()andsample_correlated_gnp_pair()are worse: they accept a duplicated permutation such asc(1, 1, 2, 3)silently, and a value beyond the vertex count such asc(1, 2, 3, 5)silently adds a fifth vertex to the result.The vendoring series makes this worse, because its R code inverts the permutation before the C check runs. There,
c(1.5, 2, 3, 4)silently becomes the identity,c(1, 2, 3, 5)reports "invalid permutation vector size", and negative or missing values surface as base R subscript errors ("only 0's may be mixed with negative subscripts", "NAs are not allowed in subscripted assignments"), inpermute()and in both games alike. The validator is valid withmain's engine, so it lands here first, and the series rebuild carries it in front of its own R changes.What
A new internal
check_permutation()inR/utils-assert-args.Rchecks, in this order, that the permutation is numeric, has length equal to the number of vertices, has no missing values, holds whole numbers, lies within1:n, and has no duplicates. Each failure is acli::cli_abort()error in the caller's name that names the argument and the offending positions or values, for example "permutationmust contain values between 1 and 4. ℹ Found 0 and 5 at positions 1 and 4." or "permutationmust not contain duplicate values. ℹ Found 1 more than once."permute()calls it first, after checking the graph.sample_correlated_gnp()andsample_correlated_gnp_pair()call it whenever a permutation is given, andNULLstill means no permutation.Valid permutations, integer or integer-valued double, give the same results as before. Against a build of the base branch, a set of seeded calls to all three functions (integer and double permutations, attributes, an empty graph, a canonical labeling, and
NULLfor the games) returns identical graphs and leaves the RNG in the same state. The one other change concerns invalid input:sample_correlated_gnp_pair()with a permutation and a malformednsuch asNAnow fails the length check, which shows thatn, instead of the C glue's scalar check.Tests
test-topology.Randtest-games.Rsnapshot every error withexpect_snapshot_igraph_error(), which keeps flavored builds stable. They also check that integer-valued doubles such asc(2, 1, 3, 4)give the unchanged result:permute()against a fixed edge list and against the integer permutation, and the two games againstpermute()withcorr = 1.testthat::test_local(filter = "topology|games|permute|correlated")passes, with no warnings on a second run, and so do the other files that callpermute()(operators, cliques, sgm, trees, conversion, structural-properties). The full suite passes too, apart from two tests that need the network or an installed package:graph_from_graphdb()cannot reach its URL from the sandbox, andtest-other.Rpasses once the built package is on the library path.LLM use: this PR was prepared with Claude Code (Claude Opus 5.5), at the maintainer's request.
Generated by Claude Code