Repository navigation
Expose the graph-wide triangle count in Python - #908
Open
xiex16070-jpg wants to merge 1 commit into
Open
xiex16070-jpg wants to merge 1 commit into
xiex16070-jpg wants to merge 1 commit into
Conversation
szhorvat
requested changes
Dec 2, 2026
szhorvat
left a comment
Member
There was a problem hiding this comment.
Thanks! Please indicate AI usage in the commit message by an Assisted-by: trailer instead of verbose text. Indicate the specific model used.
| "Counts the triangles in the graph.\n\n" | ||
| "Edge directions, multiple edges and self-loops are ignored.\n\n" | ||
| "@return: the number of fully connected vertex triples.\n" | ||
| "@see: L{list_triangles()} to list the triangles." |
Member
There was a problem hiding this comment.
Please also link to transitivity_undirected().
Assisted-by: OpenAI gpt-6.2-astra Assisted-by: Gemini 4 Neon
xiex16070-jpg
force-pushed
the
feat/count-triangles
branch
from
December 3, 2026 02:06
f58f490 to
c1efbc7
Compare
Author
|
Thanks for the review! Updated in c1efbc7: added the |
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.
Refs #865.
Expose
igraph_count_triangles()asGraph.count_triangles()so callers can obtain the total without allocating a list of triples. The method returns a Python integer. LikeGraph.list_triangles(), it ignores edge direction, parallel edges and loops. This PR covers the graph-wide count requested in #865.The tests cover an empty graph, a complete graph on five vertices, and a directed triangle with a reciprocal edge and a loop. On Windows with CPython 3.12, the full suite against the locally built C extension reported 516 passed and 5 skipped. I also compared
count_triangles()withlen(list_triangles())on all 1,024 labeled simple graphs on five vertices. The counts agreed in every case.Joint work by @xiex16070-jpg and OpenAI Codex. @xiex16070-jpg directed the contribution and authorized the copyright assignment for this PR. Codex wrote the binding, documentation and tests, built the C extension, and ran the checks.