Struct Array

Source
pub struct Array<T> { /* private fields */ }
Expand description

An N-dimensional strided array.

Implementations§

Source§

impl<T> Array<T>

Source

pub fn as_mut_slice(&mut self) -> &mut [T]

Returns a mutable reference to the underlying data as a flat slice in row-major order.

Source

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

Returns the underlying data as a flat slice in row-major order.

Source

pub fn dimensions(&self) -> usize

Returns the number of dimensions of the array.

Source

pub fn elements(&self) -> usize

Returns the number of elements in the array.

Source

pub fn from_element<S>(element: T, shape: S) -> Self
where T: Clone, S: Into<Shape>,

Creates a new array by repeating a single element to a shape.

Source

pub fn from_iter<I, S>(iter: I, shape: S) -> Result<Self, ShapeError>
where I: IntoIterator<Item = T>, S: Into<Shape>,

Creates a new array from an iterator an its shape.

§Errors

If the number of items in the iterator does not match the provided shape.

Source

pub fn get<I>(&self, index: I) -> Option<&T>
where I: AsRef<[usize]>,

Returns the element at the provided index if in bounds, and None otherwise,

Source

pub fn get_axis(&self, axis: Axis, index: usize) -> Option<View<'_, T>>

Returns a view of the array along the provided axis at the provided index if in bounds, and None otherwise.

See Array::index_axis for a panicking version.

Source

pub fn get_mut<I>(&mut self, index: I) -> Option<&mut T>
where I: AsRef<[usize]>,

Returns a mutable reference to the element at the provided index if in bounds, and None otherwise,

Source

pub fn index_axis(&self, axis: Axis, index: usize) -> View<'_, T>

Returns a view of the array along the provided axis at the provided index if in bounds.

§Panics

If the axis or the index is not in bounds, see Array::get_axis for a fallible version.

Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the underlying data in row-major order.

Source

pub fn iter_axis(&self, axis: Axis) -> AxisIter<'_, T>

Returns an iterator over views of the array along the provided axis.

Source

pub fn iter_indices(&self) -> IndicesIter<'_>

Returns an iterator over indices of the array in row-major order.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns an iterator over mutable references to the underlying data in row-major order.

Source

pub fn new<D, S>(data: D, shape: S) -> Result<Self, ShapeError>
where D: Into<Vec<T>>, S: Into<Shape>,

Creates a new array from data in row-major order and a shape.

§Errors

If the number of items in the data does not match the provided shape.

Source

pub fn new_unchecked<D, S>(data: D, shape: S) -> Self
where D: Into<Vec<T>>, S: Into<Shape>,

Creates a new array from data in row-major order and a shape.

Prefer using Array::new to ensure the data fits the provided shape. It is a logic error where this is not true, though it can not trigger unsafe behaviour.

Source

pub fn shape(&self) -> &Shape

Returns the shape of the array.

Source§

impl Array<f64>

Source

pub fn from_zeros<S>(shape: S) -> Self
where S: Into<Shape>,

Creates a new array filled with zeros to a shape.

Source

pub fn read_npy<R>(reader: R) -> Result<Self>
where R: BufRead,

Reads an array from the npy format.

See the format docs for details.

Source

pub fn sum(&self, axis: Axis) -> Self

Returns the sum of the elements in the array.

Source

pub fn write_npy<W>(&self, writer: W) -> Result<()>
where W: Write,

Writes the in the npy format.

See the format docs for details.

Trait Implementations§

Source§

impl<T: Clone> Clone for Array<T>

Source§

fn clone(&self) -> Array<T>

Returns a copy 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: Debug> Debug for Array<T>

Source§

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

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

impl From<Array<f64>> for Scs

Source§

fn from(array: Array<f64>) -> Self

Converts to this type from the input type.
Source§

impl<T, I> Index<I> for Array<T>
where I: AsRef<[usize]>,

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, I> IndexMut<I> for Array<T>
where I: AsRef<[usize]>,

Source§

fn index_mut(&mut self, index: I) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T: PartialEq> PartialEq for Array<T>

Source§

fn eq(&self, other: &Array<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> StructuralPartialEq for Array<T>

Auto Trait Implementations§

§

impl<T> Freeze for Array<T>

§

impl<T> RefUnwindSafe for Array<T>
where T: RefUnwindSafe,

§

impl<T> Send for Array<T>
where T: Send,

§

impl<T> Sync for Array<T>
where T: Sync,

§

impl<T> Unpin for Array<T>
where T: Unpin,

§

impl<T> UnwindSafe for Array<T>
where T: UnwindSafe,

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