|
Template Numerical Library version\ main:8246197
|
This page provides an overview of all reduction functions available for segment operations, helping to understand the differences between variants and choose the right function for your needs.
The segment reduction functions are organized along three independent axes:
| Category | Tracks Position? | Use Case |
|---|---|---|
| Basic | No | Only the reduced value is needed (e.g., sum, product) |
| WithArgument | Yes | Need both the value and its position (e.g., max value and where it occurs) |
| Scope | Segments Processed | Parameters |
|---|---|---|
| All | All segments | No range/array parameters |
| Range | Segments [begin, end) | begin and end indices |
| Array | Specific segments | Array of segment indices |
| If | Segment condition | Process segments based on segment-level properties |
All reduction functions follow this naming pattern: reduce[Scope][WithArgument][If]
| Function | Scope | Conditional | Tracks Position |
|---|---|---|---|
| Segments_reduceAllSegments | All | No | No |
| Segments_reduceSegments_range (range) | Range [begin,end) | No | No |
| Segments_reduceSegments_with_segment_indices (array) | Segment array | No | No |
| Segments_reduceAllSegmentsIf | All | Yes | No |
| Segments_reduceSegmentsIf | Range [begin,end) | Yes | No |
| Function | Scope | Conditional | Tracks Position |
|---|---|---|---|
| Segments_reduceAllSegmentsWithArgument | All | No | Yes |
| Segments_reduceSegmentsWithArgument_range (range) | Range [begin,end) | No | Yes |
| Segments_reduceSegmentsWithArgument_with_segment_indices (array) | Segment array | No | Yes |
| Segments_reduceAllSegmentsWithArgumentIf | All | Yes | Yes |
| Segments_reduceSegmentsWithArgumentIf | Range [begin,end) | Yes | Yes |
All reduction functions share these common parameters:
Additional parameters for specific variants:
Performance considerations:
An empty segment is a segment of zero size, i.e. a segment that contains no elements to reduce over. Note that the segments know nothing about the meaning of their elements. A segment of nonzero size is not empty even if the fetch lambda returns the identity for all its elements (e.g., for the padding elements of sparse matrices).
The behavior depends on the reduction variant: