Struct rai_core::Tensor

source ·
pub struct Tensor(/* private fields */);

Implementations§

source§

impl Tensor

source

pub fn new( backend: impl Into<Box<dyn Backend>>, dtype: DType, shape: impl Shape, primitive: impl Into<Box<dyn Primitive>>, inputs: impl Into<Vec<Tensor>> ) -> Self

source

pub fn id(&self) -> usize

source

pub fn backend(&self) -> &dyn Backend

source

pub fn dtype(&self) -> DType

source

pub fn primitive(&self) -> &dyn Primitive

source

pub fn inputs(&self) -> impl Deref<Target = [Tensor]> + '_

source

pub fn full( val: f64, shape: impl Shape, dtype: DType, backend: impl Into<Box<dyn Backend>> + Debug ) -> Tensor

source

pub fn ones( shape: impl Shape, dtype: DType, backend: impl Into<Box<dyn Backend>> + Debug ) -> Tensor

source

pub fn zeros( shape: impl Shape, dtype: DType, backend: impl Into<Box<dyn Backend>> + Debug ) -> Tensor

source

pub fn full_like(&self, val: f64) -> Tensor

source

pub fn zeros_like(&self) -> Tensor

source

pub fn ones_like(&self) -> Tensor

source

pub fn normal( shape: impl Shape, dtype: DType, backend: impl Into<Box<dyn Backend>> + Debug ) -> Tensor

source

pub fn arange<T: ArangeArgs>( args: T, backend: impl Into<Box<dyn Backend>> + Debug ) -> Tensor

source

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

source

pub fn eq<T: AsRef<Tensor>>(&self, rhs: T) -> Tensor

source

pub fn ne<T: AsRef<Tensor>>(&self, rhs: T) -> Tensor

source

pub fn gt<T: AsRef<Tensor>>(&self, rhs: T) -> Tensor

source

pub fn ge<T: AsRef<Tensor>>(&self, rhs: T) -> Tensor

source

pub fn lt<T: AsRef<Tensor>>(&self, rhs: T) -> Tensor

source

pub fn le<T: AsRef<Tensor>>(&self, rhs: T) -> Tensor

source

pub fn maximum<T: AsRef<Tensor>>(&self, rhs: T) -> Tensor

source

pub fn t(&self) -> Tensor

source

pub fn transpose(&self, dims: impl Into<Vec<usize>> + Debug) -> Tensor

source

pub fn broadcast_to(&self, shape: impl Shape) -> Tensor

source

pub fn reshape(&self, shape: impl Shape) -> Tensor

source

pub fn add<T>(&self, rhs: T) -> Tensor
where for<'a> &'a Self: Add<T, Output = Tensor>,

source

pub fn mul<T>(&self, rhs: T) -> Tensor
where for<'a> &'a Self: Mul<T, Output = Tensor>,

source

pub fn sin(&self) -> Tensor

source

pub fn cos(&self) -> Tensor

source

pub fn square(&self) -> Tensor

source

pub fn sqrt(&self) -> Tensor

source

pub fn rsqrt(&self) -> Tensor

source

pub fn sign(&self) -> Tensor

source

pub fn abs(&self) -> Tensor

source

pub fn exp(&self) -> Tensor

source

pub fn log(&self) -> Tensor

source

pub fn log2(&self) -> Tensor

source

pub fn log10(&self) -> Tensor

source

pub fn sum<T: ReduceArgs>(&self, args: T) -> Tensor

source

pub fn max<T: ReduceArgs>(&self, args: T) -> Tensor

source

pub fn min<T: ReduceArgs>(&self, args: T) -> Tensor

source

pub fn mean<T: ReduceArgs>(&self, args: T) -> Tensor

source

pub fn as_type(&self, dtype: DType) -> Tensor

source

pub fn softmax<D: Dim>(&self, d: D) -> Tensor

source

pub fn log_softmax<D: Dim>(&self, d: D) -> Tensor

source

pub fn relu(&self) -> Tensor

source

pub fn jvp(&self, tangent_cache: &mut HashMap<usize, Tensor>) -> Tensor

source

pub fn vjp(&self, cotangent_cache: &mut HashMap<usize, Tensor>)

source

pub fn dot_graph(&self) -> String

source

pub fn detach(&self)

source

pub fn replace_data(&self, rhs: Tensor)

source

pub fn set_data<T: TensorLike + 'static>(&self, data: T)

source

pub fn get_data<T>(&self) -> Option<impl Deref<Target = T> + '_>
where T: 'static,

source

pub fn is_evaluated(&self) -> bool

Trait Implementations§

source§

impl<'a, 'b> Add<&'b Tensor> for &'a Tensor

§

type Output = Tensor

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<'a> Add<&'a Tensor> for Tensor

§

type Output = Tensor

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl<'a> Add<&'a Tensor> for f32

§

type Output = Tensor

The resulting type after applying the + operator.
source§

fn add(self, rhs: &'a Tensor) -> Self::Output

Performs the + operation. Read more
source§

impl<'a> Add<&'a Tensor> for f64

§

type Output = Tensor

The resulting type after applying the + operator.
source§

fn add(self, rhs: &'a Tensor) -> Self::Output

Performs the + operation. Read more
source§

impl<'a, T> Add<T> for &'a Tensor
where T: 'static + ElemType,

§

type Output = Tensor

The resulting type after applying the + operator.
source§

fn add(self, rhs: T) -> Self::Output

Performs the + operation. Read more
source§

impl<T> Add<T> for Tensor
where T: 'static + ElemType,

§

type Output = Tensor

The resulting type after applying the + operator.
source§

fn add(self, rhs: T) -> Self::Output

Performs the + operation. Read more
source§

impl<'a> Add<Tensor> for &'a Tensor

§

type Output = Tensor

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Tensor> for f32

§

type Output = Tensor

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add<Tensor> for f64

§

type Output = Tensor

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl Add for Tensor

§

type Output = Tensor

The resulting type after applying the + operator.
source§

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

Performs the + operation. Read more
source§

impl AsRef<Tensor> for Tensor

source§

fn as_ref(&self) -> &Tensor

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Tensor

source§

fn clone(&self) -> Tensor

Returns a copy 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 Differentiable for Tensor

§

type Tensors = Tensor

§

type Gradient = Tensor

source§

fn tensors(&self) -> Self::Tensors

source§

fn grad( tensor: &Self::Tensors, grad_map: &HashMap<usize, Tensor> ) -> Self::Gradient

source§

fn grad_map( tensor: &Self::Tensors, grad: Tensor, out: &mut HashMap<usize, Tensor> )

source§

impl Display for Tensor

source§

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

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

impl<'a, 'b> Div<&'b Tensor> for &'a Tensor

§

type Output = Tensor

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl<'a> Div<&'a Tensor> for Tensor

§

type Output = Tensor

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl<'a> Div<&'a Tensor> for f32

§

type Output = Tensor

The resulting type after applying the / operator.
source§

fn div(self, rhs: &'a Tensor) -> Self::Output

Performs the / operation. Read more
source§

impl<'a> Div<&'a Tensor> for f64

§

type Output = Tensor

The resulting type after applying the / operator.
source§

fn div(self, rhs: &'a Tensor) -> Self::Output

Performs the / operation. Read more
source§

impl<'a, T> Div<T> for &'a Tensor
where T: 'static + ElemType,

§

type Output = Tensor

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
source§

impl<T> Div<T> for Tensor
where T: 'static + ElemType,

§

type Output = Tensor

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
source§

impl<'a> Div<Tensor> for &'a Tensor

§

type Output = Tensor

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl Div<Tensor> for f32

§

type Output = Tensor

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl Div<Tensor> for f64

§

type Output = Tensor

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl Div for Tensor

§

type Output = Tensor

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

impl Hash for Tensor

source§

fn hash<H>(&self, hasher: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a, 'b> Mul<&'b Tensor> for &'a Tensor

§

type Output = Tensor

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<'a> Mul<&'a Tensor> for Tensor

§

type Output = Tensor

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl<'a> Mul<&'a Tensor> for f32

§

type Output = Tensor

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &'a Tensor) -> Self::Output

Performs the * operation. Read more
source§

impl<'a> Mul<&'a Tensor> for f64

§

type Output = Tensor

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &'a Tensor) -> Self::Output

Performs the * operation. Read more
source§

impl<'a, T> Mul<T> for &'a Tensor
where T: 'static + ElemType,

§

type Output = Tensor

The resulting type after applying the * operator.
source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
source§

impl<T> Mul<T> for Tensor
where T: 'static + ElemType,

§

type Output = Tensor

The resulting type after applying the * operator.
source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
source§

impl<'a> Mul<Tensor> for &'a Tensor

§

type Output = Tensor

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Tensor> for f32

§

type Output = Tensor

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul<Tensor> for f64

§

type Output = Tensor

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Mul for Tensor

§

type Output = Tensor

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

impl Neg for &Tensor

§

type Output = Tensor

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl Neg for Tensor

§

type Output = Tensor

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl Ord for Tensor

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Tensor

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Tensor

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Shape for Tensor

source§

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

source§

fn ndim(&self) -> usize

source§

fn size(&self) -> usize

source§

fn shape_at<I: Dim>(&self, i: I) -> usize

source§

fn shape_until<I: Dim>(&self, i: I) -> &[usize]

source§

fn dim<I: Dim>(&self, i: I) -> usize

source§

fn dims<D: Dims>(&self, d: D) -> Vec<usize>

source§

fn size_of_dims<D: Dims>(&self, d: D) -> usize

source§

fn shape_transpose(&self) -> Vec<usize>

source§

fn shape_eq<S: Shape + ?Sized>(&self, rhs: &S) -> bool

source§

fn shape_ndim_eq<S: Shape + ?Sized>(&self, rhs: &S) -> bool

source§

fn shape_size_eq<S: Shape + ?Sized>(&self, rhs: &S) -> bool

source§

fn shape_broadcast<T: Shape + ?Sized>(&self, rhs: &T) -> Result<Vec<usize>>

source§

fn shape_broadcast_matmul<S: Shape + ?Sized>( &self, rhs: &S ) -> Result<Vec<usize>>

source§

fn shape_reduce<T: AsRef<[usize]>>(&self, dims: T, keep_dim: bool) -> Vec<usize>

source§

impl<'a, 'b> Sub<&'b Tensor> for &'a Tensor

§

type Output = Tensor

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<'a> Sub<&'a Tensor> for Tensor

§

type Output = Tensor

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl<'a> Sub<&'a Tensor> for f32

§

type Output = Tensor

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &'a Tensor) -> Self::Output

Performs the - operation. Read more
source§

impl<'a> Sub<&'a Tensor> for f64

§

type Output = Tensor

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &'a Tensor) -> Self::Output

Performs the - operation. Read more
source§

impl<'a, T> Sub<T> for &'a Tensor
where T: 'static + ElemType,

§

type Output = Tensor

The resulting type after applying the - operator.
source§

fn sub(self, rhs: T) -> Self::Output

Performs the - operation. Read more
source§

impl<T> Sub<T> for Tensor
where T: 'static + ElemType,

§

type Output = Tensor

The resulting type after applying the - operator.
source§

fn sub(self, rhs: T) -> Self::Output

Performs the - operation. Read more
source§

impl<'a> Sub<Tensor> for &'a Tensor

§

type Output = Tensor

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Tensor> for f32

§

type Output = Tensor

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub<Tensor> for f64

§

type Output = Tensor

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl Sub for Tensor

§

type Output = Tensor

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

impl TensorIter for Tensor

source§

fn tensor_iter(&self) -> impl Iterator<Item = &Tensor>

source§

impl Eq for Tensor

Auto Trait Implementations§

§

impl !RefUnwindSafe for Tensor

§

impl !Send for Tensor

§

impl !Sync for Tensor

§

impl Unpin for Tensor

§

impl !UnwindSafe for Tensor

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
§

impl<'short, T, Target> AsGeneralizedRef<'short, &'short Target> for T
where T: AsRef<Target> + ?Sized, Target: ?Sized,

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

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

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,

§

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§

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

§

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.
§

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

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,