Trait Backend

Source
pub trait Backend: Copy {
Show 16 methods // Required methods fn plot_graph<'a, B: Backend + 'a>( self, tensors: impl IntoIterator<Item = &'a Tensor<B>>, ) -> String; fn randn( self, shape: impl Into<Shape>, dtype: DType, ) -> Result<Tensor<Self>, ZyxError>; fn uniform( self, shape: impl Into<Shape>, range: Range<impl Scalar>, ) -> Result<Tensor<Self>, ZyxError>; fn shape(self, x: Id) -> Shape; fn dtype(self, x: Id) -> DType; fn backward( self, x: Id, sources: &BTreeSet<Id>, ) -> Result<BTreeMap<Id, Id>, ZyxError>; fn load<T: Scalar>(self, id: Id) -> Result<Vec<T>, ZyxError>; fn store<T: Scalar, IT>(self, iter: IT) -> Result<Id, ZyxError> where IT: IntoIterator<Item = T>, IT::IntoIter: ExactSizeIterator; fn push(self, node: Node) -> Result<Id, ZyxError>; fn release(self, x: Id) -> Result<(), ZyxError>; fn retain(self, x: Id); // Provided methods fn tensor( self, data: impl IntoTensor<Self>, ) -> Result<Tensor<Self>, ZyxError> { ... } fn full( self, shape: impl Into<Shape>, value: impl Scalar, ) -> Result<Tensor<Self>, ZyxError> { ... } fn zeros( self, shape: impl Into<Shape>, dtype: DType, ) -> Result<Tensor<Self>, ZyxError> { ... } fn ones( self, shape: impl Into<Shape>, dtype: DType, ) -> Result<Tensor<Self>, ZyxError> { ... } fn eye(self, n: usize, dtype: DType) -> Result<Tensor<Self>, ZyxError> { ... }
}
Expand description

Backend for tensors. Tensor requires that all backends implement this trait and only this trait.

Required Methods§

Source

fn plot_graph<'a, B: Backend + 'a>( self, tensors: impl IntoIterator<Item = &'a Tensor<B>>, ) -> String

Create graph of operations between tensors in dot format for visualization

Source

fn randn( self, shape: impl Into<Shape>, dtype: DType, ) -> Result<Tensor<Self>, ZyxError>

Create new tensor using values from standard normal distribution

Source

fn uniform( self, shape: impl Into<Shape>, range: Range<impl Scalar>, ) -> Result<Tensor<Self>, ZyxError>

Create new tensor using values from uniform distribution

Source

fn shape(self, x: Id) -> Shape

Get shape if tensor x

Source

fn dtype(self, x: Id) -> DType

Get dtype of tensor x

Source

fn backward( self, x: Id, sources: &BTreeSet<Id>, ) -> Result<BTreeMap<Id, Id>, ZyxError>

Calculate derivatives of x w.r.t. sources. Returns map source id -> gradient id

Source

fn load<T: Scalar>(self, id: Id) -> Result<Vec<T>, ZyxError>

Returns iterator over data stored in backend

Source

fn store<T: Scalar, IT>(self, iter: IT) -> Result<Id, ZyxError>
where IT: IntoIterator<Item = T>, IT::IntoIter: ExactSizeIterator,

Store iterator into backend as tensor

Source

fn push(self, node: Node) -> Result<Id, ZyxError>

Create new tensor from given operation

Source

fn release(self, x: Id) -> Result<(), ZyxError>

Decrease reference count of tensor

Source

fn retain(self, x: Id)

Increase reference count of tensor

Provided Methods§

Source

fn tensor(self, data: impl IntoTensor<Self>) -> Result<Tensor<Self>, ZyxError>

Create new tensor

Source

fn full( self, shape: impl Into<Shape>, value: impl Scalar, ) -> Result<Tensor<Self>, ZyxError>

Create new tensor by repeating single value

Source

fn zeros( self, shape: impl Into<Shape>, dtype: DType, ) -> Result<Tensor<Self>, ZyxError>

Create new tensor by repeating zeroes

Source

fn ones( self, shape: impl Into<Shape>, dtype: DType, ) -> Result<Tensor<Self>, ZyxError>

Create new tensor by repeating ones

Source

fn eye(self, n: usize, dtype: DType) -> Result<Tensor<Self>, ZyxError>

Create eye tensor

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§