1
+ use std:: marker:: PhantomData ;
2
+
1
3
use crate :: imp_prelude:: * ;
2
- use crate :: ElementsBase ;
3
- use crate :: ElementsBaseMut ;
4
+ use crate :: Baseiter ;
4
5
use crate :: IntoDimension ;
5
6
use crate :: { Layout , NdProducer } ;
6
7
@@ -9,6 +10,7 @@ impl_ndproducer! {
9
10
[ Clone => ' a, A , D : Clone ]
10
11
ExactChunks {
11
12
base,
13
+ life,
12
14
chunk,
13
15
inner_strides,
14
16
}
@@ -23,16 +25,14 @@ impl_ndproducer! {
23
25
}
24
26
}
25
27
26
- type BaseProducerRef < ' a , A , D > = ArrayView < ' a , A , D > ;
27
- type BaseProducerMut < ' a , A , D > = ArrayViewMut < ' a , A , D > ;
28
-
29
28
/// Exact chunks producer and iterable.
30
29
///
31
30
/// See [`.exact_chunks()`](ArrayBase::exact_chunks) for more
32
31
/// information.
33
32
//#[derive(Debug)]
34
33
pub struct ExactChunks < ' a , A , D > {
35
- base : BaseProducerRef < ' a , A , D > ,
34
+ base : RawArrayView < A , D > ,
35
+ life : PhantomData < & ' a A > ,
36
36
chunk : D ,
37
37
inner_strides : D ,
38
38
}
@@ -41,10 +41,11 @@ impl<'a, A, D: Dimension> ExactChunks<'a, A, D> {
41
41
/// Creates a new exact chunks producer.
42
42
///
43
43
/// **Panics** if any chunk dimension is zero
44
- pub ( crate ) fn new < E > ( mut a : ArrayView < ' a , A , D > , chunk : E ) -> Self
44
+ pub ( crate ) fn new < E > ( a : ArrayView < ' a , A , D > , chunk : E ) -> Self
45
45
where
46
46
E : IntoDimension < Dim = D > ,
47
47
{
48
+ let mut a = a. into_raw_view ( ) ;
48
49
let chunk = chunk. into_dimension ( ) ;
49
50
ndassert ! (
50
51
a. ndim( ) == chunk. ndim( ) ,
@@ -59,11 +60,12 @@ impl<'a, A, D: Dimension> ExactChunks<'a, A, D> {
59
60
for i in 0 ..a. ndim ( ) {
60
61
a. dim [ i] /= chunk[ i] ;
61
62
}
62
- let inner_strides = a. raw_strides ( ) ;
63
+ let inner_strides = a. strides . clone ( ) ;
63
64
a. strides *= & chunk;
64
65
65
66
ExactChunks {
66
67
base : a,
68
+ life : PhantomData ,
67
69
chunk,
68
70
inner_strides,
69
71
}
79
81
type IntoIter = ExactChunksIter < ' a , A , D > ;
80
82
fn into_iter ( self ) -> Self :: IntoIter {
81
83
ExactChunksIter {
82
- iter : self . base . into_elements_base ( ) ,
84
+ iter : self . base . into_base_iter ( ) ,
85
+ life : self . life ,
83
86
chunk : self . chunk ,
84
87
inner_strides : self . inner_strides ,
85
88
}
91
94
/// See [`.exact_chunks()`](ArrayBase::exact_chunks) for more
92
95
/// information.
93
96
pub struct ExactChunksIter < ' a , A , D > {
94
- iter : ElementsBase < ' a , A , D > ,
97
+ iter : Baseiter < A , D > ,
98
+ life : PhantomData < & ' a A > ,
95
99
chunk : D ,
96
100
inner_strides : D ,
97
101
}
@@ -101,6 +105,7 @@ impl_ndproducer! {
101
105
[ Clone => ]
102
106
ExactChunksMut {
103
107
base,
108
+ life,
104
109
chunk,
105
110
inner_strides,
106
111
}
@@ -122,7 +127,8 @@ impl_ndproducer! {
122
127
/// for more information.
123
128
//#[derive(Debug)]
124
129
pub struct ExactChunksMut < ' a , A , D > {
125
- base : BaseProducerMut < ' a , A , D > ,
130
+ base : RawArrayViewMut < A , D > ,
131
+ life : PhantomData < & ' a mut A > ,
126
132
chunk : D ,
127
133
inner_strides : D ,
128
134
}
@@ -131,10 +137,11 @@ impl<'a, A, D: Dimension> ExactChunksMut<'a, A, D> {
131
137
/// Creates a new exact chunks producer.
132
138
///
133
139
/// **Panics** if any chunk dimension is zero
134
- pub ( crate ) fn new < E > ( mut a : ArrayViewMut < ' a , A , D > , chunk : E ) -> Self
140
+ pub ( crate ) fn new < E > ( a : ArrayViewMut < ' a , A , D > , chunk : E ) -> Self
135
141
where
136
142
E : IntoDimension < Dim = D > ,
137
143
{
144
+ let mut a = a. into_raw_view_mut ( ) ;
138
145
let chunk = chunk. into_dimension ( ) ;
139
146
ndassert ! (
140
147
a. ndim( ) == chunk. ndim( ) ,
@@ -149,11 +156,12 @@ impl<'a, A, D: Dimension> ExactChunksMut<'a, A, D> {
149
156
for i in 0 ..a. ndim ( ) {
150
157
a. dim [ i] /= chunk[ i] ;
151
158
}
152
- let inner_strides = a. raw_strides ( ) ;
159
+ let inner_strides = a. strides . clone ( ) ;
153
160
a. strides *= & chunk;
154
161
155
162
ExactChunksMut {
156
163
base : a,
164
+ life : PhantomData ,
157
165
chunk,
158
166
inner_strides,
159
167
}
@@ -169,7 +177,8 @@ where
169
177
type IntoIter = ExactChunksIterMut < ' a , A , D > ;
170
178
fn into_iter ( self ) -> Self :: IntoIter {
171
179
ExactChunksIterMut {
172
- iter : self . base . into_elements_base ( ) ,
180
+ iter : self . base . into_base_iter ( ) ,
181
+ life : self . life ,
173
182
chunk : self . chunk ,
174
183
inner_strides : self . inner_strides ,
175
184
}
@@ -181,16 +190,17 @@ impl_iterator! {
181
190
[ Clone => ' a, A , D : Clone ]
182
191
ExactChunksIter {
183
192
iter,
193
+ life,
184
194
chunk,
185
195
inner_strides,
186
196
}
187
197
ExactChunksIter <' a, A , D > {
188
198
type Item = ArrayView <' a, A , D >;
189
199
190
- fn item( & mut self , elt ) {
200
+ fn item( & mut self , ptr ) {
191
201
unsafe {
192
202
ArrayView :: new_(
193
- elt ,
203
+ ptr ,
194
204
self . chunk. clone( ) ,
195
205
self . inner_strides. clone( ) )
196
206
}
@@ -209,10 +219,10 @@ impl_iterator! {
209
219
ExactChunksIterMut <' a, A , D > {
210
220
type Item = ArrayViewMut <' a, A , D >;
211
221
212
- fn item( & mut self , elt ) {
222
+ fn item( & mut self , ptr ) {
213
223
unsafe {
214
224
ArrayViewMut :: new_(
215
- elt ,
225
+ ptr ,
216
226
self . chunk. clone( ) ,
217
227
self . inner_strides. clone( ) )
218
228
}
@@ -225,7 +235,14 @@ impl_iterator! {
225
235
/// See [`.exact_chunks_mut()`](ArrayBase::exact_chunks_mut)
226
236
/// for more information.
227
237
pub struct ExactChunksIterMut < ' a , A , D > {
228
- iter : ElementsBaseMut < ' a , A , D > ,
238
+ iter : Baseiter < A , D > ,
239
+ life : PhantomData < & ' a mut A > ,
229
240
chunk : D ,
230
241
inner_strides : D ,
231
242
}
243
+
244
+ send_sync_read_only ! ( ExactChunks ) ;
245
+ send_sync_read_only ! ( ExactChunksIter ) ;
246
+
247
+ send_sync_read_write ! ( ExactChunksMut ) ;
248
+ send_sync_read_write ! ( ExactChunksIterMut ) ;
0 commit comments