Skip to content

Into iter methods #1510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/array_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::marker::PhantomData;
use crate::imp_prelude::*;

use super::arraytraits::ARRAY_FORMAT_VERSION;
use super::Iter;
use crate::iterators::Iter;
use crate::IntoDimension;

/// Verifies that the version of the deserialized array matches the current
Expand Down
4 changes: 2 additions & 2 deletions src/arraytraits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ where D: Dimension

fn into_iter(self) -> Self::IntoIter
{
self.into_iter_()
Iter::new(self)
}
}

Expand All @@ -369,7 +369,7 @@ where D: Dimension

fn into_iter(self) -> Self::IntoIter
{
self.into_iter_()
IterMut::new(self)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/impl_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ impl<A, D: Dimension> ArrayRef<A, D>
pub fn iter(&self) -> Iter<'_, A, D>
{
// debug_assert!(self.pointer_is_inbounds());
self.view().into_iter_()
self.view().into_iter()
}

/// Return an iterator of mutable references to the elements of the array.
Expand All @@ -474,7 +474,7 @@ impl<A, D: Dimension> ArrayRef<A, D>
/// Iterator element type is `&mut A`.
pub fn iter_mut(&mut self) -> IterMut<'_, A, D>
{
self.view_mut().into_iter_()
self.view_mut().into_iter()
}

/// Return an iterator of indexes and references to the elements of the array.
Expand Down Expand Up @@ -1290,7 +1290,7 @@ impl<A, D: Dimension> ArrayRef<A, D>
pub fn outer_iter_mut(&mut self) -> AxisIterMut<'_, A, D::Smaller>
where D: RemoveAxis
{
self.view_mut().into_outer_iter()
self.view_mut().into_outer_iter_mut()
}

/// Return an iterator that traverses over `axis`
Expand Down
120 changes: 105 additions & 15 deletions src/impl_views/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::mem::MaybeUninit;

use crate::imp_prelude::*;

use crate::{Baseiter, ElementsBase, ElementsBaseMut, Iter, IterMut};
use crate::{Baseiter, ElementsBase, ElementsBaseMut};

use crate::dimension::offset_from_low_addr_ptr_to_logical_ptr;
use crate::iter::{self, AxisIter, AxisIterMut};
Expand Down Expand Up @@ -213,7 +213,7 @@ where D: Dimension
}
}

/// Private array view methods
/// Methods for iterating over array views.
impl<'a, A, D> ArrayView<'a, A, D>
where D: Dimension
{
Expand All @@ -229,21 +229,47 @@ where D: Dimension
ElementsBase::new(self)
}

pub(crate) fn into_iter_(self) -> Iter<'a, A, D>
/// Convert into an outer iterator for this view.
///
/// Unlike [ArrayRef::outer_iter], this methods preserves the lifetime of the data,
/// not the view itself.
pub fn into_outer_iter(self) -> iter::AxisIter<'a, A, D::Smaller>
where D: RemoveAxis
{
Iter::new(self)
AxisIter::new(self, Axis(0))
}

/// Return an outer iterator for this view.
#[doc(hidden)] // not official
#[deprecated(note = "This method will be replaced.")]
pub fn into_outer_iter(self) -> iter::AxisIter<'a, A, D::Smaller>
/// Convert into an indexed iterator.
///
/// Unlike [ArrayRef::indexed_iter], this methods preserves the lifetime of the data,
/// not the view itself.
pub fn into_indexed_iter(self) -> iter::IndexedIter<'a, A, D>
{
iter::IndexedIter::new(self.into_elements_base())
}

/// Convert into an iterator over an `axis`.
///
/// Unlike [ArrayRef::axis_iter], this methods preserves the lifetime of the data,
/// not the view itself.
pub fn into_axis_iter(self, axis: Axis) -> iter::AxisIter<'a, A, D::Smaller>
where D: RemoveAxis
{
AxisIter::new(self, Axis(0))
AxisIter::new(self, axis)
}

/// Convert into an iterator over an `axis` by chunks.
///
/// Unlike [`ArrayRef::axis_chunks_iter`], this methods preserves the lifetime of the data,
/// not the view itself.
pub fn into_axis_chunks_iter(self, axis: Axis, chunk_size: usize) -> iter::AxisChunksIter<'a, A, D>
where D: RemoveAxis
{
iter::AxisChunksIter::new(self, axis, chunk_size)
}
}

/// Methods for iterating over mutable array views.
impl<'a, A, D> ArrayViewMut<'a, A, D>
where D: Dimension
{
Expand Down Expand Up @@ -294,17 +320,81 @@ where D: Dimension
}
}

pub(crate) fn into_iter_(self) -> IterMut<'a, A, D>
/// Convert into an outer iterator for this view.
///
/// Unlike [ArrayRef::outer_iter], this methods preserves the lifetime of the data,
/// not the view itself.
pub fn into_outer_iter(self) -> iter::AxisIter<'a, A, D::Smaller>
where D: RemoveAxis
{
AxisIter::new(self.into_view(), Axis(0))
}

/// Convert into an indexed iterator.
///
/// Unlike [ArrayRef::indexed_iter], this methods preserves the lifetime of the data,
/// not the view itself.
pub fn into_indexed_iter(self) -> iter::IndexedIter<'a, A, D>
{
iter::IndexedIter::new(self.into_view().into_elements_base())
}

/// Convert into an iterator over an `axis`.
///
/// Unlike [ArrayRef::axis_iter], this methods preserves the lifetime of the data,
/// not the view itself.
pub fn into_axis_iter(self, axis: Axis) -> iter::AxisIter<'a, A, D::Smaller>
where D: RemoveAxis
{
AxisIter::new(self.into_view(), axis)
}

/// Convert into an iterator over an `axis` by chunks.
///
/// Unlike [`ArrayRef::axis_chunks_iter`], this methods preserves the lifetime of the data,
/// not the view itself.
pub fn into_axis_chunks_iter(self, axis: Axis, chunk_size: usize) -> iter::AxisChunksIter<'a, A, D>
where D: RemoveAxis
{
IterMut::new(self)
iter::AxisChunksIter::new(self.into_view(), axis, chunk_size)
}

/// Return an outer iterator for this view.
#[doc(hidden)] // not official
#[deprecated(note = "This method will be replaced.")]
pub fn into_outer_iter(self) -> iter::AxisIterMut<'a, A, D::Smaller>
/// Convert into an outer iterator for this view.
///
/// Unlike [ArrayRef::outer_iter_mut], this methods preserves the lifetime of the data,
/// not the view itself.
pub fn into_outer_iter_mut(self) -> iter::AxisIterMut<'a, A, D::Smaller>
where D: RemoveAxis
{
AxisIterMut::new(self, Axis(0))
}

/// Convert into an indexed iterator.
///
/// Unlike [ArrayRef::indexed_iter_mut], this methods preserves the lifetime of the data,
/// not the view itself.
pub fn into_indexed_iter_mut(self) -> iter::IndexedIterMut<'a, A, D>
{
iter::IndexedIterMut::new(self.into_elements_base())
}

/// Convert into an iterator over an `axis`.
///
/// Unlike [ArrayRef::axis_iter_mut], this methods preserves the lifetime of the data,
/// not the view itself.
pub fn into_axis_iter_mut(self, axis: Axis) -> iter::AxisIterMut<'a, A, D::Smaller>
where D: RemoveAxis
{
AxisIterMut::new(self, axis)
}

/// Convert into an iterator over an `axis` by chunks.
///
/// Unlike [`ArrayRef::axis_chunks_iter_mut`], this methods preserves the lifetime of the data,
/// not the view itself.
pub fn into_axis_chunks_iter_mut(self, axis: Axis, chunk_size: usize) -> iter::AxisChunksIterMut<'a, A, D>
where D: RemoveAxis
{
iter::AxisChunksIterMut::new(self, axis, chunk_size)
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub use crate::order::Order;
pub use crate::slice::{MultiSliceArg, NewAxis, Slice, SliceArg, SliceInfo, SliceInfoElem, SliceNextDim};

use crate::iterators::Baseiter;
use crate::iterators::{ElementsBase, ElementsBaseMut, Iter, IterMut};
use crate::iterators::{ElementsBase, ElementsBaseMut};

pub use crate::arraytraits::AsArray;
pub use crate::linalg_traits::LinalgScalar;
Expand Down