Skip to main content

Array2

Struct Array2 

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

Owned 2D row-major array.

Implementations§

Source§

impl<T> Array2<T>

Source

pub fn from_vec(shape: [usize; 2], data: Vec<T>) -> Result<Self>

Build an array from row-major data.

Source

pub fn from_fn(shape: [usize; 2], f: impl FnMut(usize, usize) -> T) -> Self

Build an array from a function over (row, col).

Source

pub fn try_from_fn( shape: [usize; 2], f: impl FnMut(usize, usize) -> T, ) -> Result<Self>

Fallibly build an array from a function over (row, col).

Source

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

Shape as [rows, cols].

Source

pub fn rows(&self) -> usize

Number of rows.

Source

pub fn cols(&self) -> usize

Number of columns.

Source

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

Row-major strides in elements.

Source

pub fn row_stride(&self) -> isize

Distance in elements between consecutive rows.

Source

pub fn col_stride(&self) -> isize

Distance in elements between consecutive columns.

Source

pub fn leading_dimension(&self) -> isize

Leading dimension for row-major storage.

Source

pub fn len(&self) -> usize

Number of elements.

Source

pub fn is_empty(&self) -> bool

Whether the array has zero elements.

Source

pub fn is_contiguous(&self) -> bool

Owned arrays are compact row-major contiguous.

Source

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

Borrow the row-major backing slice.

Source

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

Borrow the row-major backing slice mutably.

Source

pub fn into_vec(self) -> Vec<T>

Consume into the backing vector.

Source

pub fn view(&self) -> ArrayView2<'_, T>

Immutable strided view.

Source

pub fn view_mut(&mut self) -> ArrayViewMut2<'_, T>

Mutable strided view.

Source

pub fn transpose_view(&self) -> ArrayView2<'_, T>

Transpose view without copying.

Source

pub fn get(&self, row: usize, col: usize) -> Option<&T>

Get an element reference.

Source

pub fn get_mut(&mut self, row: usize, col: usize) -> Option<&mut T>

Get a mutable element reference.

Source

pub fn row(&self, row: usize) -> Result<ArrayView2<'_, T>>

Row as a one-row matrix view.

Source

pub fn row_slice(&self, row: usize) -> Result<&[T]>

Borrow a row as a contiguous slice.

Source

pub fn row_mut(&mut self, row: usize) -> Result<ArrayViewMut2<'_, T>>

Mutable row as a one-row matrix view.

Source

pub fn row_slice_mut(&mut self, row: usize) -> Result<&mut [T]>

Borrow a row as a mutable contiguous slice.

Source

pub fn col(&self, col: usize) -> Result<ArrayView2<'_, T>>

Column as an rows x 1 matrix view.

Source

pub fn col_mut(&mut self, col: usize) -> Result<ArrayViewMut2<'_, T>>

Mutable column as an rows x 1 matrix view.

Source

pub fn rows_range(&self, start: usize, end: usize) -> Result<ArrayView2<'_, T>>

Half-open row slice.

Source

pub fn rows_range_mut( &mut self, start: usize, end: usize, ) -> Result<ArrayViewMut2<'_, T>>

Mutable half-open row slice.

Source

pub fn cols_range(&self, start: usize, end: usize) -> Result<ArrayView2<'_, T>>

Half-open column slice.

Source

pub fn cols_range_mut( &mut self, start: usize, end: usize, ) -> Result<ArrayViewMut2<'_, T>>

Mutable half-open column slice.

Source

pub fn reshape(self, shape: [usize; 2]) -> Result<Self>

Reshape without changing storage order.

Source§

impl<T: Clone> Array2<T>

Source

pub fn filled(shape: [usize; 2], value: T) -> Self

Fill a new array with value.

Source

pub fn try_filled(shape: [usize; 2], value: T) -> Result<Self>

Fallibly fill a new array with value.

Source

pub fn clone_contiguous(view: ArrayView2<'_, T>) -> Self

Clone into compact row-major storage.

Source

pub fn to_row_major(&self) -> Self

Copy this array into compact row-major storage.

Source

pub fn to_col_major_vec(&self) -> Vec<T>

Copy this array into a column-major vector.

Source

pub fn copy_from_view(&mut self, other: ArrayView2<'_, T>) -> Result<()>

Copy values from another view with the same shape.

Source§

impl<T: Float> Array2<T>

Source

pub fn zeros(shape: [usize; 2]) -> Self

Array filled with zeros.

Source

pub fn try_zeros(shape: [usize; 2]) -> Result<Self>

Fallibly allocate an array filled with zeros.

Source

pub fn ones(shape: [usize; 2]) -> Self

Array filled with ones.

Source

pub fn try_ones(shape: [usize; 2]) -> Result<Self>

Fallibly allocate an array filled with ones.

Source

pub fn zeros_like(&self) -> Self

Allocate another array with the same shape, filled with zeros.

Source

pub fn scale(&mut self, alpha: T)

Scale in place.

Source

pub fn scaled(&self, alpha: T) -> Self

Return self * alpha without modifying self.

Source

pub fn scaled_into(&self, alpha: T, out: ArrayViewMut2<'_, T>) -> Result<()>

Write self * alpha into out without modifying self.

Source

pub fn add(&self, other: ArrayView2<'_, T>) -> Result<Self>

Return self + other without modifying either input.

Source

pub fn add_into( &self, other: ArrayView2<'_, T>, out: ArrayViewMut2<'_, T>, ) -> Result<()>

Write self + other into out without modifying either input.

Source

pub fn sub(&self, other: ArrayView2<'_, T>) -> Result<Self>

Return self - other without modifying either input.

Source

pub fn sub_into( &self, other: ArrayView2<'_, T>, out: ArrayViewMut2<'_, T>, ) -> Result<()>

Write self - other into out without modifying either input.

Source

pub fn mul(&self, other: ArrayView2<'_, T>) -> Result<Self>

Return the elementwise product self * other without modifying either input.

Source

pub fn mul_into( &self, other: ArrayView2<'_, T>, out: ArrayViewMut2<'_, T>, ) -> Result<()>

Write the elementwise product into out without modifying either input.

Source

pub fn hadamard(&self, other: ArrayView2<'_, T>) -> Result<Self>

Return the Hadamard product without modifying either input.

Source

pub fn hadamard_into( &self, other: ArrayView2<'_, T>, out: ArrayViewMut2<'_, T>, ) -> Result<()>

Write the Hadamard product into out without modifying either input.

Source

pub fn div(&self, other: ArrayView2<'_, T>) -> Result<Self>

Return the elementwise quotient self / other without modifying either input.

Source

pub fn div_into( &self, other: ArrayView2<'_, T>, out: ArrayViewMut2<'_, T>, ) -> Result<()>

Write the elementwise quotient into out without modifying either input.

Source

pub fn axpy_result(&self, alpha: T, x: ArrayView2<'_, T>) -> Result<Self>

Return self + alpha * x without modifying either input.

Source

pub fn axpy_into( &self, alpha: T, x: ArrayView2<'_, T>, out: ArrayViewMut2<'_, T>, ) -> Result<()>

Write self + alpha * x into out without modifying either input.

Source

pub fn matmul(&self, other: ArrayView2<'_, T>) -> Result<Self>

Return a matrix product self @ other without modifying either input.

Source

pub fn matmul_into( &self, other: ArrayView2<'_, T>, out: ArrayViewMut2<'_, T>, ) -> Result<()>

Write matrix product self @ other into out without modifying either input.

Source

pub fn add_assign_view(&mut self, other: ArrayView2<'_, T>) -> Result<()>

In-place addition.

Source

pub fn sub_assign_view(&mut self, other: ArrayView2<'_, T>) -> Result<()>

In-place subtraction.

Source

pub fn mul_assign_view(&mut self, other: ArrayView2<'_, T>) -> Result<()>

Hadamard product in place.

Source

pub fn div_assign_view(&mut self, other: ArrayView2<'_, T>) -> Result<()>

In-place elementwise division.

Source

pub fn axpy(&mut self, alpha: T, x: ArrayView2<'_, T>) -> Result<()>

Compute self += alpha * x.

Source

pub fn map_inplace(&mut self, f: impl FnMut(T) -> T)

Map values in place.

Source

pub fn zip_map_inplace( &mut self, other: ArrayView2<'_, T>, f: impl FnMut(T, T) -> T, ) -> Result<()>

Zip-map another view into this array in place.

Source

pub fn zip_map( &self, other: ArrayView2<'_, T>, f: impl FnMut(T, T) -> T, ) -> Result<Self>

Return an elementwise zip-map without modifying either input.

Source

pub fn zip_map_into( &self, other: ArrayView2<'_, T>, out: ArrayViewMut2<'_, T>, f: impl FnMut(T, T) -> T, ) -> Result<()>

Write an elementwise zip-map into out without modifying either input.

Source

pub fn fill_uniform(&mut self, seed: u64)

Fill with deterministic uniform random values in [0, 1).

Source

pub fn fill_randn(&mut self, seed: u64)

Fill with deterministic standard-normal random values.

Source

pub fn sum(&self) -> T

Sum all elements.

Source

pub fn mean(&self) -> T

Mean of all elements, or zero for an empty array.

Source

pub fn norm_frobenius(&self) -> T

Frobenius norm.

Source

pub fn max_abs(&self) -> T

Maximum absolute element, or zero for an empty array.

Source

pub fn dot(&self, other: ArrayView2<'_, T>) -> Result<T>

Dot product of two arrays treated as flattened row-major buffers.

Trait Implementations§

Source§

impl<T: Clone> Clone for Array2<T>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Array2<T>

Source§

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

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

impl<T> Index<(usize, usize)> for Array2<T>

Source§

type Output = T

The returned type after indexing.
Source§

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

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

impl<T> IndexMut<(usize, usize)> for Array2<T>

Source§

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

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

impl<T: Float> LinearOperator<T> for Array2<T>

Source§

fn rows(&self) -> usize

Number of rows.
Source§

fn cols(&self) -> usize

Number of columns.
Source§

fn matvec(&self, x: &[T], y: &mut [T]) -> Result<()>

Compute y = A x.
Source§

fn t_matvec(&self, x: &[T], y: &mut [T]) -> Result<()>

Compute y = A^T x.
Source§

fn matmat(&self, x: ArrayView2<'_, T>, y: ArrayViewMut2<'_, T>) -> Result<()>

Compute Y = A X.
Source§

fn t_matmat(&self, x: ArrayView2<'_, T>, y: ArrayViewMut2<'_, T>) -> Result<()>

Compute Y = A^T X.
Source§

impl<T: PartialEq> PartialEq for Array2<T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Array2<T>

Auto Trait Implementations§

§

impl<T> Freeze for Array2<T>

§

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

§

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

§

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

§

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

§

impl<T> UnsafeUnpin for Array2<T>

§

impl<T> UnwindSafe for Array2<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> 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> 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.