@@ -235,11 +235,12 @@ where
235235/// units of `A` and in units of bytes between the least address and greatest
236236/// address accessible by moving along all axes does not exceed `isize::MAX`.
237237///
238- /// Warning: This function is sufficient to check the invariants of ArrayBase only
239- /// if the pointer to the first element of the array is chosen such that the element
240- /// with the smallest memory address is at the start of data. (In other words, the
241- /// pointer to the first element of the array must be computed using offset_from_ptr_to_memory
242- /// so that negative strides are correctly handled.)
238+ /// Warning: This function is sufficient to check the invariants of ArrayBase
239+ /// only if the pointer to the first element of the array is chosen such that
240+ /// the element with the smallest memory address is at the start of the
241+ /// allocation. (In other words, the pointer to the first element of the array
242+ /// must be computed using `offset_from_low_addr_ptr_to_logical_ptr` so that
243+ /// negative strides are correctly handled.)
243244pub ( crate ) fn can_index_slice < A , D : Dimension > (
244245 data : & [ A ] ,
245246 dim : & D ,
@@ -407,18 +408,19 @@ fn to_abs_slice(axis_len: usize, slice: Slice) -> (usize, usize, isize) {
407408 ( start, end, step)
408409}
409410
410- /// This function computes the offset from the logically first element to the first element in
411- /// memory of the array. The result is always <= 0 .
412- pub fn offset_from_ptr_to_memory < D : Dimension > ( dim : & D , strides : & D ) -> isize {
411+ /// Returns the offset from the lowest-address element to the logically first
412+ /// element .
413+ pub fn offset_from_low_addr_ptr_to_logical_ptr < D : Dimension > ( dim : & D , strides : & D ) -> usize {
413414 let offset = izip ! ( dim. slice( ) , strides. slice( ) ) . fold ( 0 , |_offset, ( & d, & s) | {
414415 let s = s as isize ;
415416 if s < 0 && d > 1 {
416- _offset + s * ( d as isize - 1 )
417+ _offset - s * ( d as isize - 1 )
417418 } else {
418419 _offset
419420 }
420421 } ) ;
421- offset
422+ debug_assert ! ( offset >= 0 ) ;
423+ offset as usize
422424}
423425
424426/// Modify dimension, stride and return data pointer offset
0 commit comments