Skip to main content

Triangle Count All

UDTF: cugraph_triangle_count_all

Official cuGraph reference: C API

Count the number of three-vertex cycles incident to every vertex in the graph.

Quickstart​

The call below supplies edges from registered relation target_edges with canonical src and dst columns and may include weight.

SELECT *
FROM cugraph_triangle_count_all(
edges => (SELECT src, dst FROM target_edges)
);

Inputs​

Every relation is a named parenthesized SELECT subquery. The required edges role uses canonical src and dst columns. Every role, its canonical columns, and their accepted Arrow types are listed under Relation arguments. Metadata validation resolves registered tables named in its JSON request.

The vertex-ID types this UDTF accepts, the numeric types a per-call codebook maps to native ids, and its string-key limits are listed in Vertex ID support; the concrete call-specific schema comes from gpu_validate_call.

Arguments and options​

Relation arguments​

ArgumentRequiredColumnsDescription
edgesyes
  • src, dst: Int32, Int64, Utf8, LargeUtf8, Utf8View
  • weight (optional): Float32, Float64
  • edge_id (optional): Int32, Int64
edge relation with canonical src and dst columns, plus optional weight and edge_id columns; this algorithm ignores weight

Every edge_id column must have the integer type of src and dst; string-keyed graphs accept no edge IDs.

Graph construction options​

This UDTF requires directed=false (undirected/symmetric graph). All other graph construction options follow the shared defaults documented in Graph Construction Options.

Output​

ColumnTypeNullableDescription
vertexInt64|Utf8noVertex whose triangle participation is reported.
triangle_countInt64noNumber of triangles incident to the vertex.

These are generic descriptor schemas. Run gpu_validate_call to get the concrete, table-specific output schema.

Examples​

These examples run on the citation network demo dataset.

Which well-connected papers have the tightest citation neighborhoods?​

Treating citation edges as undirected, triangle_count gives the triangles touching each paper. The local clustering coefficient 2T / (d·(d−1)) divides that count by the possible pairs among its neighbors. This query ranks papers with at least 200 undirected neighbors by the share of those pairs that are connected in the same graph:

WITH tri AS (
SELECT vertex, triangle_count
FROM cugraph_triangle_count_all(edges => (SELECT src, dst FROM citation_edges))),
deg AS (
SELECT vertex, in_degree AS degree
FROM cugraph_degrees_all(
edges => (SELECT src, dst FROM citation_edges), directed => false))
SELECT p.title, p.year, d.degree, t.triangle_count,
ROUND(2.0 * t.triangle_count / (d.degree * (d.degree - 1)), 3) AS clustering
FROM tri t
JOIN deg d ON d.vertex = t.vertex
JOIN papers p ON p.paper_id = t.vertex
WHERE d.degree >= 200
ORDER BY clustering DESC
LIMIT 5;
titleyeardegreetriangle_countclustering
Out of Control: Overcoming Control-Flow Integrity20142083,1340.146
Discriminative Correlation Filter with Channel and Spatial Reliability20172112,6870.121
Signature Schemes with Bounded Leakage Resilience20092002,3800.120
Smashing the Gadgets: Hindering Return-Oriented Programming Using In-place Code Randomization20122012,4070.120
A Leakage-Resilient Mode of Operation20092102,5660.117

SIFT has 46 times as many triangles as the top row but a coefficient near 0.0005 because its 22,925 neighbors create far more possible pairs.