iterator.h
-
struct MatrixIterator
A struct for conveniently and efficiently iterating over strided matrices.
This iterator provides the user to access the elements via either the linear or cartesian indices.
Note that this will always iterate linearly over the underlying memory, so is invariant to whether or not the matrix is transposed.
Note that if the matrix data is dense (there are no gaps in the memory), it is most efficient to iterate directly over the elements of the underlying array.
Example
for (MatrixIterator it = slap_Iterator(mat); !slap_IsFinished(&it); slap_Step(&it)) { sfloat value = mat.data[it.index]; // Use
indexto directly index the array int linear_index = it.k; //kis the linear index into the array slap_SetElement(mat, it.i, it.j); //iandjare the cartesian indices }
-
MatrixIterator slap_Iterator(Matrix mat)
Create an iterator at the beginning of the matrix.
- Parameters:
mat – A valid dense or strided matrix
- Returns:
A MatrixIterator for the matrix
-
void slap_Step(MatrixIterator *iterator)
Progress the iterator by one index. Updates the iterator-in-place.
- Parameters:
iterator – A valid iterator
-
static inline bool slap_IsFinished(const MatrixIterator *iterator)
Checks if the iterator is past the end of the matrix.
- Parameters:
iterator – A valid iterator
- Returns:
true if the iterator refers to a point past the end of the matrix