Template Numerical Library: Overview of Graph Reduction Functions

Template Numerical Library version\ main:16b9213d5

Loading...
Searching...
No Matches
Overview of Graph Reduction Functions

This page provides an overview of all reduction functions available for graph operations, helping to understand the differences between variants and choose the right function for your needs.

# What is a Graph Vertex Reduction?

A graph vertex reduction performs a reduction operation (like sum, max, min) across the edges connected to each vertex of a graph, producing one result per vertex. This is a fundamental operation for:

- computation of vertex degrees,
- finding maximum/minimum edge weights connected to each vertex,
- vertex-level statistics and analysis
- algorithms like PageRank, centrality measures, etc.

# Function Categories

Graph reduction functions are organized along three independent axes:

## Const vs. Non-Const Graph

Category | Graph Modifiable? | Use Case
--- | --- | ---
Non-const | Yes | Can modify graph edges during reduction
Const | No | Read-only access to graph edges

Note: Each reduction function has both const and non-const overloads. The possibility to modify the graph during reduction allows to fuse reduction with traversing operations into a single pass. This can improve performance by reducing memory accesses.

## Basic vs. WithArgument Variants

Category | Tracks Position? | Use Case
--- | --- | ---
Basic | No | Only the reduced weight is needed (e.g., vertex sum, vertex max)
WithArgument | Yes | Need weight and target vertex index (e.g., max weight location)

## Scope and Conditional Variants (Which Vertices to Process)

Scope | Vertices Processed | Parameters
--- | --- | ---
All | All vertices | No range/array parameters
Range | Vertices [begin, end) | begin and end indices
Array | Specific vertices | Array of vertex indices
If | Vertices filtered by a condition | Process vertices based on vertex-level properties

# Complete Function Graph

All reduction functions follow this naming pattern: reduce[All]Vertices[WithArgument][If]

Each function has both const and non-const overloads (×2 multiplier).

## Basic Reduction Functions

Function | Scope | Conditional | Tracks Position | Overloads
--- | --- | --- | --- | ---
reduceAllVertices | All | No | No | const & non-const
reduceVertices (range) | Range [begin,end) | No | No | const & non-const
reduceVertices (array) | Vertex array | No | No | const & non-const
reduceAllVerticesIf | All | Yes | No | const & non-const
reduceVerticesIf | Range [begin,end) | Yes | No | const & non-const

## WithArgument Reduction Functions

Function | Scope | Conditional | Tracks Position | Overloads
--- | --- | --- | --- | ---
reduceAllVerticesWithArgument | All | No | Yes | const & non-const
reduceVerticesWithArgument (range) | Range [begin,end) | No | Yes | const & non-const
reduceVerticesWithArgument (array) | Vertex array | No | Yes | const & non-const
reduceAllVerticesWithArgumentIf | All | Yes | Yes | const & non-const
reduceVerticesWithArgumentIf | Range [begin,end) | Yes | Yes | const & non-const

# Common Parameters

All reduction functions share these common parameters:

- graph: The graph to reduce (const or non-const)
- fetch: Lambda that retrieves edge weights (see For Non-Const Graphs or For Const Graphs)
- reduction: Lambda or function object that combines weights (see Basic Reduction (Without Arguments) or Reduction With Argument (Position Tracking))
- store: Lambda that stores the reduction results (see Basic Store (Vertex Index Only) or variants)
- identity: The identity edge for the reduction (e.g., 0 for addition, 1 for multiplication)
- launchConfig: Configuration for parallel execution (optional)

Additional parameters:

- Scope variants: begin, end (range) or vertexIndexes (array)
- If variants: condition lambda for vertex filtering (see Condition Check)

# Related Pages

- Graph Reduction Lambda Function Reference - Detailed lambda function signatures
- Overview of Graph Traversal Functions - Graph traversal operations