Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 25, 2026

Enables Stimulus autogeneration for 5 functions previously requiring manual wrappers: igraph_get_eid, igraph_community_voronoi, igraph_subisomorphic_lad, igraph_eigen_matrix, and igraph_eigen_matrix_symmetric.

Changes

New type definitions (tools/stimulus/types-RC.yaml, types-RR.yaml):

  • EDGE: Single edge index type (mirrors VERTEX pattern with 0→1-based index conversion)
    • Validates exactly one edge (not at least one)
  • EDGE_LENGTHS: Edge length vectors without automatic "weight" attribute lookup
  • VERTEXSET_LIST: Fixed to properly handle optional parameters
    • C code: Conditionally initialize and destroy only when not NULL
    • R code: Pass NULL instead of empty list when parameter is NULL

Function configurations (tools/stimulus/functions-R.yaml):

  • Removed IGNORE flags from all 5 functions
  • Added DEPS for igraph_get_eid to satisfy vertex parameter dependencies
  • Removed obsolete comment and PARAMS override for igraph_subisomorphic_lad

Generated code (src/rinterface.c, R/aaa-auto.R):

  • Updated with new *_impl functions for all 5 functions
  • Added custom validation for get_eid_impl: exactly one vertex required for from and to parameters
  • Added custom validation for subisomorphic_lad_impl: domains must be a list or NULL
  • Fixed critical bugs in subisomorphic_lad_impl:
    • C code no longer destroys uninitialized c_domains
    • R code properly passes NULL instead of empty list

Test coverage (tests/testthat/test-aaa-auto.R):

  • Added comprehensive tests for get_eid_impl with functionality checks (edge finding, directed/undirected behavior, parameter validation)
  • Added enhanced tests for community_voronoi_impl with structure validation (membership length, modularity, generators)
  • Added signature validation tests for subisomorphic_lad_impl, eigen_matrix_impl, and eigen_matrix_symmetric_impl
  • Added FIXME comments for functions requiring complex test setup

The 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.


  • By submitting this pull request, I assign the copyright of my contribution to The igraph development team.
Original prompt

This section details on the original issue you should resolve

<issue_title>Autogenerate remaining simple functions</issue_title>
<issue_description>- igraph_get_eid

  • igraph_community_voronoi
  • igraph_subisomorphic_lad
  • igraph_eigen_matrix
  • igraph_eigen_matrix_symmetric

Don't worry about other functions.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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.

Copilot AI and others added 4 commits January 25, 2026 15:16
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>
Copilot AI changed the title [WIP] Autogenerate remaining simple functions feat: autogenerate remaining simple functions Jan 25, 2026
Copilot AI requested a review from krlmlr January 25, 2026 15:37
CALL: '%I% - 1'
INCONV: |-
%I% <- as_igraph_es(%I1%, %I%)
if (length(%I%) == 0) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

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
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argument checks here?

Copy link
Contributor Author

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))
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copilot AI and others added 2 commits January 25, 2026 16:11
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Copilot AI requested a review from krlmlr January 25, 2026 16:15
@krlmlr krlmlr marked this pull request as ready for review January 25, 2026 16:17
Copilot AI review requested due to automatic review settings January 25, 2026 16:17
Copy link

Copilot AI left a 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
Comment on lines 17110 to 17111
igraph_vector_int_list_destroy(&c_domains);
IGRAPH_FINALLY_CLEAN(1);
Copy link

Copilot AI Jan 25, 2026

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.

Suggested change
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);
}

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

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),
Copy link

Copilot AI Jan 25, 2026

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.

Suggested change
lapply(domains, function(.x) .x - 1),
if (!is.null(domains)) lapply(domains, function(.x) .x - 1),

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

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.

@krlmlr
Copy link
Contributor

krlmlr commented Jan 25, 2026

@copilot: Merge main, resolving conflicts. Address unresolved feedback by adapting Stimulus.

Copy link
Contributor Author

Copilot AI commented Jan 25, 2026

@copilot: Merge main, resolving conflicts. Address unresolved feedback by adapting Stimulus.

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.

@krlmlr krlmlr enabled auto-merge (squash) January 25, 2026 18:45
@krlmlr krlmlr merged commit 42322f9 into main Jan 25, 2026
1 check passed
@krlmlr krlmlr deleted the copilot/autogenerate-simple-functions branch January 25, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autogenerate remaining simple functions

2 participants