File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,10 @@ pub fn stride_is_positive(stride: Ix) -> bool
20
20
/// Check whether the given dimension and strides are memory safe
21
21
/// to index the provided slice.
22
22
///
23
- /// To be safe, no stride may be negative, and the
23
+ /// To be safe, no stride may be negative, and the offset corresponding
24
+ /// to the last element of each dimension should be smaller than the length
25
+ /// of the slice. Also, the strides should not allow a same element to be
26
+ /// referenced by two different index.
24
27
pub fn can_index_slice < A , D : Dimension > ( data : & [ A ] ,
25
28
dim : & D ,
26
29
strides : & D
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ use ndarray::{
4
4
Array ,
5
5
RemoveAxis ,
6
6
arr2,
7
+ can_index_slice
7
8
} ;
8
9
9
10
#[ test]
@@ -36,3 +37,14 @@ fn dyn_dimension()
36
37
assert_eq ! ( z. shape( ) , & dim[ ..] ) ;
37
38
}
38
39
40
+ #[ test]
41
+ fn slice_indexing_uncommon_strides ( )
42
+ {
43
+ let v: Vec < _ > = ( 0 ..12 ) . collect ( ) ;
44
+ let dim = ( 2 , 3 , 2 ) ;
45
+ let strides = ( 1 , 2 , 6 ) ;
46
+ assert ! ( can_index_slice( & v, & dim, & strides) ) ;
47
+
48
+ let strides = ( 2 , 4 , 12 ) ;
49
+ assert ! ( !can_index_slice( & v, & dim, & strides) ) ;
50
+ }
You can’t perform that action at this time.
0 commit comments