Skip to content

Commit 85e1813

Browse files
committed
DOC: Add comments to Indices' NdProducer implementation
It's quite counterintuitive what's happening, so add some comments.
1 parent 9cba023 commit 85e1813

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/indexes.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@ where
157157
private_impl! {}
158158
}
159159

160+
// How the NdProducer for Indices works.
161+
//
162+
// NdProducer allows for raw pointers (Ptr), strides (Stride) and the produced
163+
// item (Item).
164+
//
165+
// Instead of Ptr, there is `IndexPtr<D>` which is an index value, like [0, 0, 0]
166+
// for the three dimensional case.
167+
//
168+
// The stride is simply which axis is currently being incremented. The stride for axis 1, is 1.
169+
//
170+
// .stride_offset(stride, index) simply computes the new index along that axis, for example:
171+
// [0, 0, 0].stride_offset(1, 10) => [0, 10, 0] axis 1 is incremented by 10.
172+
//
173+
// .as_ref() converts the Ptr value to an Item. For example [0, 10, 0] => (0, 10, 0)
160174
impl<D: Dimension + Copy> NdProducer for Indices<D> {
161175
type Item = D::Pattern;
162176
type Dim = D;

0 commit comments

Comments
 (0)