From b25c2aa78cb9f8ba3a7b5ce0f8faed06e344851c Mon Sep 17 00:00:00 2001 From: Remco Bloemen Date: Thu, 19 Nov 2020 16:30:59 -0800 Subject: [PATCH] Fix inner size --- src/base/iter.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/base/iter.rs b/src/base/iter.rs index 75de156e..f744cf02 100644 --- a/src/base/iter.rs +++ b/src/base/iter.rs @@ -125,17 +125,19 @@ macro_rules! iterator { // element we want to return. self.size -= 1; + // Fetch strides + let inner_stride = self.strides.0.value(); + let outer_stride = self.strides.1.value(); + // Compute number of rows - let inner_size = self.inner_end.offset_from(self.inner_ptr) as usize; + // Division should be exact + let inner_raw_size = self.inner_end.offset_from(self.inner_ptr) as usize; + let inner_size = inner_raw_size / inner_stride; // Compute rows and cols remaining let outer_remaining = self.size / inner_size; let inner_remaining = self.size % inner_size; - // Fetch strides - let inner_stride = self.strides.0.value(); - let outer_stride = self.strides.1.value(); - // Compute pointer to last element let last = self.ptr.offset( (outer_remaining * outer_stride + inner_remaining * inner_stride)