Skip to main content

ArrayView

Struct ArrayView 

Source
pub struct ArrayView<'a, T, D>
where 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, D> ArrayView<'a, T, D>
where T: Element, D: Dimension,

Source

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>
where T: Element, D: Dimension,

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, D> ArrayView<'a, T, D>
where T: Element, D: Dimension,

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, D> ArrayView<'_, T, D>
where T: Element, D: Dimension,

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, ) -> Result<Array<T, IxDyn>, FerrayError>

Fold along an axis.

Source§

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

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> ArrayView<'a, T, IxDyn>
where T: Element,

Source

pub unsafe fn from_shape_ptr( ptr: *const T, shape: &[usize], strides: &[usize], ) -> ArrayView<'a, 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:

  • 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, D> ArrayView<'_, T, D>
where T: Element, D: Dimension,

Source

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).

Source

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>
where T: Element, D: Dimension,

Source

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

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

Source

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

Slice the view along a given axis.

Source

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

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

Source

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

Remove an axis of length 1.

Source

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

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

Trait Implementations§

Source§

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

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, D> Clone for ArrayView<'_, T, D>
where T: Element, D: Dimension,

Source§

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

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, D> Debug for ArrayView<'_, T, D>
where T: Element, D: Dimension,

Source§

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

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

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

Source§

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

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

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

Source§

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.