pub struct ArrayView<'a, T, D>{ /* private fields */ }Expand description
An immutable, borrowed view into an existing array’s data.
This is a zero-copy slice — no data is cloned. The lifetime 'a
ties this view to the source array.
Implementations§
Source§impl<'a, T, D> ArrayView<'a, T, D>
impl<'a, T, D> ArrayView<'a, T, D>
Sourcepub fn broadcast_to(
&self,
target_shape: &[usize],
) -> Result<ArrayView<'a, T, IxDyn>, FerrayError>
pub fn broadcast_to( &self, target_shape: &[usize], ) -> Result<ArrayView<'a, T, IxDyn>, FerrayError>
Broadcast this view to the given shape, returning a dynamic-rank view.
§Errors
Returns FerrayError::BroadcastFailure if the view cannot be broadcast.
Source§impl<T, D> ArrayView<'_, T, D>
impl<T, D> ArrayView<'_, T, D>
Sourcepub fn indexed_iter(&self) -> impl Iterator<Item = (Vec<usize>, &T)>
pub fn indexed_iter(&self) -> impl Iterator<Item = (Vec<usize>, &T)>
Iterate with multi-dimensional indices. See Array::indexed_iter.
Source§impl<T, D> ArrayView<'_, T, D>
impl<T, D> ArrayView<'_, T, D>
Source§impl<T, D> ArrayView<'_, T, D>
impl<T, D> ArrayView<'_, T, D>
Sourcepub fn sum(&self) -> Twhere
T: Add<Output = T>,
pub fn sum(&self) -> Twhere
T: Add<Output = T>,
Sum of all elements. See Array::sum.
Sourcepub fn prod(&self) -> Twhere
T: Mul<Output = T>,
pub fn prod(&self) -> Twhere
T: Mul<Output = T>,
Product of all elements. See Array::prod.
Source§impl<T, D> ArrayView<'_, T, D>
impl<T, D> ArrayView<'_, T, D>
Sourcepub fn min(&self) -> Option<T>
pub fn min(&self) -> Option<T>
Minimum value. See Array::min.
Sourcepub fn max(&self) -> Option<T>
pub fn max(&self) -> Option<T>
Maximum value. See Array::max.
Source§impl<'a, T, D> ArrayView<'a, T, D>
impl<'a, T, D> ArrayView<'a, T, D>
Sourcepub fn layout(&self) -> MemoryLayout
pub fn layout(&self) -> MemoryLayout
Memory layout.
Sourcepub fn to_owned(&self) -> Array<T, D>
pub fn to_owned(&self) -> Array<T, D>
Convert this view into an owned array by cloning all elements.
Sourcepub fn to_vec_flat(&self) -> Vec<T>
pub fn to_vec_flat(&self) -> Vec<T>
Convert to a flat Vec<T> in logical (row-major) order.
Unlike as_slice() which requires contiguous memory, this works on
strided/non-contiguous views by iterating elements in logical order.
Sourcepub fn flags(&self) -> ArrayFlags
pub fn flags(&self) -> ArrayFlags
Array flags for this view.
Source§impl<T> ArrayView<'_, T, IxDyn>where
T: Element,
impl<T> ArrayView<'_, T, IxDyn>where
T: Element,
Sourcepub unsafe fn from_shape_ptr(
ptr: *const T,
shape: &[usize],
strides: &[usize],
) -> ArrayView<'_, T, IxDyn>
pub unsafe fn from_shape_ptr( ptr: *const T, shape: &[usize], strides: &[usize], ) -> ArrayView<'_, T, IxDyn>
Construct a dynamic-rank view from a raw pointer, shape, and strides.
This is the primary escape hatch for crates that need to build views
with custom stride patterns (e.g., ferray-stride-tricks).
§Safety
The caller must ensure:
ptris valid for reads for the entire region described byshapeandstrides.- The lifetime
'adoes not outlive the allocation thatptrpoints into. - No mutable reference to the same memory region exists for the
duration of
'a. stridesare given in units of elements (not bytes).
Source§impl<T, D> ArrayView<'_, T, D>
impl<T, D> ArrayView<'_, T, D>
Sourcepub fn index_select(
&self,
axis: Axis,
indices: &[isize],
) -> Result<Array<T, IxDyn>, FerrayError>
pub fn index_select( &self, axis: Axis, indices: &[isize], ) -> Result<Array<T, IxDyn>, FerrayError>
Select elements along an axis using an array of indices (copy).
Sourcepub fn boolean_index(
&self,
mask: &Array<bool, D>,
) -> Result<Array<T, Ix1>, FerrayError>
pub fn boolean_index( &self, mask: &Array<bool, D>, ) -> Result<Array<T, Ix1>, FerrayError>
Select elements using a boolean mask (copy).
Source§impl<'a, T, D> ArrayView<'a, T, D>
impl<'a, T, D> ArrayView<'a, T, D>
Sourcepub fn index_axis(
&self,
axis: Axis,
index: isize,
) -> Result<ArrayView<'a, T, <D as Dimension>::Smaller>, FerrayError>where
<D as Dimension>::NdarrayDim: RemoveAxis<Smaller = <<D as Dimension>::Smaller as Dimension>::NdarrayDim>,
pub fn index_axis(
&self,
axis: Axis,
index: isize,
) -> Result<ArrayView<'a, T, <D as Dimension>::Smaller>, FerrayError>where
<D as Dimension>::NdarrayDim: RemoveAxis<Smaller = <<D as Dimension>::Smaller as Dimension>::NdarrayDim>,
Index into the view along a given axis, removing that axis.
Returns a view with rank one less than Self (#349).
Sourcepub fn slice_axis(
&self,
axis: Axis,
spec: SliceSpec,
) -> Result<ArrayView<'a, T, IxDyn>, FerrayError>
pub fn slice_axis( &self, axis: Axis, spec: SliceSpec, ) -> Result<ArrayView<'a, T, IxDyn>, FerrayError>
Slice the view along a given axis.
Sourcepub fn insert_axis(
&self,
axis: Axis,
) -> Result<ArrayView<'a, T, <D as Dimension>::Larger>, FerrayError>where
<D as Dimension>::NdarrayDim: Dimension<Larger = <<D as Dimension>::Larger as Dimension>::NdarrayDim>,
pub fn insert_axis(
&self,
axis: Axis,
) -> Result<ArrayView<'a, T, <D as Dimension>::Larger>, FerrayError>where
<D as Dimension>::NdarrayDim: Dimension<Larger = <<D as Dimension>::Larger as Dimension>::NdarrayDim>,
Insert a new axis of length 1 at the given position.
Returns a view with rank one greater than Self (#349).
Sourcepub fn remove_axis(
&self,
axis: Axis,
) -> Result<ArrayView<'a, T, <D as Dimension>::Smaller>, FerrayError>where
<D as Dimension>::NdarrayDim: RemoveAxis<Smaller = <<D as Dimension>::Smaller as Dimension>::NdarrayDim>,
pub fn remove_axis(
&self,
axis: Axis,
) -> Result<ArrayView<'a, T, <D as Dimension>::Smaller>, FerrayError>where
<D as Dimension>::NdarrayDim: RemoveAxis<Smaller = <<D as Dimension>::Smaller as Dimension>::NdarrayDim>,
Remove an axis of length 1.
Returns a view with rank one less than Self (#349).
Trait Implementations§
Source§impl<'a, T, D> AsRawBuffer for ArrayView<'a, T, D>
impl<'a, T, D> AsRawBuffer for ArrayView<'a, T, D>
Source§fn raw_strides_bytes(&self) -> Vec<isize>
fn raw_strides_bytes(&self) -> Vec<isize>
Source§fn is_c_contiguous(&self) -> bool
fn is_c_contiguous(&self) -> bool
Source§fn is_f_contiguous(&self) -> bool
fn is_f_contiguous(&self) -> bool
Source§fn buffer_descriptor(&self) -> BufferDescriptor<'_>
fn buffer_descriptor(&self) -> BufferDescriptor<'_>
BufferDescriptor aggregating every field above into
a single FFI-safe struct (#358). Default impl composes the
other trait methods so concrete types don’t need to override.Auto Trait Implementations§
impl<'a, T, D> Freeze for ArrayView<'a, T, D>
impl<'a, T, D> RefUnwindSafe for ArrayView<'a, T, D>
impl<'a, T, D> Send for ArrayView<'a, T, D>
impl<'a, T, D> Sync for ArrayView<'a, T, D>
impl<'a, T, D> Unpin for ArrayView<'a, T, D>
impl<'a, T, D> UnsafeUnpin for ArrayView<'a, T, D>
impl<'a, T, D> UnwindSafe for ArrayView<'a, T, D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more