Struct zyx_cpu::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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

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

§

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

§

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.