pub struct Array2<T> { /* private fields */ }Expand description
Owned 2D row-major array.
Implementations§
Source§impl<T> Array2<T>
impl<T> Array2<T>
Sourcepub fn from_vec(shape: [usize; 2], data: Vec<T>) -> Result<Self>
pub fn from_vec(shape: [usize; 2], data: Vec<T>) -> Result<Self>
Build an array from row-major data.
Sourcepub fn from_fn(shape: [usize; 2], f: impl FnMut(usize, usize) -> T) -> Self
pub fn from_fn(shape: [usize; 2], f: impl FnMut(usize, usize) -> T) -> Self
Build an array from a function over (row, col).
Sourcepub fn try_from_fn(
shape: [usize; 2],
f: impl FnMut(usize, usize) -> T,
) -> Result<Self>
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).
Sourcepub fn row_stride(&self) -> isize
pub fn row_stride(&self) -> isize
Distance in elements between consecutive rows.
Sourcepub fn col_stride(&self) -> isize
pub fn col_stride(&self) -> isize
Distance in elements between consecutive columns.
Sourcepub fn leading_dimension(&self) -> isize
pub fn leading_dimension(&self) -> isize
Leading dimension for row-major storage.
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Owned arrays are compact row-major contiguous.
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Borrow the row-major backing slice mutably.
Sourcepub fn view(&self) -> ArrayView2<'_, T>
pub fn view(&self) -> ArrayView2<'_, T>
Immutable strided view.
Sourcepub fn view_mut(&mut self) -> ArrayViewMut2<'_, T>
pub fn view_mut(&mut self) -> ArrayViewMut2<'_, T>
Mutable strided view.
Sourcepub fn transpose_view(&self) -> ArrayView2<'_, T>
pub fn transpose_view(&self) -> ArrayView2<'_, T>
Transpose view without copying.
Sourcepub fn get_mut(&mut self, row: usize, col: usize) -> Option<&mut T>
pub fn get_mut(&mut self, row: usize, col: usize) -> Option<&mut T>
Get a mutable element reference.
Sourcepub fn row(&self, row: usize) -> Result<ArrayView2<'_, T>>
pub fn row(&self, row: usize) -> Result<ArrayView2<'_, T>>
Row as a one-row matrix view.
Sourcepub fn row_mut(&mut self, row: usize) -> Result<ArrayViewMut2<'_, T>>
pub fn row_mut(&mut self, row: usize) -> Result<ArrayViewMut2<'_, T>>
Mutable row as a one-row matrix view.
Sourcepub fn row_slice_mut(&mut self, row: usize) -> Result<&mut [T]>
pub fn row_slice_mut(&mut self, row: usize) -> Result<&mut [T]>
Borrow a row as a mutable contiguous slice.
Sourcepub fn col(&self, col: usize) -> Result<ArrayView2<'_, T>>
pub fn col(&self, col: usize) -> Result<ArrayView2<'_, T>>
Column as an rows x 1 matrix view.
Sourcepub fn col_mut(&mut self, col: usize) -> Result<ArrayViewMut2<'_, T>>
pub fn col_mut(&mut self, col: usize) -> Result<ArrayViewMut2<'_, T>>
Mutable column as an rows x 1 matrix view.
Sourcepub fn rows_range(&self, start: usize, end: usize) -> Result<ArrayView2<'_, T>>
pub fn rows_range(&self, start: usize, end: usize) -> Result<ArrayView2<'_, T>>
Half-open row slice.
Sourcepub fn rows_range_mut(
&mut self,
start: usize,
end: usize,
) -> Result<ArrayViewMut2<'_, T>>
pub fn rows_range_mut( &mut self, start: usize, end: usize, ) -> Result<ArrayViewMut2<'_, T>>
Mutable half-open row slice.
Sourcepub fn cols_range(&self, start: usize, end: usize) -> Result<ArrayView2<'_, T>>
pub fn cols_range(&self, start: usize, end: usize) -> Result<ArrayView2<'_, T>>
Half-open column slice.
Sourcepub fn cols_range_mut(
&mut self,
start: usize,
end: usize,
) -> Result<ArrayViewMut2<'_, T>>
pub fn cols_range_mut( &mut self, start: usize, end: usize, ) -> Result<ArrayViewMut2<'_, T>>
Mutable half-open column slice.
Source§impl<T: Clone> Array2<T>
impl<T: Clone> Array2<T>
Sourcepub fn try_filled(shape: [usize; 2], value: T) -> Result<Self>
pub fn try_filled(shape: [usize; 2], value: T) -> Result<Self>
Fallibly fill a new array with value.
Sourcepub fn clone_contiguous(view: ArrayView2<'_, T>) -> Self
pub fn clone_contiguous(view: ArrayView2<'_, T>) -> Self
Clone into compact row-major storage.
Sourcepub fn to_row_major(&self) -> Self
pub fn to_row_major(&self) -> Self
Copy this array into compact row-major storage.
Sourcepub fn to_col_major_vec(&self) -> Vec<T>
pub fn to_col_major_vec(&self) -> Vec<T>
Copy this array into a column-major vector.
Sourcepub fn copy_from_view(&mut self, other: ArrayView2<'_, T>) -> Result<()>
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>
impl<T: Float> Array2<T>
Sourcepub fn try_zeros(shape: [usize; 2]) -> Result<Self>
pub fn try_zeros(shape: [usize; 2]) -> Result<Self>
Fallibly allocate an array filled with zeros.
Sourcepub fn try_ones(shape: [usize; 2]) -> Result<Self>
pub fn try_ones(shape: [usize; 2]) -> Result<Self>
Fallibly allocate an array filled with ones.
Sourcepub fn zeros_like(&self) -> Self
pub fn zeros_like(&self) -> Self
Allocate another array with the same shape, filled with zeros.
Sourcepub fn scaled_into(&self, alpha: T, out: ArrayViewMut2<'_, T>) -> Result<()>
pub fn scaled_into(&self, alpha: T, out: ArrayViewMut2<'_, T>) -> Result<()>
Write self * alpha into out without modifying self.
Sourcepub fn add(&self, other: ArrayView2<'_, T>) -> Result<Self>
pub fn add(&self, other: ArrayView2<'_, T>) -> Result<Self>
Return self + other without modifying either input.
Sourcepub fn add_into(
&self,
other: ArrayView2<'_, T>,
out: ArrayViewMut2<'_, T>,
) -> Result<()>
pub fn add_into( &self, other: ArrayView2<'_, T>, out: ArrayViewMut2<'_, T>, ) -> Result<()>
Write self + other into out without modifying either input.
Sourcepub fn sub(&self, other: ArrayView2<'_, T>) -> Result<Self>
pub fn sub(&self, other: ArrayView2<'_, T>) -> Result<Self>
Return self - other without modifying either input.
Sourcepub fn sub_into(
&self,
other: ArrayView2<'_, T>,
out: ArrayViewMut2<'_, T>,
) -> Result<()>
pub fn sub_into( &self, other: ArrayView2<'_, T>, out: ArrayViewMut2<'_, T>, ) -> Result<()>
Write self - other into out without modifying either input.
Sourcepub fn mul(&self, other: ArrayView2<'_, T>) -> Result<Self>
pub fn mul(&self, other: ArrayView2<'_, T>) -> Result<Self>
Return the elementwise product self * other without modifying either input.
Sourcepub fn mul_into(
&self,
other: ArrayView2<'_, T>,
out: ArrayViewMut2<'_, T>,
) -> Result<()>
pub fn mul_into( &self, other: ArrayView2<'_, T>, out: ArrayViewMut2<'_, T>, ) -> Result<()>
Write the elementwise product into out without modifying either input.
Sourcepub fn hadamard(&self, other: ArrayView2<'_, T>) -> Result<Self>
pub fn hadamard(&self, other: ArrayView2<'_, T>) -> Result<Self>
Return the Hadamard product without modifying either input.
Sourcepub fn hadamard_into(
&self,
other: ArrayView2<'_, T>,
out: ArrayViewMut2<'_, T>,
) -> Result<()>
pub fn hadamard_into( &self, other: ArrayView2<'_, T>, out: ArrayViewMut2<'_, T>, ) -> Result<()>
Write the Hadamard product into out without modifying either input.
Sourcepub fn div(&self, other: ArrayView2<'_, T>) -> Result<Self>
pub fn div(&self, other: ArrayView2<'_, T>) -> Result<Self>
Return the elementwise quotient self / other without modifying either input.
Sourcepub fn div_into(
&self,
other: ArrayView2<'_, T>,
out: ArrayViewMut2<'_, T>,
) -> Result<()>
pub fn div_into( &self, other: ArrayView2<'_, T>, out: ArrayViewMut2<'_, T>, ) -> Result<()>
Write the elementwise quotient into out without modifying either input.
Sourcepub fn axpy_result(&self, alpha: T, x: ArrayView2<'_, T>) -> Result<Self>
pub fn axpy_result(&self, alpha: T, x: ArrayView2<'_, T>) -> Result<Self>
Return self + alpha * x without modifying either input.
Sourcepub fn axpy_into(
&self,
alpha: T,
x: ArrayView2<'_, T>,
out: ArrayViewMut2<'_, T>,
) -> Result<()>
pub fn axpy_into( &self, alpha: T, x: ArrayView2<'_, T>, out: ArrayViewMut2<'_, T>, ) -> Result<()>
Write self + alpha * x into out without modifying either input.
Sourcepub fn matmul(&self, other: ArrayView2<'_, T>) -> Result<Self>
pub fn matmul(&self, other: ArrayView2<'_, T>) -> Result<Self>
Return a matrix product self @ other without modifying either input.
Sourcepub fn matmul_into(
&self,
other: ArrayView2<'_, T>,
out: ArrayViewMut2<'_, T>,
) -> Result<()>
pub fn matmul_into( &self, other: ArrayView2<'_, T>, out: ArrayViewMut2<'_, T>, ) -> Result<()>
Write matrix product self @ other into out without modifying either input.
Sourcepub fn add_assign_view(&mut self, other: ArrayView2<'_, T>) -> Result<()>
pub fn add_assign_view(&mut self, other: ArrayView2<'_, T>) -> Result<()>
In-place addition.
Sourcepub fn sub_assign_view(&mut self, other: ArrayView2<'_, T>) -> Result<()>
pub fn sub_assign_view(&mut self, other: ArrayView2<'_, T>) -> Result<()>
In-place subtraction.
Sourcepub fn mul_assign_view(&mut self, other: ArrayView2<'_, T>) -> Result<()>
pub fn mul_assign_view(&mut self, other: ArrayView2<'_, T>) -> Result<()>
Hadamard product in place.
Sourcepub fn div_assign_view(&mut self, other: ArrayView2<'_, T>) -> Result<()>
pub fn div_assign_view(&mut self, other: ArrayView2<'_, T>) -> Result<()>
In-place elementwise division.
Sourcepub fn axpy(&mut self, alpha: T, x: ArrayView2<'_, T>) -> Result<()>
pub fn axpy(&mut self, alpha: T, x: ArrayView2<'_, T>) -> Result<()>
Compute self += alpha * x.
Sourcepub fn map_inplace(&mut self, f: impl FnMut(T) -> T)
pub fn map_inplace(&mut self, f: impl FnMut(T) -> T)
Map values in place.
Sourcepub fn zip_map_inplace(
&mut self,
other: ArrayView2<'_, T>,
f: impl FnMut(T, T) -> T,
) -> Result<()>
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.
Sourcepub fn zip_map(
&self,
other: ArrayView2<'_, T>,
f: impl FnMut(T, T) -> T,
) -> Result<Self>
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.
Sourcepub fn zip_map_into(
&self,
other: ArrayView2<'_, T>,
out: ArrayViewMut2<'_, T>,
f: impl FnMut(T, T) -> T,
) -> Result<()>
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.
Sourcepub fn fill_uniform(&mut self, seed: u64)
pub fn fill_uniform(&mut self, seed: u64)
Fill with deterministic uniform random values in [0, 1).
Sourcepub fn fill_randn(&mut self, seed: u64)
pub fn fill_randn(&mut self, seed: u64)
Fill with deterministic standard-normal random values.
Sourcepub fn norm_frobenius(&self) -> T
pub fn norm_frobenius(&self) -> T
Frobenius norm.
Sourcepub fn dot(&self, other: ArrayView2<'_, T>) -> Result<T>
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: Float> LinearOperator<T> for Array2<T>
impl<T: Float> LinearOperator<T> for Array2<T>
Source§fn matmat(&self, x: ArrayView2<'_, T>, y: ArrayViewMut2<'_, T>) -> Result<()>
fn matmat(&self, x: ArrayView2<'_, T>, y: ArrayViewMut2<'_, T>) -> Result<()>
Y = A X.Source§fn t_matmat(&self, x: ArrayView2<'_, T>, y: ArrayViewMut2<'_, T>) -> Result<()>
fn t_matmat(&self, x: ArrayView2<'_, T>, y: ArrayViewMut2<'_, T>) -> Result<()>
Y = A^T X.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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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