Struct NDArray

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

Structure representing an owned n-dimensional array. The underlying storage is in row-major order.

Implementations§

Source§

impl<T: Clone> NDArray<T>

Source

pub fn new(shape: &[usize], v: T) -> NDArray<T>

Allocate a new array of the specified shape with all elements initialized with the value v.

Source

pub fn copy<R: NDData<T>>(data: &R) -> NDArray<T>

Allocate a new array which is a copy of data.

Source

pub fn from_slice(shape: &[usize], data: &[T]) -> NDArray<T>

Allocate a new array from a row-major order contiguous array and a shape. The size of the shape (product of all its elements) must be equal to the array length.

Source

pub fn cast<U>(data: &dyn NDData<U>) -> NDArray<T>
where T: Copy, U: Cast<T> + Copy,

Allocate a new array where each element has been casted from data.

Source

pub fn reshape(&mut self, new_shape: &[usize])

Reshape this NDArray. The size of the new shape (product of all its elements) must be equal to the size of the current shape.

Source

pub fn insert(&mut self, dim: usize, pos: usize, other: &dyn NDData<T>)

Insert another NDData of the same dimensionality in this NDArray. The insertion is made at the position pos in the dimension dim. The shape of NDData need to be the same as this NDArray in every dimension except for the insertion dimension.

Source

pub fn extract(&self, start: &[usize], end: &[usize]) -> NDArray<T>

Extract a sub part of this NDArray as a new NDArray. start and end are two index of the same dimensionality ad this NDArray.

Source

pub fn remove(&mut self, dim: usize, start: usize, end: usize)

Remove a part of this NDArray. The removal is made in dimension dim from the position start until end (not included). This can be seen as the opposite operation of insert.

Source

pub fn split(&mut self, dim: usize, pos: usize) -> NDArray<T>

Split this NDArray at position pos of dimension dim. The lower indices are kept in dim while the upper indices are returned. This is in fact an extract operation followed by a remove operation.

Trait Implementations§

Source§

impl<'a, 'b, T: Clone + Display + From<f32>, R: NDData<T> + Sized> Add<&'a R> for &'b NDArray<T>
where NDArray<T>: Blas<T>,

Source§

type Output = NDArray<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &'a R) -> NDArray<T>

Performs the + operation. Read more
Source§

impl<'a, T: Clone + Display + From<f32>, R: NDData<T> + Sized> AddAssign<&'a R> for NDArray<T>
where NDArray<T>: Blas<T>,

Source§

fn add_assign(&mut self, rhs: &'a R)

Performs the += operation. Read more
Source§

impl<'b, T> Index<&'b [usize]> for NDArray<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index<'c>(&'c self, idx: &'b [usize]) -> &'c T

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

impl<'b, T> Index<&'b [usize; 1]> for NDArray<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index<'c>(&'c self, idx: &'b [usize; 1]) -> &'c T

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

impl<'b, T> Index<&'b [usize; 2]> for NDArray<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index<'c>(&'c self, idx: &'b [usize; 2]) -> &'c T

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

impl<'b, T> Index<&'b [usize; 3]> for NDArray<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index<'c>(&'c self, idx: &'b [usize; 3]) -> &'c T

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

impl<'b, T: Clone + Display> IndexMut<&'b [usize]> for NDArray<T>

Source§

fn index_mut<'c>(&'c mut self, idx: &[usize]) -> &'c mut T

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

impl<'b, T: Clone + Display> IndexMut<&'b [usize; 1]> for NDArray<T>

Source§

fn index_mut<'c>(&'c mut self, idx: &[usize; 1]) -> &'c mut T

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

impl<'b, T: Clone + Display> IndexMut<&'b [usize; 2]> for NDArray<T>

Source§

fn index_mut<'c>(&'c mut self, idx: &[usize; 2]) -> &'c mut T

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

impl<'b, T: Clone + Display> IndexMut<&'b [usize; 3]> for NDArray<T>

Source§

fn index_mut<'c>(&'c mut self, idx: &[usize; 3]) -> &'c mut T

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

impl<'a, 'b, T: Clone + Display + From<f32>, R: NDData<T> + Sized> Mul<&'a R> for &'b NDArray<T>
where NDArray<T>: Blas<T>,

Source§

type Output = NDArray<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &'a R) -> NDArray<T>

Performs the * operation. Read more
Source§

impl<'a, T: Clone + Display + From<f32>, I: NDData<T> + Sized> MulAssign<&'a I> for NDArray<T>
where NDArray<T>: Blas<T> + NDData<T>,

Source§

fn mul_assign(&mut self, rhs: &'a I)

Performs the *= operation. Read more
Source§

impl<T> NDData<T> for NDArray<T>

Source§

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

Return a slice of length N where each element is the length of the dimension. For a 2 dimensional matrix, the first dimension is the number of rows and the second dimension is the number of columns.
Source§

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

Return a slice of length N where each element is the stride of the dimension.
Source§

fn get_data(&self) -> &[T]

Return the underlying storage array as a slice.
Source§

fn dim(&self) -> usize

Return N, the number of dimensions.
Source§

fn size(&self) -> usize

Return the total number of element of the N-dimensional array.
Source§

fn idx<'a>(&'a self, idx: &[usize]) -> &'a T

Take a slice of length N representing an N-dimensional index in the array and return a reference to the element at this position.
Source§

impl<T: Clone + Display> NDDataMut<T> for NDArray<T>

Source§

fn transpose(&mut self)

The transpose function of a NDArray allow to transpose any shape.

Source§

fn get_data_mut(&mut self) -> &mut [T]

Return the underlying storage array as a mutable slice.
Source§

fn idx_mut<'a>(&'a mut self, idx: &[usize]) -> &'a mut T

Take a slice of length N representing an -index in the array and return a mutable reference to the element at this position.
Source§

fn assign(&mut self, other: &dyn NDData<T>)

Assign another NDData to the NDDataMut. The shapes need to be identical.
Source§

impl<'a, T: 'a> NDSliceable<'a, T> for NDArray<T>

Source§

fn slice(&'a self, idx: &[usize]) -> NDSlice<'a, T>

Take a slice of length < N representing the sub slice index and return immutable borrow of the sub slice as an NDSlice. Because the storage is in row-major order and the slice need to be contiguous in the underlying storage array it means, for example, only the rows of a matrix can be borrowed.
Source§

impl<'a, T: 'a> NDSliceableMut<'a, T> for NDArray<T>

Source§

fn slice_mut(&'a mut self, idx: &[usize]) -> NDSliceMut<'a, T>

Take a slice of length < N representing the sub slice index and return immutable borrow of the sub slice as an NDSlice. Because the storage is in row-major order and the slice need to be contiguous in the underlying storage array it means, for example, only the rows of a matrix can be borrowed.
Source§

impl<T: PartialEq, O: NDData<T> + Sized> PartialEq<O> for NDArray<T>

Source§

fn eq(&self, other: &O) -> 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> SizedBuffer for NDArray<T>

Source§

impl<T: Clone + Display> SizedBufferMut for NDArray<T>
where NDArray<T>: SizedBuffer,

Source§

unsafe fn get_raw_ptr_mut(&mut self) -> *mut c_void

Source§

impl<'a, 'b, T: Clone + Display + From<f32>, R: NDData<T> + Sized> Sub<&'a R> for &'b NDArray<T>
where NDArray<T>: Blas<T>,

Source§

type Output = NDArray<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &'a R) -> NDArray<T>

Performs the - operation. Read more
Source§

impl<'a, T: Clone + Display + From<f32>, R: NDData<T> + Sized> SubAssign<&'a R> for NDArray<T>
where NDArray<T>: Blas<T>,

Source§

fn sub_assign(&mut self, rhs: &'a R)

Performs the -= operation. Read more
Source§

impl<T: Eq> Eq for NDArray<T>

Auto Trait Implementations§

§

impl<T> Freeze for NDArray<T>

§

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

§

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

§

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

§

impl<T> Unpin for NDArray<T>

§

impl<T> UnwindSafe for NDArray<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<R> Blas<c32> for R
where R: NDDataMut<c32>,

Source§

fn asum(&self) -> c32

Compute an element-wise sum of the N-dimensional array.
Source§

fn nrm2(&self) -> c32

Compute the euclidian norm of the N-dimensional array.
Source§

fn scal(&mut self, a: c32)

Scale the N-dimensional array by a factor a.
Source§

fn axpy(&mut self, a: c32, x: &dyn NDData<c32>)

Compute y += a * x where y is this array, x is a N-dimensional array of the same size as y and a is a scalar.
Source§

fn dot(&self, x: &dyn NDData<c32>) -> c32

Compute the dot product of this array and x.
Source§

fn gemv( &mut self, alpha: c32, a: &dyn NDData<c32>, x: &dyn NDData<c32>, beta: c32, )

Compute y = alpha * a * x + beta * y where y is this array, x is a one dimensional array, a a two dimensional array and alpha and beta are scalars. Automatically determine whether a need to be transposed.
Source§

fn gemm( &mut self, alpha: c32, a: &dyn NDData<c32>, b: &dyn NDData<c32>, beta: c32, )

Compute y = alpha * a * x + beta * y where y is this array, a and b are two dimensional arrays and alpha and beta are scalars. Automatically determine whether a and b need to be transposed.
Source§

impl<R> Blas<c64> for R
where R: NDDataMut<c64>,

Source§

fn asum(&self) -> c64

Compute an element-wise sum of the N-dimensional array.
Source§

fn nrm2(&self) -> c64

Compute the euclidian norm of the N-dimensional array.
Source§

fn scal(&mut self, a: c64)

Scale the N-dimensional array by a factor a.
Source§

fn axpy(&mut self, a: c64, x: &dyn NDData<c64>)

Compute y += a * x where y is this array, x is a N-dimensional array of the same size as y and a is a scalar.
Source§

fn dot(&self, x: &dyn NDData<c64>) -> c64

Compute the dot product of this array and x.
Source§

fn gemv( &mut self, alpha: c64, a: &dyn NDData<c64>, x: &dyn NDData<c64>, beta: c64, )

Compute y = alpha * a * x + beta * y where y is this array, x is a one dimensional array, a a two dimensional array and alpha and beta are scalars. Automatically determine whether a need to be transposed.
Source§

fn gemm( &mut self, alpha: c64, a: &dyn NDData<c64>, b: &dyn NDData<c64>, beta: c64, )

Compute y = alpha * a * x + beta * y where y is this array, a and b are two dimensional arrays and alpha and beta are scalars. Automatically determine whether a and b need to be transposed.
Source§

impl<R> Blas<f32> for R
where R: NDDataMut<f32>,

Source§

fn asum(&self) -> f32

Compute an element-wise sum of the N-dimensional array.
Source§

fn nrm2(&self) -> f32

Compute the euclidian norm of the N-dimensional array.
Source§

fn scal(&mut self, a: f32)

Scale the N-dimensional array by a factor a.
Source§

fn axpy(&mut self, a: f32, x: &dyn NDData<f32>)

Compute y += a * x where y is this array, x is a N-dimensional array of the same size as y and a is a scalar.
Source§

fn dot(&self, x: &dyn NDData<f32>) -> f32

Compute the dot product of this array and x.
Source§

fn gemv( &mut self, alpha: f32, a: &dyn NDData<f32>, x: &dyn NDData<f32>, beta: f32, )

Compute y = alpha * a * x + beta * y where y is this array, x is a one dimensional array, a a two dimensional array and alpha and beta are scalars. Automatically determine whether a need to be transposed.
Source§

fn gemm( &mut self, alpha: f32, a: &dyn NDData<f32>, b: &dyn NDData<f32>, beta: f32, )

Compute y = alpha * a * x + beta * y where y is this array, a and b are two dimensional arrays and alpha and beta are scalars. Automatically determine whether a and b need to be transposed.
Source§

impl<R> Blas<f64> for R
where R: NDDataMut<f64>,

Source§

fn asum(&self) -> f64

Compute an element-wise sum of the N-dimensional array.
Source§

fn nrm2(&self) -> f64

Compute the euclidian norm of the N-dimensional array.
Source§

fn scal(&mut self, a: f64)

Scale the N-dimensional array by a factor a.
Source§

fn axpy(&mut self, a: f64, x: &dyn NDData<f64>)

Compute y += a * x where y is this array, x is a N-dimensional array of the same size as y and a is a scalar.
Source§

fn dot(&self, x: &dyn NDData<f64>) -> f64

Compute the dot product of this array and x.
Source§

fn gemv( &mut self, alpha: f64, a: &dyn NDData<f64>, x: &dyn NDData<f64>, beta: f64, )

Compute y = alpha * a * x + beta * y where y is this array, x is a one dimensional array, a a two dimensional array and alpha and beta are scalars. Automatically determine whether a need to be transposed.
Source§

fn gemm( &mut self, alpha: f64, a: &dyn NDData<f64>, b: &dyn NDData<f64>, beta: f64, )

Compute y = alpha * a * x + beta * y where y is this array, a and b are two dimensional arrays and alpha and beta are scalars. Automatically determine whether a and b need to be transposed.
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> 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, 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.