pub struct ArrayView<'a, T: Element, D: Dimension> { /* 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: Element, D: Dimension> ArrayView<'a, T, D>
impl<'a, T: Element, D: Dimension> ArrayView<'a, T, D>
Sourcepub fn broadcast_to(
&self,
target_shape: &[usize],
) -> FerrayResult<ArrayView<'a, T, IxDyn>>
pub fn broadcast_to( &self, target_shape: &[usize], ) -> FerrayResult<ArrayView<'a, T, IxDyn>>
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: Element, D: Dimension> ArrayView<'_, T, D>
impl<T: Element, D: Dimension> ArrayView<'_, T, D>
Sourcepub fn mapv(&self, f: impl Fn(T) -> T) -> Array<T, D>
pub fn mapv(&self, f: impl Fn(T) -> T) -> Array<T, D>
Apply a closure to every element, returning a new owned array.
Sourcepub fn fold_axis(
&self,
axis: Axis,
init: T,
fold: impl FnMut(&T, &T) -> T,
) -> FerrayResult<Array<T, IxDyn>>where
D::NdarrayDim: RemoveAxis,
pub fn fold_axis(
&self,
axis: Axis,
init: T,
fold: impl FnMut(&T, &T) -> T,
) -> FerrayResult<Array<T, IxDyn>>where
D::NdarrayDim: RemoveAxis,
Fold along an axis.
Source§impl<'a, T: Element, D: Dimension> ArrayView<'a, T, D>
impl<'a, T: Element, D: Dimension> 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 flags(&self) -> ArrayFlags
pub fn flags(&self) -> ArrayFlags
Array flags for this view.
Source§impl<'a, T: Element> ArrayView<'a, T, IxDyn>
impl<'a, T: Element> ArrayView<'a, T, IxDyn>
Sourcepub unsafe fn from_shape_ptr(
ptr: *const T,
shape: &[usize],
strides: &[usize],
) -> Self
pub unsafe fn from_shape_ptr( ptr: *const T, shape: &[usize], strides: &[usize], ) -> Self
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: Element, D: Dimension> ArrayView<'_, T, D>
impl<T: Element, D: Dimension> ArrayView<'_, T, D>
Sourcepub fn index_select(
&self,
axis: Axis,
indices: &[isize],
) -> FerrayResult<Array<T, IxDyn>>
pub fn index_select( &self, axis: Axis, indices: &[isize], ) -> FerrayResult<Array<T, IxDyn>>
Select elements along an axis using an array of indices (copy).
Sourcepub fn boolean_index(
&self,
mask: &Array<bool, D>,
) -> FerrayResult<Array<T, Ix1>>
pub fn boolean_index( &self, mask: &Array<bool, D>, ) -> FerrayResult<Array<T, Ix1>>
Select elements using a boolean mask (copy).
Source§impl<'a, T: Element, D: Dimension> ArrayView<'a, T, D>
impl<'a, T: Element, D: Dimension> ArrayView<'a, T, D>
Sourcepub fn index_axis(
&self,
axis: Axis,
index: isize,
) -> FerrayResult<ArrayView<'a, T, IxDyn>>where
D::NdarrayDim: RemoveAxis,
pub fn index_axis(
&self,
axis: Axis,
index: isize,
) -> FerrayResult<ArrayView<'a, T, IxDyn>>where
D::NdarrayDim: RemoveAxis,
Index into the view along a given axis, removing that axis.
Sourcepub fn slice_axis(
&self,
axis: Axis,
spec: SliceSpec,
) -> FerrayResult<ArrayView<'a, T, IxDyn>>
pub fn slice_axis( &self, axis: Axis, spec: SliceSpec, ) -> FerrayResult<ArrayView<'a, T, IxDyn>>
Slice the view along a given axis.
Sourcepub fn insert_axis(&self, axis: Axis) -> FerrayResult<ArrayView<'a, T, IxDyn>>
pub fn insert_axis(&self, axis: Axis) -> FerrayResult<ArrayView<'a, T, IxDyn>>
Insert a new axis of length 1 at the given position.
Sourcepub fn remove_axis(&self, axis: Axis) -> FerrayResult<ArrayView<'a, T, IxDyn>>
pub fn remove_axis(&self, axis: Axis) -> FerrayResult<ArrayView<'a, T, IxDyn>>
Remove an axis of length 1.
Sourcepub fn get(&self, indices: &[isize]) -> FerrayResult<&'a T>
pub fn get(&self, indices: &[isize]) -> FerrayResult<&'a T>
Get a reference to a single element by multi-dimensional index.