Strides and the models of loops #
The parts of the specification of loops that name no element type, shared by all the arrays:
iterRange f lo hi xappliesf lo,f (lo + 1), …,f (hi - 1)tox, in this order, anditerRangeRev f lo hi xapplies them in the opposite order. They are the models of a loop whose stepjmaps its state byf j; therun_forInFromandrun_forInRevFromlemmas of each array'sInPlace.Tailrun a loop to them, anditerRange_prod_of_snddrops the array from a loop that only reads it.Strideis the affine index mapi ↦ off + inc * iof a strided vector, such as theincxof a BLAS routine, the diagonal of a matrix or a column of a matrix stored by columns, andStride.Fits s n sizesays that its firstnindices are distinct and less thansize. The arrays'modifyAtupdates the elements at any index map, soa.modifyAt s.idx lo hi gis the model of a strided loop.
A loop computes the USize copies of the offset and the stride once, before it starts:
toNat_idx_toUSize gives the Nat value of s.off.toUSize + s.inc.toUSize * j for a step j
of a stride that fits in an array in memory.
Iteration over a range #
iterRangeRev f lo hi x applies f (hi - 1), f (hi - 2), …, f lo to x, in this order: the
model of a loop from hi - 1 down to lo whose step j maps its state by f j. It is x when
hi ≤ lo.
Instances For
The step lo of iterRangeRev comes last.
iterRangeRev splits at any mid between its bounds.
iterRangeRev depends only on the steps in its range.
A property that each step in the range preserves holds after iterRangeRev.
A map φ that takes each step f i to g i takes iterRangeRev f to iterRangeRev g.
A loop whose steps i map its variable by g i and leave the array a alone, such as a loop that
only reads, maps (b, a) to (iterRange g lo hi b, a).
Strides #
The indices off + inc * i of a strided vector, such as the incx of a BLAS routine, the diagonal
of a matrix or a column of a matrix stored by columns. It is plain data: Stride.Fits s n size
says that its first n indices are distinct and less than size.
- off : Nat
The index of the step
0. - inc : Nat
The distance between the indices of two consecutive steps.
Instances For
Instances For
The stride from the step k of s on, with the same increment.
Instances For
The first n steps of s are at distinct indices, less than size: the stride is positive,
unless there is at most one step, and the index of the last step is less than size.
The stride is positive, unless there is at most one step.
The index of the last step is less than
size.
Instances For
The USize index s.off.toUSize + s.inc.toUSize * i of a step i < n of a stride that fits in
an array of USize size, as every array in memory has, doesn't wrap around.
Disjoint strides #
Two strides with the same increment, whose offsets differ by less than it, never meet: for example two rows of a matrix stored by columns, whose increment is the leading dimension.