Skip to main content

ArrayView

Struct ArrayView 

Source
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>

Source

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>

Source

pub fn itemsize(&self) -> usize

Size in bytes of a single element.

Source

pub fn nbytes(&self) -> usize

Total size in bytes of all elements.

Source

pub fn dtype(&self) -> DType

Runtime dtype tag.

Source

pub fn t(&self) -> ArrayView<'_, T, D>

Transposed view (zero-copy).

Source§

impl<'a, T: Element, D: Dimension> ArrayView<'a, T, D>

Source

pub fn iter(&self) -> impl Iterator<Item = &T> + '_

Iterate over all elements in logical order.

Source

pub fn flat(&self) -> impl Iterator<Item = &T> + '_

Flat iterator.

Source

pub fn indexed_iter(&self) -> impl Iterator<Item = (Vec<usize>, &T)> + '_

Iterate with multi-dimensional indices.

Source§

impl<T: Element, D: Dimension> ArrayView<'_, T, D>

Source

pub fn mapv(&self, f: impl Fn(T) -> T) -> Array<T, D>

Apply a closure to every element, returning a new owned array.

Source

pub fn fold_axis( &self, axis: Axis, init: T, fold: impl FnMut(&T, &T) -> T, ) -> FerrayResult<Array<T, IxDyn>>

Fold along an axis.

Source§

impl<'a, T: Element, D: Dimension> ArrayView<'a, T, D>

Source

pub fn shape(&self) -> &[usize]

Shape as a slice.

Source

pub fn ndim(&self) -> usize

Number of dimensions.

Source

pub fn size(&self) -> usize

Total number of elements.

Source

pub fn is_empty(&self) -> bool

Whether the view has zero elements.

Source

pub fn strides(&self) -> &[isize]

Strides as a slice.

Source

pub fn as_ptr(&self) -> *const T

Raw pointer to the first element.

Source

pub fn as_slice(&self) -> Option<&[T]>

Try to get a contiguous slice.

Source

pub fn layout(&self) -> MemoryLayout

Memory layout.

Source

pub fn dim(&self) -> &D

Return a reference to the internal dimension descriptor.

Source

pub fn to_owned(&self) -> Array<T, D>

Convert this view into an owned array by cloning all elements.

Source

pub fn flags(&self) -> ArrayFlags

Array flags for this view.

Source§

impl<'a, T: Element> ArrayView<'a, T, IxDyn>

Source

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:

  • ptr is valid for reads for the entire region described by shape and strides.
  • The lifetime 'a does not outlive the allocation that ptr points into.
  • No mutable reference to the same memory region exists for the duration of 'a.
  • strides are given in units of elements (not bytes).
Source§

impl<T: Element, D: Dimension> ArrayView<'_, T, D>

Source

pub fn index_select( &self, axis: Axis, indices: &[isize], ) -> FerrayResult<Array<T, IxDyn>>

Select elements along an axis using an array of indices (copy).

Source

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>

Source

pub fn index_axis( &self, axis: Axis, index: isize, ) -> FerrayResult<ArrayView<'a, T, IxDyn>>

Index into the view along a given axis, removing that axis.

Source

pub fn slice_axis( &self, axis: Axis, spec: SliceSpec, ) -> FerrayResult<ArrayView<'a, T, IxDyn>>

Slice the view along a given axis.

Source

pub fn insert_axis(&self, axis: Axis) -> FerrayResult<ArrayView<'a, T, IxDyn>>

Insert a new axis of length 1 at the given position.

Source

pub fn remove_axis(&self, axis: Axis) -> FerrayResult<ArrayView<'a, T, IxDyn>>

Remove an axis of length 1.

Source

pub fn get(&self, indices: &[isize]) -> FerrayResult<&'a T>

Get a reference to a single element by multi-dimensional index.

Trait Implementations§

Source§

impl<T: Element, D: Dimension> AsRawBuffer for ArrayView<'_, T, D>

Source§

fn raw_ptr(&self) -> *const u8

Raw pointer to the first element.
Source§

fn raw_shape(&self) -> &[usize]

Shape as a slice of dimension sizes.
Source§

fn raw_strides_bytes(&self) -> Vec<isize>

Strides in bytes (not elements).
Source§

fn raw_dtype(&self) -> DType

Runtime dtype descriptor.
Source§

fn is_c_contiguous(&self) -> bool

Whether the data is C-contiguous.
Source§

fn is_f_contiguous(&self) -> bool

Whether the data is Fortran-contiguous.
Source§

impl<T: Element, D: Dimension> Clone for ArrayView<'_, T, D>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Element, D: Dimension> Debug for ArrayView<'_, T, D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Element, D: Dimension> Display for ArrayView<'_, T, D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T: Element, D: Dimension> From<ArrayView<'a, T, D>> for CowArray<'a, T, D>

Source§

fn from(view: ArrayView<'a, T, D>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a, T, D> Freeze for ArrayView<'a, T, D>
where D: Freeze, <D as Dimension>::NdarrayDim: Freeze,

§

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>
where D: Unpin, <D as Dimension>::NdarrayDim: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.