Skip to content

Commit 070a67e

Browse files
committed
FIX: Move LaneIter related items to iterators::lanes
1 parent f85e368 commit 070a67e

File tree

2 files changed

+91
-91
lines changed

2 files changed

+91
-91
lines changed

src/iterators/lanes.rs

+90-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::marker::PhantomData;
22

3-
use super::LanesIter;
4-
use super::LanesIterMut;
53
use crate::imp_prelude::*;
64
use crate::{Layout, NdProducer};
5+
use crate::iterators::Baseiter;
76

87
impl_ndproducer! {
98
['a, A, D: Dimension]
@@ -142,3 +141,92 @@ where
142141
}
143142
}
144143
}
144+
145+
/// An iterator that traverses over all axes but one, and yields a view for
146+
/// each lane along that axis.
147+
///
148+
/// See [`.lanes()`](../struct.ArrayBase.html#method.lanes) for more information.
149+
pub struct LanesIter<'a, A, D> {
150+
inner_len: Ix,
151+
inner_stride: Ixs,
152+
iter: Baseiter<A, D>,
153+
life: PhantomData<&'a A>,
154+
}
155+
156+
clone_bounds!(
157+
['a, A, D: Clone]
158+
LanesIter['a, A, D] {
159+
@copy {
160+
inner_len,
161+
inner_stride,
162+
life,
163+
}
164+
iter,
165+
}
166+
);
167+
168+
impl<'a, A, D> Iterator for LanesIter<'a, A, D>
169+
where
170+
D: Dimension,
171+
{
172+
type Item = ArrayView<'a, A, Ix1>;
173+
fn next(&mut self) -> Option<Self::Item> {
174+
self.iter.next().map(|ptr| unsafe {
175+
ArrayView::new_(ptr, Ix1(self.inner_len), Ix1(self.inner_stride as Ix))
176+
})
177+
}
178+
179+
fn size_hint(&self) -> (usize, Option<usize>) {
180+
self.iter.size_hint()
181+
}
182+
}
183+
184+
impl<'a, A, D> ExactSizeIterator for LanesIter<'a, A, D>
185+
where
186+
D: Dimension,
187+
{
188+
fn len(&self) -> usize {
189+
self.iter.len()
190+
}
191+
}
192+
193+
// NOTE: LanesIterMut is a mutable iterator and must not expose aliasing
194+
// pointers. Due to this we use an empty slice for the raw data (it's unused
195+
// anyway).
196+
/// An iterator that traverses over all dimensions but the innermost,
197+
/// and yields each inner row (mutable).
198+
///
199+
/// See [`.lanes_mut()`](../struct.ArrayBase.html#method.lanes_mut)
200+
/// for more information.
201+
pub struct LanesIterMut<'a, A, D> {
202+
inner_len: Ix,
203+
inner_stride: Ixs,
204+
iter: Baseiter<A, D>,
205+
life: PhantomData<&'a mut A>,
206+
}
207+
208+
impl<'a, A, D> Iterator for LanesIterMut<'a, A, D>
209+
where
210+
D: Dimension,
211+
{
212+
type Item = ArrayViewMut<'a, A, Ix1>;
213+
fn next(&mut self) -> Option<Self::Item> {
214+
self.iter.next().map(|ptr| unsafe {
215+
ArrayViewMut::new_(ptr, Ix1(self.inner_len), Ix1(self.inner_stride as Ix))
216+
})
217+
}
218+
219+
fn size_hint(&self) -> (usize, Option<usize>) {
220+
self.iter.size_hint()
221+
}
222+
}
223+
224+
impl<'a, A, D> ExactSizeIterator for LanesIterMut<'a, A, D>
225+
where
226+
D: Dimension,
227+
{
228+
fn len(&self) -> usize {
229+
self.iter.len()
230+
}
231+
}
232+

src/iterators/mod.rs

+1-89
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::Ix1;
2525
use super::{NdProducer, RemoveAxis};
2626

2727
pub use self::chunks::{ExactChunks, ExactChunksIter, ExactChunksIterMut, ExactChunksMut};
28-
pub use self::lanes::{Lanes, LanesMut};
28+
pub use self::lanes::{Lanes, LanesMut, LanesIter, LanesIterMut};
2929
pub use self::windows::Windows;
3030
pub use self::into_iter::IntoIter;
3131
pub(crate) use self::trusted::{TrustedIterator, to_vec, to_vec_mapped};
@@ -744,94 +744,6 @@ where
744744
}
745745
}
746746

747-
/// An iterator that traverses over all axes but one, and yields a view for
748-
/// each lane along that axis.
749-
///
750-
/// See [`.lanes()`](../struct.ArrayBase.html#method.lanes) for more information.
751-
pub struct LanesIter<'a, A, D> {
752-
inner_len: Ix,
753-
inner_stride: Ixs,
754-
iter: Baseiter<A, D>,
755-
life: PhantomData<&'a A>,
756-
}
757-
758-
clone_bounds!(
759-
['a, A, D: Clone]
760-
LanesIter['a, A, D] {
761-
@copy {
762-
inner_len,
763-
inner_stride,
764-
life,
765-
}
766-
iter,
767-
}
768-
);
769-
770-
impl<'a, A, D> Iterator for LanesIter<'a, A, D>
771-
where
772-
D: Dimension,
773-
{
774-
type Item = ArrayView<'a, A, Ix1>;
775-
fn next(&mut self) -> Option<Self::Item> {
776-
self.iter.next().map(|ptr| unsafe {
777-
ArrayView::new_(ptr, Ix1(self.inner_len), Ix1(self.inner_stride as Ix))
778-
})
779-
}
780-
781-
fn size_hint(&self) -> (usize, Option<usize>) {
782-
self.iter.size_hint()
783-
}
784-
}
785-
786-
impl<'a, A, D> ExactSizeIterator for LanesIter<'a, A, D>
787-
where
788-
D: Dimension,
789-
{
790-
fn len(&self) -> usize {
791-
self.iter.len()
792-
}
793-
}
794-
795-
// NOTE: LanesIterMut is a mutable iterator and must not expose aliasing
796-
// pointers. Due to this we use an empty slice for the raw data (it's unused
797-
// anyway).
798-
/// An iterator that traverses over all dimensions but the innermost,
799-
/// and yields each inner row (mutable).
800-
///
801-
/// See [`.lanes_mut()`](../struct.ArrayBase.html#method.lanes_mut)
802-
/// for more information.
803-
pub struct LanesIterMut<'a, A, D> {
804-
inner_len: Ix,
805-
inner_stride: Ixs,
806-
iter: Baseiter<A, D>,
807-
life: PhantomData<&'a mut A>,
808-
}
809-
810-
impl<'a, A, D> Iterator for LanesIterMut<'a, A, D>
811-
where
812-
D: Dimension,
813-
{
814-
type Item = ArrayViewMut<'a, A, Ix1>;
815-
fn next(&mut self) -> Option<Self::Item> {
816-
self.iter.next().map(|ptr| unsafe {
817-
ArrayViewMut::new_(ptr, Ix1(self.inner_len), Ix1(self.inner_stride as Ix))
818-
})
819-
}
820-
821-
fn size_hint(&self) -> (usize, Option<usize>) {
822-
self.iter.size_hint()
823-
}
824-
}
825-
826-
impl<'a, A, D> ExactSizeIterator for LanesIterMut<'a, A, D>
827-
where
828-
D: Dimension,
829-
{
830-
fn len(&self) -> usize {
831-
self.iter.len()
832-
}
833-
}
834-
835747
#[derive(Debug)]
836748
struct AxisIterCore<A, D> {
837749
/// Index along the axis of the value of `.next()`, relative to the start

0 commit comments

Comments
 (0)