Skip to content

eles.triangleCount(options?)

eles.triangleCount — Collection > Algorithms > Structural measures. Cytoscape.js signatures, parameters and return contract.

eles.triangleCount — Collection › Algorithms › Structural measures

Preview · Collection › Algorithms › Structural measures

Read in the complete API reference · All API members

// Triangle counting: per-node triangle counts, local clustering coefficients, and the collection's transitivity, read over the simple undirected graph (direction ignored, parallel edges collapsed, loops excluded)
eles.triangleCount(options?: TriangleCountOptions): AlgoRun<TriangleCountResult>

Triangle counting: per-node triangle counts, local clustering coefficients, and the collection's transitivity, read over the simple undirected graph (direction ignored, parallel edges collapsed, loops excluded). Async: returns a promise, and executor ('cpu' | 'gpu' | 'auto', default 'auto'; 'workers' runs the reference on one pool worker) picks where the counting runs — under 'auto' the GPU's A²∘A matmul is used only on graphs dense enough to beat the CPU's sparse walk (a mean degree of 64).

Parameters
NameDescription
options: TriangleCountOptions?

{ executor }

Fields of options
NameDescription
executor: AlgoExecutor?

where the run executes; see AlgoExecutor (default 'auto'). 'auto' routes to the GPU only on graphs dense enough that the O(n³) matmul beats the CPU's O(Σ deg²) sparse walk.

Returns AlgoRun<TriangleCountResult>

a promise of { triangles, clusteringCoefficient, totalTriangles, transitivity } — with cancel() on it: a pending run rejects with CancelledError, a 'cpu' run has already completed

Example

const run = eles.triangleCount({ executor: 'cpu' });
const result = await run;
console.log(result.totalTriangles); // 0

Example graph and handle setup

Throws

if executor is invalid; rejects if executor: 'gpu' is unavailable in this environment