Skip to main content

NdArray

Trait NdArray 

Source
pub trait NdArray {
    // Required methods
    fn shape(&self) -> Result<Shape>;
    fn to_cpu_storage(&self) -> HostBuffer;
}
Expand description

Trait for host array-like values that describe their shape and yield CPU storage.

Implemented for scalars, arrays, slices, and nested vecs up to 4 dimensions. It lets array-like Rust values report the Shape their data describes and materialize into a HostBuffer — the raw material a lazy tensor is built from.

§Example

use fuel_tensor::NdArray;
// Scalars, arrays, and nested arrays all implement `NdArray` and report
// the shape their data describes.
assert_eq!(3.14f32.shape()?.dims(), &[] as &[usize]);
assert_eq!((&[1f32, 2., 3.]).shape()?.dims(), &[3]);
assert_eq!((&[[1f32, 2.], [3., 4.]]).shape()?.dims(), &[2, 2]);

Required Methods§

Source

fn shape(&self) -> Result<Shape>

Returns the shape determined by this array-like value.

Source

fn to_cpu_storage(&self) -> HostBuffer

Converts this value into CPU storage.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<S: WithDType, const N1: usize, const N2: usize, const N3: usize, const N4: usize> NdArray for &[[[[S; N4]; N3]; N2]; N1]

Source§

impl<S: WithDType, const N1: usize, const N2: usize, const N3: usize> NdArray for &[[[S; N3]; N2]; N1]

Source§

impl<S: WithDType, const N: usize, const M: usize> NdArray for &[[S; N]; M]

Source§

impl<S: WithDType, const N: usize> NdArray for &[S; N]

Source§

impl<S: WithDType> NdArray for &[S]

Source§

impl<S: WithDType> NdArray for Vec<&[S]>

Source§

impl<S: WithDType> NdArray for Vec<S>

Source§

impl<S: WithDType> NdArray for Vec<Vec<S>>

Source§

impl<S: WithDType> NdArray for Vec<Vec<Vec<S>>>

Source§

impl<S: WithDType> NdArray for Vec<Vec<Vec<Vec<S>>>>

Implementors§

Source§

impl<S: WithDType> NdArray for S