Struct CPU

Source
pub struct CPU(/* private fields */);
Expand description

CPU backend

Implementations§

Source§

impl CPU

Source

pub fn tensor<'a>(&'a self, data: impl IntoTensor<&'a Self>) -> Tensor<&'a Self>

Create new tensor

Source

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

Create new tensor using values from standard normal distribution

Source

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

Create new tensor using values from uniform distribution

Source

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

Create new tensor by repeating single value

Source

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

Create new tensor by repeating zeroes

Source

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

Create new tensor by repeating ones

Source

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

Create eye tensor

Source

pub 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

pub fn load( &self, path: impl AsRef<Path>, ) -> Result<Vec<Tensor<&CPU>>, ZyxError>

Load tensors from disk.

Trait Implementations§

Source§

impl Backend for &CPU

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, x: 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
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

Auto Trait Implementations§

§

impl !Freeze for CPU

§

impl !RefUnwindSafe for CPU

§

impl Send for CPU

§

impl !Sync for CPU

§

impl Unpin for CPU

§

impl UnwindSafe for CPU

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<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.