1+ use std:: marker:: PhantomData ;
2+
13use crate :: imp_prelude:: * ;
2- use crate :: ElementsBase ;
3- use crate :: ElementsBaseMut ;
4+ use crate :: Baseiter ;
45use crate :: IntoDimension ;
56use crate :: { Layout , NdProducer } ;
67
@@ -9,6 +10,7 @@ impl_ndproducer! {
910 [ Clone => ' a, A , D : Clone ]
1011 ExactChunks {
1112 base,
13+ life,
1214 chunk,
1315 inner_strides,
1416 }
@@ -23,16 +25,14 @@ impl_ndproducer! {
2325 }
2426}
2527
26- type BaseProducerRef < ' a , A , D > = ArrayView < ' a , A , D > ;
27- type BaseProducerMut < ' a , A , D > = ArrayViewMut < ' a , A , D > ;
28-
2928/// Exact chunks producer and iterable.
3029///
3130/// See [`.exact_chunks()`](ArrayBase::exact_chunks) for more
3231/// information.
3332//#[derive(Debug)]
3433pub struct ExactChunks < ' a , A , D > {
35- base : BaseProducerRef < ' a , A , D > ,
34+ base : RawArrayView < A , D > ,
35+ life : PhantomData < & ' a A > ,
3636 chunk : D ,
3737 inner_strides : D ,
3838}
@@ -41,10 +41,11 @@ impl<'a, A, D: Dimension> ExactChunks<'a, A, D> {
4141 /// Creates a new exact chunks producer.
4242 ///
4343 /// **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
4545 where
4646 E : IntoDimension < Dim = D > ,
4747 {
48+ let mut a = a. into_raw_view ( ) ;
4849 let chunk = chunk. into_dimension ( ) ;
4950 ndassert ! (
5051 a. ndim( ) == chunk. ndim( ) ,
@@ -59,11 +60,12 @@ impl<'a, A, D: Dimension> ExactChunks<'a, A, D> {
5960 for i in 0 ..a. ndim ( ) {
6061 a. dim [ i] /= chunk[ i] ;
6162 }
62- let inner_strides = a. raw_strides ( ) ;
63+ let inner_strides = a. strides . clone ( ) ;
6364 a. strides *= & chunk;
6465
6566 ExactChunks {
6667 base : a,
68+ life : PhantomData ,
6769 chunk,
6870 inner_strides,
6971 }
7981 type IntoIter = ExactChunksIter < ' a , A , D > ;
8082 fn into_iter ( self ) -> Self :: IntoIter {
8183 ExactChunksIter {
82- iter : self . base . into_elements_base ( ) ,
84+ iter : self . base . into_base_iter ( ) ,
85+ life : self . life ,
8386 chunk : self . chunk ,
8487 inner_strides : self . inner_strides ,
8588 }
9194/// See [`.exact_chunks()`](ArrayBase::exact_chunks) for more
9295/// information.
9396pub struct ExactChunksIter < ' a , A , D > {
94- iter : ElementsBase < ' a , A , D > ,
97+ iter : Baseiter < A , D > ,
98+ life : PhantomData < & ' a A > ,
9599 chunk : D ,
96100 inner_strides : D ,
97101}
@@ -101,6 +105,7 @@ impl_ndproducer! {
101105 [ Clone => ]
102106 ExactChunksMut {
103107 base,
108+ life,
104109 chunk,
105110 inner_strides,
106111 }
@@ -122,7 +127,8 @@ impl_ndproducer! {
122127/// for more information.
123128//#[derive(Debug)]
124129pub struct ExactChunksMut < ' a , A , D > {
125- base : BaseProducerMut < ' a , A , D > ,
130+ base : RawArrayViewMut < A , D > ,
131+ life : PhantomData < & ' a mut A > ,
126132 chunk : D ,
127133 inner_strides : D ,
128134}
@@ -131,10 +137,11 @@ impl<'a, A, D: Dimension> ExactChunksMut<'a, A, D> {
131137 /// Creates a new exact chunks producer.
132138 ///
133139 /// **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
135141 where
136142 E : IntoDimension < Dim = D > ,
137143 {
144+ let mut a = a. into_raw_view_mut ( ) ;
138145 let chunk = chunk. into_dimension ( ) ;
139146 ndassert ! (
140147 a. ndim( ) == chunk. ndim( ) ,
@@ -149,11 +156,12 @@ impl<'a, A, D: Dimension> ExactChunksMut<'a, A, D> {
149156 for i in 0 ..a. ndim ( ) {
150157 a. dim [ i] /= chunk[ i] ;
151158 }
152- let inner_strides = a. raw_strides ( ) ;
159+ let inner_strides = a. strides . clone ( ) ;
153160 a. strides *= & chunk;
154161
155162 ExactChunksMut {
156163 base : a,
164+ life : PhantomData ,
157165 chunk,
158166 inner_strides,
159167 }
@@ -169,7 +177,8 @@ where
169177 type IntoIter = ExactChunksIterMut < ' a , A , D > ;
170178 fn into_iter ( self ) -> Self :: IntoIter {
171179 ExactChunksIterMut {
172- iter : self . base . into_elements_base ( ) ,
180+ iter : self . base . into_base_iter ( ) ,
181+ life : self . life ,
173182 chunk : self . chunk ,
174183 inner_strides : self . inner_strides ,
175184 }
@@ -181,16 +190,17 @@ impl_iterator! {
181190 [ Clone => ' a, A , D : Clone ]
182191 ExactChunksIter {
183192 iter,
193+ life,
184194 chunk,
185195 inner_strides,
186196 }
187197 ExactChunksIter <' a, A , D > {
188198 type Item = ArrayView <' a, A , D >;
189199
190- fn item( & mut self , elt ) {
200+ fn item( & mut self , ptr ) {
191201 unsafe {
192202 ArrayView :: new_(
193- elt ,
203+ ptr ,
194204 self . chunk. clone( ) ,
195205 self . inner_strides. clone( ) )
196206 }
@@ -209,10 +219,10 @@ impl_iterator! {
209219 ExactChunksIterMut <' a, A , D > {
210220 type Item = ArrayViewMut <' a, A , D >;
211221
212- fn item( & mut self , elt ) {
222+ fn item( & mut self , ptr ) {
213223 unsafe {
214224 ArrayViewMut :: new_(
215- elt ,
225+ ptr ,
216226 self . chunk. clone( ) ,
217227 self . inner_strides. clone( ) )
218228 }
@@ -225,7 +235,14 @@ impl_iterator! {
225235/// See [`.exact_chunks_mut()`](ArrayBase::exact_chunks_mut)
226236/// for more information.
227237pub struct ExactChunksIterMut < ' a , A , D > {
228- iter : ElementsBaseMut < ' a , A , D > ,
238+ iter : Baseiter < A , D > ,
239+ life : PhantomData < & ' a mut A > ,
229240 chunk : D ,
230241 inner_strides : D ,
231242}
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