-
-
Notifications
You must be signed in to change notification settings - Fork 206
feat: autogenerate remaining simple functions #2551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
tools/stimulus/types-RR.yaml
Outdated
| CALL: '%I% - 1' | ||
| INCONV: |- | ||
| %I% <- as_igraph_es(%I1%, %I%) | ||
| if (length(%I%) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Length must be exactly one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in f613b2d. Changed validation from length(%I%) == 0 to length(%I%) != 1 for EDGE type.
tools/stimulus/functions-R.yaml
Outdated
| GRAPH graph, OUT GRAPH res, OUT VECTOR_INT vertex_color, OUT VECTOR_INT edge_color | ||
| GRAPH pattern, GRAPH target, OPTIONAL VERTEXSET_LIST domains, | ||
| OPTIONAL OUT BOOLEAN iso, OPTIONAL OUT INDEX_VECTOR map, | ||
| OPTIONAL OUT VECTOR_INT_LIST maps, BOOLEAN induced, INTEGER time_limit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we now drop this entirely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, removed in f613b2d. The cigraph definition already has the correct PARAMS.
R/aaa-auto.R
Outdated
| # Argument checks | ||
| ensure_igraph(graph) | ||
| from <- as_igraph_vs(graph, from) | ||
| if (length(from) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Length must be exactly one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in f613b2d. Added custom validation in get_eid_impl to check length(from) != 1 and length(to) != 1.
R/aaa-auto.R
Outdated
| R_igraph_subisomorphic_lad, | ||
| pattern, | ||
| target, | ||
| lapply(domains, function(.x) .x - 1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argument checks here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in f613b2d. Now validates that domains is either NULL or a list.
| local_igraph_options(print.id = FALSE) | ||
|
|
||
| # Just verify the function exists | ||
| expect_true(is.function(subisomorphic_lad_impl)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a few functionality tests or add a FIXME if difficult, here and for the other functions. Review the library source code if unsure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in f613b2d. For get_eid_impl and community_voronoi_impl, added functionality tests. For subisomorphic_lad_impl and eigen_matrix functions, added FIXME comments noting they need complex setup, along with signature validation tests.
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enables Stimulus autogeneration for 5 functions that previously required manual wrappers by adding new type definitions (EDGE, EDGE_LENGTHS) and removing IGNORE flags from function configurations. However, the generated code contains several critical bugs that must be fixed before merging.
Changes:
- Added EDGE and EDGE_LENGTHS type definitions to support single edge index parameters and edge length vectors without automatic "weight" attribute lookup
- Configured 5 functions for autogeneration with custom parameter validation where needed
- Generated C wrapper functions and R interface code for all 5 functions with tests
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/stimulus/types-RR.yaml | Added EDGE type (single edge index with exact-length validation) and EDGE_LENGTHS type (edge lengths without automatic weight attribute lookup) |
| tools/stimulus/types-RC.yaml | Added C-side definitions for EDGE and EDGE_LENGTHS types with proper conversion and cleanup logic |
| tools/stimulus/functions-R.yaml | Removed IGNORE flags and added custom validation for get_eid (single vertex requirement), subisomorphic_lad (domains must be list or NULL) |
| src/rinterface.c | Generated C wrapper functions for all 5 functions, but contains critical bugs in subisomorphic_lad (unconditional destroy) and eigen_matrix functions (missing parameter) |
| src/cpp11.cpp | Added function registrations for the 5 new C wrappers |
| R/aaa-auto.R | Generated R interface functions with parameter validation, but subisomorphic_lad_impl has critical bug with lapply on NULL |
| tests/testthat/test-aaa-auto.R | Added basic tests with functionality checks for get_eid and community_voronoi, signature validation for others |
| tests/testthat/_snaps/aaa-auto.md | Added test snapshots for the new functions |
src/rinterface.c
Outdated
| igraph_vector_int_list_destroy(&c_domains); | ||
| IGRAPH_FINALLY_CLEAN(1); |
Copilot
AI
Jan 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Destroying c_domains unconditionally is incorrect because it's only initialized when domains is not NULL (line 17093). This will cause undefined behavior when domains is NULL. The destroy call should be wrapped in a conditional check like if (!Rf_isNull(domains)) to match the initialization pattern.
| igraph_vector_int_list_destroy(&c_domains); | |
| IGRAPH_FINALLY_CLEAN(1); | |
| if (!Rf_isNull(domains)) { | |
| igraph_vector_int_list_destroy(&c_domains); | |
| IGRAPH_FINALLY_CLEAN(1); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 677edc3. Updated VERTEXSET_LIST type in types-RC.yaml to conditionally destroy c_domains only when it was initialized (wrapped in if (!Rf_isNull(domains))). This matches the pattern used in EDGESET_LIST and other optional list types.
R/aaa-auto.R
Outdated
| R_igraph_subisomorphic_lad, | ||
| pattern, | ||
| target, | ||
| lapply(domains, function(.x) .x - 1), |
Copilot
AI
Jan 25, 2026
•
edited by krlmlr
Loading
edited by krlmlr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When domains is NULL, lapply(domains, function(.x) .x - 1) will return an empty list instead of NULL. This means NULL will never be passed to the C code, which expects NULL to be passed when no domains are specified. The lapply call should be conditional: if (!is.null(domains)) lapply(domains, function(.x) .x - 1) else NULL or wrapped in a conditional block.
| lapply(domains, function(.x) .x - 1), | |
| if (!is.null(domains)) lapply(domains, function(.x) .x - 1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 677edc3. Updated VERTEXSET_LIST type in types-RR.yaml to conditionally apply lapply: if (!is.null(%I%)) lapply(%I%, function(.x) .x - 1) else NULL. This ensures NULL is properly passed to C code when domains is not specified.
|
@copilot: Merge main, resolving conflicts. Address unresolved feedback by adapting Stimulus. |
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Done in 677edc3. Merged main branch and fixed the VERTEXSET_LIST type definition in Stimulus to properly handle optional parameters - both C code initialization/destruction and R code NULL passing are now correct. |
Enables Stimulus autogeneration for 5 functions previously requiring manual wrappers:
igraph_get_eid,igraph_community_voronoi,igraph_subisomorphic_lad,igraph_eigen_matrix, andigraph_eigen_matrix_symmetric.Changes
New type definitions (tools/stimulus/types-RC.yaml, types-RR.yaml):
EDGE: Single edge index type (mirrorsVERTEXpattern with 0→1-based index conversion)EDGE_LENGTHS: Edge length vectors without automatic "weight" attribute lookupFunction configurations (tools/stimulus/functions-R.yaml):
IGNOREflags from all 5 functionsDEPSforigraph_get_eidto satisfy vertex parameter dependenciesigraph_subisomorphic_ladGenerated code (src/rinterface.c, R/aaa-auto.R):
*_implfunctions for all 5 functionsget_eid_impl: exactly one vertex required forfromandtoparameterssubisomorphic_lad_impl:domainsmust be a list or NULLsubisomorphic_lad_impl:Test coverage (tests/testthat/test-aaa-auto.R):
get_eid_implwith functionality checks (edge finding, directed/undirected behavior, parameter validation)community_voronoi_implwith structure validation (membership length, modularity, generators)subisomorphic_lad_impl,eigen_matrix_impl, andeigen_matrix_symmetric_implThe generated functions follow existing patterns for parameter validation, argument conversion, and return value handling. All critical bugs identified in code review have been fixed by adapting the Stimulus type system.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.