in crates/ratchet-core/src/cpu/utils.rs [81:122]
fn next(&mut self) -> Option<Self::Item> {
let storage_index = match self.next_index {
None => return None,
Some(storage_index) => storage_index,
};
if self.block_size > 1 {
if self.block_step < self.block_size {
self.block_step += 1;
return Some(storage_index + self.block_step - 1);
} else {
self.block_step = 0;
}
}
let mut updated = false;
let mut next_storage_index = storage_index;
for ((multi_i, max_i), stride_i) in self
.multi_index
.iter_mut()
.zip(self.shape.iter())
.zip(self.strides.iter())
.rev()
{
let next_i = *multi_i + 1;
if next_i < *max_i {
*multi_i = next_i;
updated = true;
next_storage_index += *stride_i as usize;
break;
} else {
next_storage_index -= *multi_i * *stride_i as usize;
*multi_i = 0
}
}
self.next_index = if updated {
Some(next_storage_index)
} else {
None
};
Some(storage_index)
}