Skip to main content

Tensor

Struct Tensor 

Source
pub struct Tensor { /* private fields */ }

Implementations§

Source§

impl Tensor

Source

pub fn expand(&self, new_shape: &[usize]) -> Tensor

Source§

impl Tensor

Source

pub fn new(data: &[f32], shape: &[usize]) -> Self

Source

pub fn new_with_storage(storage: Storage, shape: &[usize]) -> Self

Source

pub fn zeros(shape: &[usize]) -> Self

Source

pub fn full(shape: &[usize], value: f32) -> Self

Source

pub fn ones(shape: &[usize]) -> Self

Source

pub fn storage(&self) -> &Storage

Source

pub fn to_wgpu(&self) -> Self

Source

pub fn to_cpu(&self) -> Self

Source

pub fn shape(&self) -> &[usize]

Source

pub fn strides(&self) -> &[usize]

Source

pub fn set_requires_grad(self, requires_grad: bool) -> Self

Source

pub fn set_requires_grad_mut(&mut self, requires_grad: bool)

Source

pub fn requires_grad(&self) -> bool

Source

pub fn data(&self) -> RwLockReadGuard<'_, Vec<f32>>

Source

pub fn data_mut(&self) -> RwLockWriteGuard<'_, Vec<f32>>

Source

pub fn grad(&self) -> Option<Tensor>

Source

pub fn zero_grad(&self)

Source

pub fn accumulate_grad(&self, grad: &Tensor)

Source

pub fn backward(&self)

Source

pub fn backward_step(&self)

Source

pub fn detach(&self) -> Tensor

Returns a new Tensor, detached from the current graph. The result will never require gradient.

Source

pub fn set_op(&mut self, op: Arc<dyn BackwardOp>)

Source

pub fn matmul(&self, rhs: &Tensor) -> Tensor

Source

pub fn t(&self) -> Tensor

Source

pub fn sub(&self, rhs: &Tensor) -> Tensor

Source

pub fn add(&self, rhs: &Tensor) -> Tensor

Source

pub fn neg(&self) -> Tensor

Source

pub fn relu(&self) -> Tensor

Source

pub fn sigmoid(&self) -> Tensor

Source

pub fn tanh(&self) -> Tensor

Source

pub fn softmax(&self, dim: i64) -> Tensor

Source

pub fn conv2d( &self, weight: &Tensor, stride: (usize, usize), padding: (usize, usize), ) -> Tensor

Source

pub fn max_pool2d( &self, kernel_size: (usize, usize), stride: (usize, usize), padding: (usize, usize), ) -> Tensor

Source

pub fn batch_norm2d( &self, gamma: Option<&Tensor>, beta: Option<&Tensor>, running_mean: &Tensor, running_var: &Tensor, training: bool, momentum: f32, eps: f32, ) -> Tensor

Source

pub fn layer_norm( &self, normalized_shape: &[usize], weight: Option<&Tensor>, bias: Option<&Tensor>, eps: f32, ) -> Tensor

Source

pub fn permute(&self, dims: &[usize]) -> Tensor

Source

pub fn transpose(&self, dim0: usize, dim1: usize) -> Tensor

Source

pub fn contiguous(&self) -> Tensor

Source

pub fn is_contiguous(&self) -> bool

Source

pub fn normal_(&self, mean: f32, std: f32)

Source

pub fn uniform_(&self, low: f32, high: f32)

Source

pub fn fill_(&self, value: f32)

Source

pub fn reshape(&self, new_shape: &[usize]) -> Tensor

Source

pub fn mul(&self, rhs: &Tensor) -> Tensor

Source

pub fn div(&self, rhs: &Tensor) -> Tensor

Source

pub fn matmul_relu(&self, rhs: &Tensor) -> Tensor

Source

pub fn sgd_step(&self, grad: &Tensor, lr: f32) -> Tensor

Source

pub fn copy_(&self, src: &Tensor)

Source

pub fn copy_from_slice(&self, src: &[f32])

Trait Implementations§

Source§

impl Add for &Tensor

Source§

type Output = Tensor

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Tensor

Performs the + operation. Read more
Source§

impl Add for Tensor

Source§

type Output = Tensor

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Tensor) -> Tensor

Performs the + operation. Read more
Source§

impl Clone for Tensor

Source§

fn clone(&self) -> Tensor

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tensor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Tensor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div for &Tensor

Source§

type Output = Tensor

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Tensor

Performs the / operation. Read more
Source§

impl Div for Tensor

Source§

type Output = Tensor

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Tensor) -> Tensor

Performs the / operation. Read more
Source§

impl Mul for &Tensor

Source§

type Output = Tensor

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Tensor

Performs the * operation. Read more
Source§

impl Mul for Tensor

Source§

type Output = Tensor

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Tensor) -> Tensor

Performs the * operation. Read more
Source§

impl PartialEq for Tensor

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub for &Tensor

Source§

type Output = Tensor

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Tensor

Performs the - operation. Read more
Source§

impl Sub for Tensor

Source§

type Output = Tensor

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Tensor) -> Tensor

Performs the - operation. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,