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 index to directly index the array int linear_index = it.k; // k is the linear index into the array slap_SetElement(mat, it.i, it.j); // i and j are the cartesian indices }

Public Members

uint32_t len
uint16_t rows
uint16_t dx
uint16_t dy
uint16_t i
uint16_t j
uint16_t k
uint16_t index
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