Skip to content

Commit

Permalink
Fix offset_from_ptr_to_memory for axis length 0
Browse files Browse the repository at this point in the history
  • Loading branch information
jturner314 authored and bluss committed May 13, 2021
1 parent b2873db commit 664ce2d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/dimension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,10 @@ fn to_abs_slice(axis_len: usize, slice: Slice) -> (usize, usize, isize) {
/// This function computes the offset from the logically first element to the first element in
/// memory of the array. The result is always <= 0.
pub fn offset_from_ptr_to_memory<D: Dimension>(dim: &D, strides: &D) -> isize {
let offset = izip!(dim.slice(), strides.slice()).fold(0, |_offset, (d, s)| {
if (*s as isize) < 0 {
_offset + *s as isize * (*d as isize - 1)
let offset = izip!(dim.slice(), strides.slice()).fold(0, |_offset, (&d, &s)| {
let s = s as isize;
if s < 0 && d > 1 {
_offset + s * (d as isize - 1)
} else {
_offset
}
Expand Down

0 comments on commit 664ce2d

Please sign in to comment.