@@ -20,32 +20,15 @@ impl<'a, A, D: Dimension> Windows<'a, A, D> {
20
20
E : IntoDimension < Dim = D > ,
21
21
{
22
22
let window = window_size. into_dimension ( ) ;
23
- ndassert ! (
24
- a. ndim( ) == window. ndim( ) ,
25
- concat!(
26
- "Window dimension {} does not match array dimension {} " ,
27
- "(with array of shape {:?})"
28
- ) ,
29
- window. ndim( ) ,
30
- a. ndim( ) ,
31
- a. shape( )
32
- ) ;
33
- let mut size = a. dim ;
34
- for ( sz, & ws) in size. slice_mut ( ) . iter_mut ( ) . zip ( window. slice ( ) ) {
35
- assert_ne ! ( ws, 0 , "window-size must not be zero!" ) ;
36
- // cannot use std::cmp::max(0, ..) since arithmetic underflow panics
37
- * sz = if * sz < ws { 0 } else { * sz - ws + 1 } ;
38
- }
23
+ let ndim = window. ndim ( ) ;
39
24
40
- let window_strides = a. strides . clone ( ) ;
41
-
42
- unsafe {
43
- Windows {
44
- base : ArrayView :: new ( a. ptr , size, a. strides ) ,
45
- window,
46
- strides : window_strides,
47
- }
25
+ let mut unit_stride = D :: zeros ( ndim) ;
26
+ let stride_slice = unit_stride. slice_mut ( ) ;
27
+ for s in stride_slice. iter_mut ( ) {
28
+ * s = 1 ;
48
29
}
30
+
31
+ Windows :: new_with_stride ( a, window, unit_stride)
49
32
}
50
33
51
34
pub ( crate ) fn new_with_stride < E > ( a : ArrayView < ' a , A , D > , window_size : E , strides : E ) -> Self
0 commit comments