Skip to content

fix: cut_at() handles partial dendrograms from cluster_leading_eigen()#2599

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-cutat-to-handle-partial-dendrograms
Draft

fix: cut_at() handles partial dendrograms from cluster_leading_eigen()#2599
Copilot wants to merge 3 commits intomainfrom
copilot/fix-cutat-to-handle-partial-dendrograms

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 27, 2026

cut_at() incorrectly used igraph_community_to_membership for all hierarchical community structures. cluster_leading_eigen() produces a partial dendrogram where merges entries are community IDs (not vertex IDs), requiring the dedicated igraph_le_community_to_membership function.

Changes

  • R/community.Rcut_at(): Detects leading eigenvector results via communities$algorithm == "leading eigenvector" and routes to le_community_to_membership_impl() with correct 0-based index conversion. Handles boundary warnings for out-of-range no and steps values.
  • tests/testthat/test-community.R: New test block covering no= and steps= variants, including warning behavior for out-of-range inputs.

Example

g <- make_full_graph(5) %du% make_full_graph(5) %du% make_full_graph(5)
g <- add_edges(g, c(1, 6, 1, 11, 6, 11))
lec <- cluster_leading_eigen(g)  # partial dendrogram: 3 communities, 2 merges

cut_at(lec, no = 3)  # previously returned garbage; now returns original 3-community membership
cut_at(lec, no = 2)  # merge 2 of 3 communities
cut_at(lec, no = 1)  # all vertices in one community
  • By submitting this pull request, I assign the copyright of my contribution to The igraph development team.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits March 27, 2026 17:23
Copilot AI changed the title [WIP] Fix cutat() to handle partial dendrograms for leading.eigenvector fix: cut_at() handles partial dendrograms from cluster_leading_eigen() Mar 27, 2026
Copilot AI requested a review from schochastics March 27, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cutat() should be able to handle partial dendrograms

2 participants