@@ -13,6 +13,7 @@ use crate::error::ShapeError;
1313use crate :: extension:: nonnull:: nonnull_debug_checked_from_ptr;
1414use crate :: imp_prelude:: * ;
1515use crate :: { is_aligned, StrideShape } ;
16+ use crate :: dimension:: offset_from_ptr_to_memory;
1617
1718/// Methods for read-only array views.
1819impl < ' a , A , D > ArrayView < ' a , A , D >
5556 let dim = shape. dim ;
5657 dimension:: can_index_slice_with_strides ( xs, & dim, & shape. strides ) ?;
5758 let strides = shape. strides . strides_for_dim ( & dim) ;
58- unsafe { Ok ( Self :: new_ ( xs. as_ptr ( ) , dim, strides) ) }
59+ unsafe { Ok ( Self :: new_ ( xs. as_ptr ( ) . offset ( - offset_from_ptr_to_memory ( & dim , & strides ) ) , dim, strides) ) }
5960 }
6061
6162 /// Create an `ArrayView<A, D>` from shape information and a raw pointer to
@@ -152,7 +153,7 @@ where
152153 let dim = shape. dim ;
153154 dimension:: can_index_slice_with_strides ( xs, & dim, & shape. strides ) ?;
154155 let strides = shape. strides . strides_for_dim ( & dim) ;
155- unsafe { Ok ( Self :: new_ ( xs. as_mut_ptr ( ) , dim, strides) ) }
156+ unsafe { Ok ( Self :: new_ ( xs. as_mut_ptr ( ) . offset ( - offset_from_ptr_to_memory ( & dim , & strides ) ) , dim, strides) ) }
156157 }
157158
158159 /// Create an `ArrayViewMut<A, D>` from shape information and a
0 commit comments