pub struct CpuBackend;Expand description
Re-export CPU backend. CPU backend. Implements Backend by running operations on CPU via iterators.
Trait Implementations§
Source§impl Backend for CpuBackend
impl Backend for CpuBackend
Source§type Storage = CpuStorage
type Storage = CpuStorage
The storage type for this backend.
Source§fn zeros(
shape: &Shape,
dtype: DType,
_device: &CpuDevice,
) -> Result<CpuStorage, Error>
fn zeros( shape: &Shape, dtype: DType, _device: &CpuDevice, ) -> Result<CpuStorage, Error>
Allocate storage filled with zeros.
Source§fn ones(
shape: &Shape,
dtype: DType,
_device: &CpuDevice,
) -> Result<CpuStorage, Error>
fn ones( shape: &Shape, dtype: DType, _device: &CpuDevice, ) -> Result<CpuStorage, Error>
Allocate storage filled with ones.
Source§fn full(
shape: &Shape,
val: f64,
dtype: DType,
_device: &CpuDevice,
) -> Result<CpuStorage, Error>
fn full( shape: &Shape, val: f64, dtype: DType, _device: &CpuDevice, ) -> Result<CpuStorage, Error>
Allocate storage filled with a constant value.
Source§fn from_f64_slice(
data: &[f64],
dtype: DType,
_device: &CpuDevice,
) -> Result<CpuStorage, Error>
fn from_f64_slice( data: &[f64], dtype: DType, _device: &CpuDevice, ) -> Result<CpuStorage, Error>
Create storage from a flat f64 slice, converting to the target dtype.
Source§fn rand_uniform(
shape: &Shape,
dtype: DType,
_device: &CpuDevice,
) -> Result<CpuStorage, Error>
fn rand_uniform( shape: &Shape, dtype: DType, _device: &CpuDevice, ) -> Result<CpuStorage, Error>
Create storage with random uniform values in [0, 1).
Source§fn rand_normal(
shape: &Shape,
dtype: DType,
_device: &CpuDevice,
) -> Result<CpuStorage, Error>
fn rand_normal( shape: &Shape, dtype: DType, _device: &CpuDevice, ) -> Result<CpuStorage, Error>
Create storage with random normal values (mean=0, std=1).
Source§fn binary_op(
op: BinaryOp,
lhs: &CpuStorage,
lhs_layout: &Layout,
rhs: &CpuStorage,
rhs_layout: &Layout,
) -> Result<CpuStorage, Error>
fn binary_op( op: BinaryOp, lhs: &CpuStorage, lhs_layout: &Layout, rhs: &CpuStorage, rhs_layout: &Layout, ) -> Result<CpuStorage, Error>
Apply a binary op element-wise: result[i] = op(lhs[i], rhs[i]).
The layouts handle broadcasting and non-contiguous access.
Source§fn unary_op(
op: UnaryOp,
input: &CpuStorage,
layout: &Layout,
) -> Result<CpuStorage, Error>
fn unary_op( op: UnaryOp, input: &CpuStorage, layout: &Layout, ) -> Result<CpuStorage, Error>
Apply a unary op element-wise: result[i] = op(input[i]).
Source§fn reduce_op(
op: ReduceOp,
input: &CpuStorage,
layout: &Layout,
dims: &[usize],
keep_dim: bool,
) -> Result<CpuStorage, Error>
fn reduce_op( op: ReduceOp, input: &CpuStorage, layout: &Layout, dims: &[usize], keep_dim: bool, ) -> Result<CpuStorage, Error>
Reduce along specific dimensions.
If
dims is empty, reduce over all elements.Source§fn matmul(
lhs: &CpuStorage,
lhs_layout: &Layout,
rhs: &CpuStorage,
rhs_layout: &Layout,
) -> Result<CpuStorage, Error>
fn matmul( lhs: &CpuStorage, lhs_layout: &Layout, rhs: &CpuStorage, rhs_layout: &Layout, ) -> Result<CpuStorage, Error>
General matrix multiply: C = A @ B.
Supports batched matmul for tensors with rank > 2.
Source§fn to_contiguous(
input: &CpuStorage,
layout: &Layout,
) -> Result<CpuStorage, Error>
fn to_contiguous( input: &CpuStorage, layout: &Layout, ) -> Result<CpuStorage, Error>
Make a contiguous copy of the storage following the given layout.
If the layout is already contiguous, this may just clone the storage.
Source§fn to_f64_vec(input: &CpuStorage, layout: &Layout) -> Result<Vec<f64>, Error>
fn to_f64_vec(input: &CpuStorage, layout: &Layout) -> Result<Vec<f64>, Error>
Copy data from this storage to a Vec on the host (for inspection).
Source§fn cmp_op(
op: CmpOp,
lhs: &CpuStorage,
lhs_layout: &Layout,
rhs: &CpuStorage,
rhs_layout: &Layout,
) -> Result<CpuStorage, Error>
fn cmp_op( op: CmpOp, lhs: &CpuStorage, lhs_layout: &Layout, rhs: &CpuStorage, rhs_layout: &Layout, ) -> Result<CpuStorage, Error>
Element-wise comparison, returns a u8 storage (0 or 1).
Source§fn affine(
input: &CpuStorage,
layout: &Layout,
mul: f64,
add: f64,
) -> Result<CpuStorage, Error>
fn affine( input: &CpuStorage, layout: &Layout, mul: f64, add: f64, ) -> Result<CpuStorage, Error>
Affine transform: result = input * mul + add.
Used for normalization and other fused operations.
Source§fn index_select(
input: &CpuStorage,
input_layout: &Layout,
indices: &CpuStorage,
indices_layout: &Layout,
dim: usize,
) -> Result<CpuStorage, Error>
fn index_select( input: &CpuStorage, input_layout: &Layout, indices: &CpuStorage, indices_layout: &Layout, dim: usize, ) -> Result<CpuStorage, Error>
Gather elements along a dimension using index tensor.
Source§fn powf(
input: &CpuStorage,
layout: &Layout,
exponent: f64,
) -> Result<CpuStorage, Error>
fn powf( input: &CpuStorage, layout: &Layout, exponent: f64, ) -> Result<CpuStorage, Error>
Element-wise power: result[i] = input[i] ^ exponent.
Source§fn clamp(
input: &CpuStorage,
layout: &Layout,
min: f64,
max: f64,
) -> Result<CpuStorage, Error>
fn clamp( input: &CpuStorage, layout: &Layout, min: f64, max: f64, ) -> Result<CpuStorage, Error>
Element-wise clamp: result[i] = clamp(input[i], min, max).
Source§fn where_cond(
mask: &CpuStorage,
mask_layout: &Layout,
on_true: &CpuStorage,
on_true_layout: &Layout,
on_false: &CpuStorage,
on_false_layout: &Layout,
) -> Result<CpuStorage, Error>
fn where_cond( mask: &CpuStorage, mask_layout: &Layout, on_true: &CpuStorage, on_true_layout: &Layout, on_false: &CpuStorage, on_false_layout: &Layout, ) -> Result<CpuStorage, Error>
Element-wise conditional: result[i] = if mask[i] != 0 { on_true[i] } else { on_false[i] }.
Source§fn gather(
input: &CpuStorage,
input_layout: &Layout,
index: &CpuStorage,
index_layout: &Layout,
dim: usize,
) -> Result<CpuStorage, Error>
fn gather( input: &CpuStorage, input_layout: &Layout, index: &CpuStorage, index_layout: &Layout, dim: usize, ) -> Result<CpuStorage, Error>
Source§fn cat(
inputs: &[(&CpuStorage, &Layout)],
out_shape: &Shape,
dim: usize,
) -> Result<CpuStorage, Error>
fn cat( inputs: &[(&CpuStorage, &Layout)], out_shape: &Shape, dim: usize, ) -> Result<CpuStorage, Error>
Concatenate multiple storages along
dim into a single contiguous storage.
Each entry is (storage, layout) so non-contiguous inputs are handled correctly.
out_shape is the pre-validated output shape.Source§impl Clone for CpuBackend
impl Clone for CpuBackend
Source§fn clone(&self) -> CpuBackend
fn clone(&self) -> CpuBackend
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CpuBackend
impl RefUnwindSafe for CpuBackend
impl Send for CpuBackend
impl Sync for CpuBackend
impl Unpin for CpuBackend
impl UnwindSafe for CpuBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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