|
Template Numerical Library version\ main:8246197
|
This page provides an overview of all reduction functions available for matrix operations, helping to understand the differences between variants and choose the right function for your needs.
A matrix row reduction performs a reduction operation (like sum, max, min) across the elements within each row of a matrix, producing one result per row. This is a fundamental operation for:
Matrix reduction functions are organized along three independent axes:
| Category | Matrix Modifiable? | Use Case |
|---|---|---|
| Non-const | Yes | Can modify matrix elements during reduction |
| Const | No | Read-only access to matrix elements |
Note: Each reduction function has both const and non-const overloads. The possibility to modify the matrix during reduction allows to fuse reduction with traversing operations into a single pass. This can improve performance by reducing memory accesses.
| Category | Tracks Position? | Use Case |
|---|---|---|
| Basic | No | Only the reduced value is needed (e.g., row sum, row max) |
| WithArgument | Yes | Need value and column position (e.g., max value location) |
| Scope | Rows Processed | Parameters |
|---|---|---|
| All | All rows | No range/array parameters |
| Range | Rows [begin, end) | begin and end indices |
| Array | Specific rows | Array of row indices |
| If | Rows filtered by a condition | Process rows based on row-level properties |
All reduction functions follow this naming pattern: reduce[Scope]Rows[WithArgument][If]
Each function has both const and non-const overloads (×2 multiplier).
| Function | Scope | Conditional | Tracks Position | Overloads |
|---|---|---|---|---|
| reduceAllRows | All | No | No | const & non-const |
| reduceRows (range) | Range [begin,end) | No | No | const & non-const |
| reduceRows (array) | Row array | No | No | const & non-const |
| reduceAllRowsIf | All | Yes | No | const & non-const |
| reduceRowsIf | Range [begin,end) | Yes | No | const & non-const |
| reduceRowsIf (array) | Row array | Yes | No | const & non-const |
| Function | Scope | Conditional | Tracks Position | Overloads |
|---|---|---|---|---|
| reduceAllRowsWithArgument | All | No | Yes | const & non-const |
| reduceRowsWithArgument (range) | Range [begin,end) | No | Yes | const & non-const |
| reduceRowsWithArgument (array) | Row array | No | Yes | const & non-const |
| reduceAllRowsWithArgumentIf | All | Yes | Yes | const & non-const |
| reduceRowsWithArgumentIf (range) | Range [begin,end) | Yes | Yes | const & non-const |
| reduceRowsWithArgumentIf (array) | Row array | Yes | Yes | const & non-const |
All variants with an array of row indexes accept either the whole array or an interval [begin, end) of its positions. The parameter indexOfRowIdx of the store lambda function is the position within the whole array for the unconditional variants and the rank of the row among the processed rows for the conditional variants.
All reduction functions share these common parameters:
Additional parameters:
An empty row is a row that contains no matrix elements to reduce over. This can happen, for example, with sparse matrices that have a row with zero non-zero elements (even if the row contains padding elements), with multidiagonal/tridiagonal matrices where all diagonals fall outside the valid column range for a given row, or with lambda matrices where all elements of a row are zero.
The behavior depends on the reduction variant:
Matrix type considerations: