|
Template Numerical Library version\ main:4e6e2c1
|
This page provides an overview of all traversal functions available for matrix operations, helping to understand the differences between variants and choose the right function for your needs.
Matrix traversal operations apply a user-defined function to matrix elements or rows. Unlike reductions (which compute results), traversals are used for side effects:
Matrix traversal functions are organized along three main dimensions:
| Category | Matrix Modifiable? | Use Case |
|---|---|---|
| Non-const | Yes | Can modify matrix elements and structure |
| Const | No | Read-only access to matrix elements |
Note: Each traversal function has both const and non-const overloads.
| Category | Operates On | Lambda Parameter | Use Case |
|---|---|---|---|
| Element-wise (forElements, forAllElements) | Individual elements | Element indices & values | Operate on each element separately |
| Row-wise (forRows, forAllRows) | Whole rows | RowView object | Operate on rows as units |
Similar to other matrix operations, traversal functions have different scope and conditional variants.
| 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 |
These functions iterate over individual elements within matrix rows:
| Function | Rows Processed | Description | Overloads |
|---|---|---|---|
| forAllElements | All rows | Process all elements in all rows | const & non-const |
| forElements (range) | Rows [begin, end) | Process elements in row range | const & non-const |
| forElements (array) | Rows in array | Process elements in specified rows | const & non-const |
| forAllElementsIf | All rows | Row-level condition | const & non-const |
| forElementsIf | Rows [begin, end) | Row-level condition | const & non-const |
When to use:
These functions iterate over rows as whole units using RowView:
| Function | Rows Processed | Description | Overloads |
|---|---|---|---|
| forAllRows | All rows | Process all rows | const & non-const |
| forRows (range) | Rows [begin, end) | Process rows in range | const & non-const |
| forRows (array) | Rows in array | Process specified rows | const & non-const |
| forAllRowsIf | All rows | Row-level condition | const & non-const |
| forRowsIf | Rows [begin, end) | Row-level condition | const & non-const |
When to use:
All traversal functions share these common parameters:
Additional parameters:
Matrix type considerations:
Performance considerations: