Skip to content

Commit b11a648

Browse files
committed
Fix offset_from_ptr_to_memory for axis length 0
1 parent 9e93200 commit b11a648

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/dimension/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,10 @@ fn to_abs_slice(axis_len: usize, slice: Slice) -> (usize, usize, isize) {
410410
/// This function computes the offset from the logically first element to the first element in
411411
/// memory of the array. The result is always <= 0.
412412
pub fn offset_from_ptr_to_memory<D: Dimension>(dim: &D, strides: &D) -> isize {
413-
let offset = izip!(dim.slice(), strides.slice()).fold(0, |_offset, (d, s)| {
414-
if (*s as isize) < 0 {
415-
_offset + *s as isize * (*d as isize - 1)
413+
let offset = izip!(dim.slice(), strides.slice()).fold(0, |_offset, (&d, &s)| {
414+
let s = s as isize;
415+
if s < 0 && d > 1 {
416+
_offset + s * (d as isize - 1)
416417
} else {
417418
_offset
418419
}

0 commit comments

Comments
 (0)