@@ -13,6 +13,7 @@ use crate::error::ShapeError;
13
13
use crate :: extension:: nonnull:: nonnull_debug_checked_from_ptr;
14
14
use crate :: imp_prelude:: * ;
15
15
use crate :: { is_aligned, StrideShape } ;
16
+ use crate :: dimension:: offset_from_ptr_to_memory;
16
17
17
18
/// Methods for read-only array views.
18
19
impl < ' a , A , D > ArrayView < ' a , A , D >
55
56
let dim = shape. dim ;
56
57
dimension:: can_index_slice_with_strides ( xs, & dim, & shape. strides ) ?;
57
58
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) ) }
59
60
}
60
61
61
62
/// Create an `ArrayView<A, D>` from shape information and a raw pointer to
@@ -152,7 +153,7 @@ where
152
153
let dim = shape. dim ;
153
154
dimension:: can_index_slice_with_strides ( xs, & dim, & shape. strides ) ?;
154
155
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) ) }
156
157
}
157
158
158
159
/// Create an `ArrayViewMut<A, D>` from shape information and a
0 commit comments