Trait dfdx::tensor::Storage

source ·
pub trait Storage<E>: 'static + Debug + Default + Clone + HasErr {
    type Vec: 'static + Debug + Clone + Send + Sync;

    // Required methods
    fn try_alloc_len(&self, len: usize) -> Result<Self::Vec, Self::Err>;
    fn tensor_to_vec<S: Shape, T>(
        &self,
        tensor: &Tensor<S, E, Self, T>
    ) -> Vec<E>;
    fn len(&self, v: &Self::Vec) -> usize;

    // Provided method
    fn try_alloc_grad(
        &self,
        storage: &Self::Vec
    ) -> Result<Self::Vec, Self::Err> { ... }
}
Expand description

Something that can store nd arrays for a given Shape and Dtype

Required Associated Types§

source

type Vec: 'static + Debug + Clone + Send + Sync

Generic Storage type

Required Methods§

source

fn try_alloc_len(&self, len: usize) -> Result<Self::Vec, Self::Err>

source

fn tensor_to_vec<S: Shape, T>(&self, tensor: &Tensor<S, E, Self, T>) -> Vec<E>

source

fn len(&self, v: &Self::Vec) -> usize

Provided Methods§

source

fn try_alloc_grad(&self, storage: &Self::Vec) -> Result<Self::Vec, Self::Err>

Allocates a gradient for the given nd array

Implementors§

source§

impl<E: Unit> Storage<E> for Cpu

§

type Vec = CachableVec<E>

source§

impl<E: Unit> Storage<E> for Cuda

§

type Vec = CachableCudaSlice<E>