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§
Sourcefn plot_graph<'a, B: Backend + 'a>(
self,
tensors: impl IntoIterator<Item = &'a Tensor<B>>,
) -> String
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
Sourcefn randn(
self,
shape: impl Into<Shape>,
dtype: DType,
) -> Result<Tensor<Self>, ZyxError>
fn randn( self, shape: impl Into<Shape>, dtype: DType, ) -> Result<Tensor<Self>, ZyxError>
Create new tensor using values from standard normal distribution
Sourcefn uniform(
self,
shape: impl Into<Shape>,
range: Range<impl Scalar>,
) -> Result<Tensor<Self>, ZyxError>
fn uniform( self, shape: impl Into<Shape>, range: Range<impl Scalar>, ) -> Result<Tensor<Self>, ZyxError>
Create new tensor using values from uniform distribution
Sourcefn backward(
self,
x: Id,
sources: &BTreeSet<Id>,
) -> Result<BTreeMap<Id, Id>, ZyxError>
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
Sourcefn load<T: Scalar>(self, id: Id) -> Result<Vec<T>, ZyxError>
fn load<T: Scalar>(self, id: Id) -> Result<Vec<T>, ZyxError>
Returns iterator over data stored in backend
Provided Methods§
Sourcefn tensor(self, data: impl IntoTensor<Self>) -> Result<Tensor<Self>, ZyxError>
fn tensor(self, data: impl IntoTensor<Self>) -> Result<Tensor<Self>, ZyxError>
Create new tensor
Sourcefn full(
self,
shape: impl Into<Shape>,
value: impl Scalar,
) -> Result<Tensor<Self>, ZyxError>
fn full( self, shape: impl Into<Shape>, value: impl Scalar, ) -> Result<Tensor<Self>, ZyxError>
Create new tensor by repeating single value
Sourcefn zeros(
self,
shape: impl Into<Shape>,
dtype: DType,
) -> Result<Tensor<Self>, ZyxError>
fn zeros( self, shape: impl Into<Shape>, dtype: DType, ) -> Result<Tensor<Self>, ZyxError>
Create new tensor by repeating zeroes
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.