@@ -17,6 +17,45 @@ pub fn stride_is_positive(stride: Ix) -> bool
17
17
( stride as Ixs ) > 0
18
18
}
19
19
20
+ /// Return the axis ordering corresponding to the fastest variation
21
+ ///
22
+ /// Assumes that no stride value appears twice. This cannot yield the correct
23
+ /// result the strides are not positive.
24
+ fn fastest_varying_order < D : Dimension > ( strides : & D ) -> D
25
+ {
26
+ let mut sorted = strides. clone ( ) ;
27
+ sorted. slice_mut ( ) . sort ( ) ;
28
+ let mut res = strides. clone ( ) ;
29
+ for ( ind, val) in sorted. slice ( ) . iter ( ) . enumerate ( ) {
30
+ res. slice_mut ( ) [ ind] = sorted. slice ( )
31
+ . binary_search ( val)
32
+ . expect ( "should be present" ) ;
33
+ }
34
+ res
35
+ }
36
+
37
+ /// Check whether the given `dim` and `stride` lead to overlapping indices
38
+ ///
39
+ /// There is overlap if, when iterating through the dimensions in the order
40
+ /// of maximum variation, the current stride is inferior to the sum of all
41
+ /// preceding strides multiplied by their corresponding dimensions.
42
+ ///
43
+ /// The current implementation assumes strides to be positive
44
+ pub fn dim_stride_overlap < D : Dimension > ( dim : & D , strides : & D ) -> bool
45
+ {
46
+ let order = fastest_varying_order ( strides) ;
47
+
48
+ let mut sum = 0 ;
49
+ for & ind in order. slice ( ) . iter ( ) {
50
+ let s = strides. slice ( ) [ ind] ;
51
+ if ( s as isize ) < sum {
52
+ return true ;
53
+ }
54
+ sum += stride_offset ( dim. slice ( ) [ ind] , s) ;
55
+ }
56
+ false
57
+ }
58
+
20
59
/// Check whether the given dimension and strides are memory safe
21
60
/// to index the provided slice.
22
61
///
0 commit comments