Struct DiffTensor

Source
pub struct DiffTensor<T, B = Cpu, const DEVICE_ID: usize = 0, A = HptAllocator<B>>
where B: BackendTy + Buffer, A: Allocator,
{ /* private fields */ }
Expand description

DiffTensor is a tensor that has a gradient.

Implementations§

Source§

impl<T, const DEVICE: usize, A> DiffTensor<T, Cpu, DEVICE, A>
where A: Allocator + Send + Sync + 'static, A::Output: AllocatorOutputRetrive,

Source

pub fn log_softmax( &self, axis: i64, ) -> Result<DiffTensor<<T as FloatOutUnary>::Output, Cpu, DEVICE, A>, TensorError>

Applies the logsoftmax function along a specified axis.

The logsoftmax function normalizes the elements along the specified axis such that they sum to 1. It is commonly used in machine learning models, particularly for multi-class classification tasks. The logsoftmax function transforms each element x_i in the input tensor into a probability by computing:

logsoftmax(x_i) = log(exp(x_i) / sum(exp(x_j))) for all j along the specified axis
§Arguments
  • axis - The axis along which to apply the softmax function. The elements along this axis will be transformed into probabilities that sum to 1.
§Returns

This function returns a Result containing a tensor with the softmax values computed along the specified axis.

Source§

impl<T, const DEVICE: usize, A> DiffTensor<T, Cpu, DEVICE, A>
where A: Allocator + Send + Sync + 'static, A::Output: AllocatorOutputRetrive,

Source

pub fn softmax( &self, axis: i64, ) -> Result<DiffTensor<<T as FloatOutUnary>::Output, Cpu, DEVICE, A>, TensorError>

Applies the softmax function along a specified axis.

The softmax function normalizes the elements along the specified axis such that they sum to 1. It is commonly used in machine learning models, particularly for multi-class classification tasks. The softmax function transforms each element x_i in the input tensor into a probability by computing:

softmax(x_i) = exp(x_i) / sum(exp(x_j)) for all j along the specified axis
§Arguments
  • axis - The axis along which to apply the softmax function. The elements along this axis will be transformed into probabilities that sum to 1.
§Returns

This function returns a Result containing a tensor with the softmax values computed along the specified axis.

Source§

impl<T: Clone, const DEVICE: usize> DiffTensor<T, Cpu, DEVICE>

Source

pub fn backward( &mut self, grad: Tensor<T, Cpu, DEVICE>, ) -> Result<(), TensorError>

Backward the gradient of the tensor

Source

pub fn grad(&self) -> Option<Tensor<T, Cpu, DEVICE>>

Get the gradient of the tensor

Source§

impl<T, const DEVICE: usize, Al> DiffTensor<T, Cpu, DEVICE, Al>
where Al: Allocator,

Source

pub fn new<A>(data: A) -> Self
where A: Into<Tensor<T, Cpu, DEVICE, Al>>,

Creates a new differentiable tensor from the provided data.

Trait Implementations§

Source§

impl<T, U, const DEVICE: usize, A> Add<&DiffTensor<U, Cpu, DEVICE, A>> for &DiffTensor<T, Cpu, DEVICE, A>
where T: CommonBounds + NormalOut<U>, U: CommonBounds, <T as NormalOut<U>>::Output: CommonBounds + Cast<<T as NormalOut<U>>::Output> + Cast<T> + Cast<U>, T::Vec: NormalOut<<U as TypeCommon>::Vec, Output = <<T as NormalOut<U>>::Output as TypeCommon>::Vec>, A: Allocator + 'static + Send + Sync, A::Output: AllocatorOutputRetrive,

Source§

type Output = DiffTensor<<T as NormalOut<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T, U, const DEVICE: usize, A> Add<&DiffTensor<U, Cpu, DEVICE, A>> for DiffTensor<T, Cpu, DEVICE, A>
where T: CommonBounds + NormalOut<U>, U: CommonBounds, <T as NormalOut<U>>::Output: CommonBounds + Cast<<T as NormalOut<U>>::Output> + Cast<T> + Cast<U>, T::Vec: NormalOut<<U as TypeCommon>::Vec, Output = <<T as NormalOut<U>>::Output as TypeCommon>::Vec>, A: Allocator + 'static + Send + Sync, A::Output: AllocatorOutputRetrive,

Source§

type Output = DiffTensor<<T as NormalOut<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T, U, const DEVICE: usize, A> Add<DiffTensor<U, Cpu, DEVICE, A>> for &DiffTensor<T, Cpu, DEVICE, A>
where T: CommonBounds + NormalOut<U>, U: CommonBounds, <T as NormalOut<U>>::Output: CommonBounds + Cast<<T as NormalOut<U>>::Output> + Cast<T> + Cast<U>, T::Vec: NormalOut<<U as TypeCommon>::Vec, Output = <<T as NormalOut<U>>::Output as TypeCommon>::Vec>, A: Allocator + 'static + Send + Sync, A::Output: AllocatorOutputRetrive,

Source§

type Output = DiffTensor<<T as NormalOut<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T, U, const DEVICE: usize, A> Add<DiffTensor<U, Cpu, DEVICE, A>> for DiffTensor<T, Cpu, DEVICE, A>
where T: CommonBounds + NormalOut<U>, U: CommonBounds, <T as NormalOut<U>>::Output: CommonBounds + Cast<<T as NormalOut<U>>::Output> + Cast<T> + Cast<U>, T::Vec: NormalOut<<U as TypeCommon>::Vec, Output = <<T as NormalOut<U>>::Output as TypeCommon>::Vec>, A: Allocator + 'static + Send + Sync, A::Output: AllocatorOutputRetrive,

Source§

type Output = DiffTensor<<T as NormalOut<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T, const DEVICE: usize, Al> AdvancedOps for DiffTensor<T, Cpu, DEVICE, Al>
where T: NormalOut<bool, Output = T> + Cast<i64> + CommonBounds + PartialOrd, f64: Cast<T>, Al: Allocator + Send + Sync + 'static, Al::Output: AllocatorOutputRetrive,

Source§

type Meta = T

The type of the meta data
Source§

type Output = DiffTensor<T, Cpu, DEVICE, Al>

The type of the output tensor
Source§

type IndexOutput = Tensor<i64, Cpu, DEVICE, Al>

The type of the index tensor
Source§

fn pad( &self, pads: &[(i64, i64)], val: Self::Meta, ) -> Result<Self::Output, TensorError>

Pad the tensor
Source§

fn topk( &self, k: i64, dim: i64, largest: bool, sorted: bool, ) -> Result<(Self::IndexOutput, Self::Output), TensorError>

Topk the tensor
Source§

fn onehot( &self, _: usize, _: i64, _: Self::Meta, _: Self::Meta, ) -> Result<Self::Output, TensorError>

Onehot the tensor
Source§

fn dropout(&self, _: f64) -> Result<Self::Output, TensorError>

Gather the tensor Dropout the tensor
Source§

fn scatter( &self, _: &Self::IndexOutput, _: i64, _: &Self::Output, ) -> Result<Self::Output, TensorError>

Gather elements the tensor Scatter elements the tensor
Source§

impl<T: Clone, B, const DEVICE_ID: usize, A> Clone for DiffTensor<T, B, DEVICE_ID, A>
where B: BackendTy + Buffer + Clone, A: Allocator + Clone,

Source§

fn clone(&self) -> DiffTensor<T, B, DEVICE_ID, A>

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<T: CommonBounds, const DEVICE: usize, Al> Concat for DiffTensor<T, Cpu, DEVICE, Al>
where Al: Allocator + Send + Sync + Clone + 'static, Al::Output: AllocatorOutputRetrive,

Source§

type Output = DiffTensor<T, Cpu, DEVICE, Al>

the output type of concat
Source§

fn concat( tensors: Vec<Self>, axis: usize, keepdims: bool, ) -> Result<Self::Output, TensorError>

Concatenates multiple tensors along a specified axis. Read more
Source§

fn vstack(tensors: Vec<Self>) -> Result<Self::Output, TensorError>

Stacks multiple tensors vertically (along the first axis). Read more
Source§

fn hstack(tensors: Vec<Self>) -> Result<Self::Output, TensorError>

Stacks multiple tensors horizontally (along the second axis). Read more
Source§

fn dstack(tensors: Vec<Self>) -> Result<Self::Output, TensorError>

Stacks multiple tensors along the depth axis (third dimension). Read more
Source§

impl<T, U, const DEVICE: usize, A> Div<&DiffTensor<U, Cpu, DEVICE, A>> for &DiffTensor<T, Cpu, DEVICE, A>

Source§

type Output = DiffTensor<<T as FloatOutBinary<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the / operation. Read more
Source§

impl<T, U, const DEVICE: usize, A> Div<&DiffTensor<U, Cpu, DEVICE, A>> for DiffTensor<T, Cpu, DEVICE, A>

Source§

type Output = DiffTensor<<T as FloatOutBinary<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the / operation. Read more
Source§

impl<T, U, const DEVICE: usize, A> Div<DiffTensor<U, Cpu, DEVICE, A>> for &DiffTensor<T, Cpu, DEVICE, A>

Source§

type Output = DiffTensor<<T as FloatOutBinary<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the / operation. Read more
Source§

impl<T, U, const DEVICE: usize, A> Div<DiffTensor<U, Cpu, DEVICE, A>> for DiffTensor<T, Cpu, DEVICE, A>

Source§

type Output = DiffTensor<<T as FloatOutBinary<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the / operation. Read more
Source§

impl<T: CommonBounds + NormalOut<Output = T> + Cmp<T, Output = bool>, const DEVICE: usize> IndexReduce for DiffTensor<T, Cpu, DEVICE>

Source§

type Output = Tensor<i64, Cpu, DEVICE>

The output tensor type.
Source§

fn argmax<S: Into<Axis>>( &self, axis: S, keep_dims: bool, ) -> Result<Self::Output, TensorError>

Returns the indices of the maximum values along the specified axis. Read more
Source§

fn argmin<S: Into<Axis>>( &self, axis: S, keep_dims: bool, ) -> Result<Self::Output, TensorError>

Returns the indices of the minimum values along the specified axis. Read more
Source§

impl<A, B, const DEVICE: usize, Al> Matmul<DiffTensor<B, Cpu, DEVICE, Al>> for DiffTensor<A, Cpu, DEVICE, Al>
where A: CommonBounds + NormalOut<B> + Cast<<A as NormalOut<B>>::Output> + NormalOut<<A as NormalOut<B>>::Output> + Cast<<A as NormalOut<<A as NormalOut<B>>::Output>>::Output>, B: CommonBounds + Cast<<A as NormalOut<B>>::Output> + Cast<<<A as NormalOut<B>>::Output as NormalOut<B>>::Output>, <A as NormalOut<B>>::Output: CommonBounds + NormalOut<A> + NormalOut<B> + Cast<<<A as NormalOut<B>>::Output as NormalOut<B>>::Output> + Cast<<A as NormalOut<<A as NormalOut<B>>::Output>>::Output>, <<A as NormalOut<B>>::Output as NormalOut<B>>::Output: CommonBounds + Cast<<A as NormalOut<<A as NormalOut<B>>::Output>>::Output> + Cast<A>, <A as NormalOut<<A as NormalOut<B>>::Output>>::Output: CommonBounds + Cast<B>, Al: Allocator + 'static + Send + Sync, Al::Output: AllocatorOutputRetrive,

Source§

type Output = DiffTensor<<A as NormalOut<B>>::Output, Cpu, DEVICE, Al>

The output tensor type.
Source§

type OutputMeta = <A as NormalOut<B>>::Output

The output tensor data type.
Source§

type InplaceOutput = Tensor<<A as NormalOut<B>>::Output, Cpu, DEVICE, Al>

The inplace output tensor type.
Source§

fn matmul( &self, rhs: DiffTensor<B, Cpu, DEVICE, Al>, ) -> Result<Self::Output, TensorError>

Computes the matrix multiplication of two tensors. Read more
Source§

fn matmul_<U>( &self, rhs: DiffTensor<B, Cpu, DEVICE, Al>, out: U, ) -> Result<Self::InplaceOutput, TensorError>
where U: Borrow<Self::InplaceOutput> + BorrowMut<Self::InplaceOutput>,

Inplace version of matmul Read more
Source§

impl<T, U, const DEVICE: usize, A> Mul<&DiffTensor<U, Cpu, DEVICE, A>> for &DiffTensor<T, Cpu, DEVICE, A>
where T: CommonBounds + NormalOut<U>, U: CommonBounds, <T as NormalOut<U>>::Output: CommonBounds + Cast<<T as NormalOut<U>>::Output> + Cast<T> + Cast<U> + NormalOut<U> + NormalOut<T>, T::Vec: NormalOut<<U as TypeCommon>::Vec, Output = <<T as NormalOut<U>>::Output as TypeCommon>::Vec>, <<T as NormalOut<U>>::Output as NormalOut<U>>::Output: CommonBounds + Cast<T>, <<T as NormalOut<U>>::Output as NormalOut<T>>::Output: CommonBounds + Cast<U>, <<T as NormalOut<U>>::Output as TypeCommon>::Vec: NormalOut<<U as TypeCommon>::Vec, Output = <<<T as NormalOut<U>>::Output as NormalOut<U>>::Output as TypeCommon>::Vec> + NormalOut<<T as TypeCommon>::Vec, Output = <<<T as NormalOut<U>>::Output as NormalOut<T>>::Output as TypeCommon>::Vec>, A: Allocator + 'static + Send + Sync, A::Output: AllocatorOutputRetrive,

Source§

type Output = DiffTensor<<T as NormalOut<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T, U, const DEVICE: usize, A> Mul<&DiffTensor<U, Cpu, DEVICE, A>> for DiffTensor<T, Cpu, DEVICE, A>
where T: CommonBounds + NormalOut<U>, U: CommonBounds, <T as NormalOut<U>>::Output: CommonBounds + Cast<<T as NormalOut<U>>::Output> + Cast<T> + Cast<U> + NormalOut<U> + NormalOut<T>, T::Vec: NormalOut<<U as TypeCommon>::Vec, Output = <<T as NormalOut<U>>::Output as TypeCommon>::Vec>, <<T as NormalOut<U>>::Output as NormalOut<U>>::Output: CommonBounds + Cast<T>, <<T as NormalOut<U>>::Output as NormalOut<T>>::Output: CommonBounds + Cast<U>, <<T as NormalOut<U>>::Output as TypeCommon>::Vec: NormalOut<<U as TypeCommon>::Vec, Output = <<<T as NormalOut<U>>::Output as NormalOut<U>>::Output as TypeCommon>::Vec> + NormalOut<<T as TypeCommon>::Vec, Output = <<<T as NormalOut<U>>::Output as NormalOut<T>>::Output as TypeCommon>::Vec>, A: Allocator + 'static + Send + Sync, A::Output: AllocatorOutputRetrive,

Source§

type Output = DiffTensor<<T as NormalOut<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T, U, const DEVICE: usize, A> Mul<DiffTensor<U, Cpu, DEVICE, A>> for &DiffTensor<T, Cpu, DEVICE, A>
where T: CommonBounds + NormalOut<U>, U: CommonBounds, <T as NormalOut<U>>::Output: CommonBounds + Cast<<T as NormalOut<U>>::Output> + Cast<T> + Cast<U> + NormalOut<U> + NormalOut<T>, T::Vec: NormalOut<<U as TypeCommon>::Vec, Output = <<T as NormalOut<U>>::Output as TypeCommon>::Vec>, <<T as NormalOut<U>>::Output as NormalOut<U>>::Output: CommonBounds + Cast<T>, <<T as NormalOut<U>>::Output as NormalOut<T>>::Output: CommonBounds + Cast<U>, <<T as NormalOut<U>>::Output as TypeCommon>::Vec: NormalOut<<U as TypeCommon>::Vec, Output = <<<T as NormalOut<U>>::Output as NormalOut<U>>::Output as TypeCommon>::Vec> + NormalOut<<T as TypeCommon>::Vec, Output = <<<T as NormalOut<U>>::Output as NormalOut<T>>::Output as TypeCommon>::Vec>, A: Allocator + 'static + Send + Sync, A::Output: AllocatorOutputRetrive,

Source§

type Output = DiffTensor<<T as NormalOut<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T, U, const DEVICE: usize, A> Mul<DiffTensor<U, Cpu, DEVICE, A>> for DiffTensor<T, Cpu, DEVICE, A>
where T: CommonBounds + NormalOut<U>, U: CommonBounds, <T as NormalOut<U>>::Output: CommonBounds + Cast<<T as NormalOut<U>>::Output> + Cast<T> + Cast<U> + NormalOut<U> + NormalOut<T>, T::Vec: NormalOut<<U as TypeCommon>::Vec, Output = <<T as NormalOut<U>>::Output as TypeCommon>::Vec>, <<T as NormalOut<U>>::Output as NormalOut<U>>::Output: CommonBounds + Cast<T>, <<T as NormalOut<U>>::Output as NormalOut<T>>::Output: CommonBounds + Cast<U>, <<T as NormalOut<U>>::Output as TypeCommon>::Vec: NormalOut<<U as TypeCommon>::Vec, Output = <<<T as NormalOut<U>>::Output as NormalOut<U>>::Output as TypeCommon>::Vec> + NormalOut<<T as TypeCommon>::Vec, Output = <<<T as NormalOut<U>>::Output as NormalOut<T>>::Output as TypeCommon>::Vec>, A: Allocator + 'static + Send + Sync, A::Output: AllocatorOutputRetrive,

Source§

type Output = DiffTensor<<T as NormalOut<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T, const DEVICE: usize, Al> Random for DiffTensor<T, Cpu, DEVICE, Al>

Source§

type Meta = T

Associated type for meta-information or parameters relevant to distributions.
Source§

fn randn<S: Into<Shape>>(shape: S) -> Result<Self, TensorError>

Generates a random number array with a standard normal distribution (mean = 0, standard deviation = 1).
Source§

fn randn_like(&self) -> Result<Self, TensorError>

Generates a random number array with a standard normal distribution (mean = 0, standard deviation = 1), with the same shape as the calling instance.
Source§

fn rand<S: Into<Shape>>( shape: S, low: Self::Meta, high: Self::Meta, ) -> Result<Self, TensorError>

Generates a random number array with a uniform distribution between [0, 1). Read more
Source§

fn rand_like( &self, low: Self::Meta, high: Self::Meta, ) -> Result<Self, TensorError>

Generates a random number array with a uniform distribution between [0, 1),
Source§

fn beta<S: Into<Shape>>( a: Self::Meta, b: Self::Meta, shape: S, ) -> Result<Self, TensorError>

Generates a random number array following the Beta distribution. Read more
Source§

fn beta_like(&self, a: Self::Meta, b: Self::Meta) -> Result<Self, TensorError>

Generates a random number array following the Beta distribution, with the same shape as the calling instance. Read more
Source§

fn chisquare<S: Into<Shape>>( df: Self::Meta, shape: S, ) -> Result<Self, TensorError>

Generates a random number array following the Chi-Squared distribution. Read more
Source§

fn chisquare_like(&self, df: Self::Meta) -> Result<Self, TensorError>

Generates a random number array following the Chi-Squared distribution, with the same shape as the calling instance. Read more
Source§

fn exponential<S: Into<Shape>>( lambda: Self::Meta, shape: S, ) -> Result<Self, TensorError>

Generates a random number array following the Exponential distribution. Read more
Source§

fn exponential_like(&self, lambda: Self::Meta) -> Result<Self, TensorError>

Generates a random number array following the Exponential distribution, with the same shape as the calling instance. Read more
Source§

fn gamma<S: Into<Shape>>( gamm_shape: Self::Meta, scale: Self::Meta, shape: S, ) -> Result<Self, TensorError>

Generates a random number array following the Gamma distribution. Read more
Source§

fn gamma_like( &self, shape: Self::Meta, scale: Self::Meta, ) -> Result<Self, TensorError>

Generates a random number array following the Gamma distribution, with the same shape as the calling instance. Read more
Source§

fn gumbel<S: Into<Shape>>( mu: Self::Meta, beta: Self::Meta, shape: S, ) -> Result<Self, TensorError>

Generates a random number array following the Gumbel distribution. Read more
Source§

fn gumbel_like( &self, mu: Self::Meta, beta: Self::Meta, ) -> Result<Self, TensorError>

Generates a random number array following the Gumbel distribution, with the same shape as the calling instance. Read more
Source§

fn lognormal<S: Into<Shape>>( mean: Self::Meta, std: Self::Meta, shape: S, ) -> Result<Self, TensorError>

Generates a random number array following the Log-Normal distribution. Read more
Source§

fn lognormal_like( &self, mean: Self::Meta, std: Self::Meta, ) -> Result<Self, TensorError>

Generates a random number array following the Log-Normal distribution, with the same shape as the calling instance. Read more
Source§

fn normal_gaussian<S: Into<Shape>>( mean: Self::Meta, std: Self::Meta, shape: S, ) -> Result<Self, TensorError>

Generates a random number array following the Normal (Gaussian) distribution. Read more
Source§

fn normal_gaussian_like( &self, mean: Self::Meta, std: Self::Meta, ) -> Result<Self, TensorError>

Generates a random number array following the Normal (Gaussian) distribution, with the same shape as the calling instance. Read more
Source§

fn pareto<S: Into<Shape>>( pareto_shape: Self::Meta, a: Self::Meta, shape: S, ) -> Result<Self, TensorError>

Generates a random number array following the Pareto distribution. Read more
Source§

fn pareto_like( &self, pareto_shape: Self::Meta, a: Self::Meta, ) -> Result<Self, TensorError>

Generates a random number array following the Pareto distribution, with the same shape as the calling instance. Read more
Source§

fn poisson<S: Into<Shape>>( lambda: Self::Meta, shape: S, ) -> Result<Self, TensorError>

Generates a random number array following the Poisson distribution. Read more
Source§

fn poisson_like(&self, lambda: Self::Meta) -> Result<Self, TensorError>

Generates a random number array following the Poisson distribution, with the same shape as the calling instance. Read more
Source§

fn weibull<S: Into<Shape>>( a: Self::Meta, b: Self::Meta, shape: S, ) -> Result<Self, TensorError>

Generates a random number array following the Weibull distribution. Read more
Source§

fn weibull_like( &self, a: Self::Meta, b: Self::Meta, ) -> Result<Self, TensorError>

Generates a random number array following the Weibull distribution, with the same shape as the calling instance. Read more
Source§

fn zipf<S: Into<Shape>>( n: u64, a: Self::Meta, shape: S, ) -> Result<Self, TensorError>

Generates a random number array following the Zipf distribution. Read more
Source§

fn zipf_like(&self, n: u64, a: Self::Meta) -> Result<Self, TensorError>

Generates a random number array following the Zipf distribution, with the same shape as the calling instance. Read more
Source§

fn triangular<S: Into<Shape>>( low: Self::Meta, high: Self::Meta, mode: Self::Meta, shape: S, ) -> Result<Self, TensorError>

Generates a random number array following the Triangular distribution. Read more
Source§

fn triangular_like( &self, low: Self::Meta, high: Self::Meta, mode: Self::Meta, ) -> Result<Self, TensorError>

Generates a random number array following the Triangular distribution, with the same shape as the calling instance. Read more
Source§

fn bernoulli<S: Into<Shape>>( shape: S, p: Self::Meta, ) -> Result<Self, TensorError>
where T: Cast<f64>, bool: Cast<T>,

Generates a bernoulli array with values true or false following the Bernoulli distribution. Read more
Source§

impl<T, const DEVICE: usize, Al> RandomInt for DiffTensor<T, Cpu, DEVICE, Al>

Source§

type Meta = T

Associated type for meta-information or parameters relevant to distributions.
Source§

fn randint<S: Into<Shape>>( low: Self::Meta, high: Self::Meta, shape: S, ) -> Result<Self, TensorError>
where <T as SampleUniform>::Sampler: Sync,

Generates a random integer array with values in the specified range. Read more
Source§

fn randint_like( &self, low: Self::Meta, high: Self::Meta, ) -> Result<Self, TensorError>
where <T as SampleUniform>::Sampler: Sync,

Generates a random integer array with values in the specified range, with the same shape as the calling instance. Read more
Source§

impl<T, U, const DEVICE: usize, A> Rem<&DiffTensor<U, Cpu, DEVICE, A>> for &DiffTensor<T, Cpu, DEVICE, A>

Source§

type Output = DiffTensor<<T as NormalOut<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the % operation. Read more
Source§

impl<T, U, const DEVICE: usize, A> Rem<&DiffTensor<U, Cpu, DEVICE, A>> for DiffTensor<T, Cpu, DEVICE, A>

Source§

type Output = DiffTensor<<T as NormalOut<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the % operation. Read more
Source§

impl<T, U, const DEVICE: usize, A> Rem<DiffTensor<U, Cpu, DEVICE, A>> for &DiffTensor<T, Cpu, DEVICE, A>

Source§

type Output = DiffTensor<<T as NormalOut<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the % operation. Read more
Source§

impl<T, U, const DEVICE: usize, A> Rem<DiffTensor<U, Cpu, DEVICE, A>> for DiffTensor<T, Cpu, DEVICE, A>

Source§

type Output = DiffTensor<<T as NormalOut<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the % operation. Read more
Source§

impl<T: CommonBounds, const DEVICE: usize, Al> ShapeManipulate for DiffTensor<T, Cpu, DEVICE, Al>
where Al: Allocator + 'static + Send + Sync, Al::Output: AllocatorOutputRetrive,

Source§

type Meta = T

tensor data type
Source§

type Output = DiffTensor<T, Cpu, DEVICE, Al>

the output type
Source§

fn squeeze<A: Into<Axis>>(&self, axes: A) -> Result<Self::Output, TensorError>

Removes dimensions of size 1 from the tensor along the specified axes. Read more
Source§

fn unsqueeze<A: Into<Axis>>(&self, axes: A) -> Result<Self::Output, TensorError>

Adds a new dimension of size 1 to the tensor at the specified axes. Read more
Source§

fn reshape<S: Into<Shape>>(&self, shape: S) -> Result<Self::Output, TensorError>

Reshapes the tensor into the specified shape without changing its data. Read more
Source§

fn transpose(&self, axis1: i64, axis2: i64) -> Result<Self::Output, TensorError>

Swaps two axes of the tensor, effectively transposing the dimensions along the specified axes. Read more
Source§

fn permute<A: Into<Axis>>(&self, axes: A) -> Result<Self::Output, TensorError>

Reorders the dimensions of the tensor according to the specified axes. Read more
Source§

fn permute_inv<A: Into<Axis>>( &self, axes: A, ) -> Result<Self::Output, TensorError>

Reverses the permutation of the dimensions of the tensor according to the specified axes. Read more
Source§

fn expand<S: Into<Shape>>(&self, shape: S) -> Result<Self::Output, TensorError>

Expands the tensor to a larger shape without copying data, using broadcasting. Read more
Source§

fn t(&self) -> Result<Self::Output, TensorError>

Returns the transpose of the tensor by swapping the last two dimensions. Read more
Source§

fn mt(&self) -> Result<Self::Output, TensorError>

reverse the dimensions of the tensor. Read more
Source§

fn flip<A: Into<Axis>>(&self, axes: A) -> Result<Self::Output, TensorError>

Reverses the order of elements along the specified axes of the tensor. Read more
Source§

fn fliplr(&self) -> Result<Self::Output, TensorError>

Reverses the order of elements along the last dimension (columns) of a 2D tensor (matrix). Read more
Source§

fn flipud(&self) -> Result<Self::Output, TensorError>

Reverses the order of elements along the first dimension (rows) of a 2D tensor (matrix). Read more
Source§

fn tile<S: Into<Axis>>(&self, repeats: S) -> Result<Self::Output, TensorError>

Repeats the tensor along the specified axes according to the given repetition values. Read more
Source§

fn trim_zeros(&self, trim: &str) -> Result<Self::Output, TensorError>
where Self::Meta: PartialEq,

Removes leading or trailing zeros from the tensor based on the specified trim mode. Read more
Source§

fn repeat(&self, repeats: usize, axes: i16) -> Result<Self::Output, TensorError>

Repeats the elements of the tensor along the specified axis a given number of times. Read more
Source§

fn split( &self, indices_or_sections: &[i64], axis: i64, ) -> Result<Vec<Self>, TensorError>

Splits the tensor into multiple sub-tensors along the specified axis. Read more
Source§

fn dsplit(&self, indices: &[i64]) -> Result<Vec<Self>, TensorError>

Splits the tensor into multiple sub-tensors along the depth axis (third dimension). Read more
Source§

fn hsplit(&self, indices: &[i64]) -> Result<Vec<Self>, TensorError>

Splits the tensor into multiple sub-tensors along the horizontal axis (second dimension). Read more
Source§

fn vsplit(&self, indices: &[i64]) -> Result<Vec<Self>, TensorError>

Splits the tensor into multiple sub-tensors along the vertical axis (first dimension). Read more
Source§

fn swap_axes(&self, axis1: i64, axis2: i64) -> Result<Self::Output, TensorError>

Swaps two axes of the tensor, effectively transposing the data along the specified axes. Read more
Source§

fn flatten<A>(&self, start: A, end: A) -> Result<Self::Output, TensorError>
where A: Into<Option<usize>>,

Flattens a range of dimensions into a single dimension. Read more
Source§

impl<T, const DEVICE: usize, Al> Slice for DiffTensor<T, Cpu, DEVICE, Al>
where T: CommonBounds, Al: Allocator + 'static + Send + Sync, Al::Output: AllocatorOutputRetrive,

Source§

fn slice( &self, index: &[(i64, i64, i64)], ) -> Result<DiffTensor<T, Cpu, DEVICE, Al>, TensorError>

Extracts a slice of the tensor based on the provided indices. Read more
Source§

impl<T, U, const DEVICE: usize, A> Sub<&DiffTensor<U, Cpu, DEVICE, A>> for &DiffTensor<T, Cpu, DEVICE, A>
where T: CommonBounds + NormalOut<U>, U: CommonBounds, <T as NormalOut<U>>::Output: CommonBounds + Cast<<T as NormalOut<U>>::Output> + Cast<T> + Cast<U>, T::Vec: NormalOut<<U as TypeCommon>::Vec, Output = <<T as NormalOut<U>>::Output as TypeCommon>::Vec>, Tensor<T, Cpu, DEVICE, A>: Neg<Output = Tensor<T, Cpu, DEVICE, A>>, A: Allocator + 'static + Send + Sync, A::Output: AllocatorOutputRetrive,

Source§

type Output = DiffTensor<<T as NormalOut<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T, U, const DEVICE: usize, A> Sub<&DiffTensor<U, Cpu, DEVICE, A>> for DiffTensor<T, Cpu, DEVICE, A>
where T: CommonBounds + NormalOut<U>, U: CommonBounds, <T as NormalOut<U>>::Output: CommonBounds + Cast<<T as NormalOut<U>>::Output> + Cast<T> + Cast<U>, T::Vec: NormalOut<<U as TypeCommon>::Vec, Output = <<T as NormalOut<U>>::Output as TypeCommon>::Vec>, Tensor<T, Cpu, DEVICE, A>: Neg<Output = Tensor<T, Cpu, DEVICE, A>>, A: Allocator + 'static + Send + Sync, A::Output: AllocatorOutputRetrive,

Source§

type Output = DiffTensor<<T as NormalOut<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T, U, const DEVICE: usize, A> Sub<DiffTensor<U, Cpu, DEVICE, A>> for &DiffTensor<T, Cpu, DEVICE, A>
where T: CommonBounds + NormalOut<U>, U: CommonBounds, <T as NormalOut<U>>::Output: CommonBounds + Cast<<T as NormalOut<U>>::Output> + Cast<T> + Cast<U>, T::Vec: NormalOut<<U as TypeCommon>::Vec, Output = <<T as NormalOut<U>>::Output as TypeCommon>::Vec>, Tensor<T, Cpu, DEVICE, A>: Neg<Output = Tensor<T, Cpu, DEVICE, A>>, A: Allocator + 'static + Send + Sync, A::Output: AllocatorOutputRetrive,

Source§

type Output = DiffTensor<<T as NormalOut<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T, U, const DEVICE: usize, A> Sub<DiffTensor<U, Cpu, DEVICE, A>> for DiffTensor<T, Cpu, DEVICE, A>
where T: CommonBounds + NormalOut<U>, U: CommonBounds, <T as NormalOut<U>>::Output: CommonBounds + Cast<<T as NormalOut<U>>::Output> + Cast<T> + Cast<U>, T::Vec: NormalOut<<U as TypeCommon>::Vec, Output = <<T as NormalOut<U>>::Output as TypeCommon>::Vec>, Tensor<T, Cpu, DEVICE, A>: Neg<Output = Tensor<T, Cpu, DEVICE, A>>, A: Allocator + 'static + Send + Sync, A::Output: AllocatorOutputRetrive,

Source§

type Output = DiffTensor<<T as NormalOut<U>>::Output, Cpu, DEVICE, A>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: DiffTensor<U, Cpu, DEVICE, A>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T, C, const DEVICE: usize, Al> TensorCmp<T, C> for DiffTensor<T, Cpu, DEVICE, Al>
where T: CommonBounds + Cmp<C, Output = bool>, C: CommonBounds, T::Vec: SimdCmp<C::Vec>, <T::Vec as SimdCmp<C::Vec>>::Output: IntoVec<boolx16>, Al: Allocator + 'static, Al::Output: AllocatorOutputRetrive,

Source§

type RHS = DiffTensor<C, Cpu, DEVICE, Al>

right hand side tensor type
Source§

type Output = Tensor<bool, Cpu, DEVICE, Al>

output tensor type, normally a boolean tensor
Source§

type BoolVector = boolx16

a boolean simd vector
Source§

fn tensor_neq<D>(&self, rhs: D) -> Result<Self::Output, TensorError>
where D: Borrow<Self::RHS>,

check if two tensors are equal, return a bool tensor Read more
Source§

fn tensor_eq<D>(&self, rhs: D) -> Result<Self::Output, TensorError>
where D: Borrow<Self::RHS>,

check if two tensors are equal, return a bool tensor Read more
Source§

fn tensor_lt<D>(&self, rhs: D) -> Result<Self::Output, TensorError>
where D: Borrow<Self::RHS>,

check if two tensors are equal, return a bool tensor Read more
Source§

fn tensor_gt<D>(&self, rhs: D) -> Result<Self::Output, TensorError>
where D: Borrow<Self::RHS>,

check if two tensors are equal, return a bool tensor Read more
Source§

fn tensor_le<D>(&self, rhs: D) -> Result<Self::Output, TensorError>
where D: Borrow<Self::RHS>,

check if two tensors are equal, return a bool tensor Read more
Source§

fn tensor_ge<D>(&self, rhs: D) -> Result<Self::Output, TensorError>
where D: Borrow<Self::RHS>,

check if two tensors are equal, return a bool tensor Read more
Source§

impl<T: CommonBounds, const DEVICE: usize, Al> TensorCreator<T> for DiffTensor<T, Cpu, DEVICE, Al>

Source§

type Output = DiffTensor<T, Cpu, DEVICE, Al>

the output type of the creator
Source§

fn empty<S: Into<Shape>>(shape: S) -> Result<Self::Output, TensorError>

Creates a tensor with uninitialized elements of the specified shape. Read more
Source§

fn zeros<S: Into<Shape>>(shape: S) -> Result<Self::Output, TensorError>

Creates a tensor filled with zeros of the specified shape. Read more
Source§

fn ones<S: Into<Shape>>(shape: S) -> Result<Self::Output, TensorError>
where u8: Cast<T>,

Creates a tensor filled with ones of the specified shape. Read more
Source§

fn empty_like(&self) -> Result<Self::Output, TensorError>

Creates a tensor with uninitialized elements, having the same shape as the input tensor. Read more
Source§

fn zeros_like(&self) -> Result<Self::Output, TensorError>

Creates a tensor filled with zeros, having the same shape as the input tensor. Read more
Source§

fn ones_like(&self) -> Result<Self::Output, TensorError>
where u8: Cast<T>,

Creates a tensor filled with ones, having the same shape as the input tensor. Read more
Source§

fn full<S: Into<Shape>>(val: T, shape: S) -> Result<Self::Output, TensorError>

Creates a tensor filled with a specified value, with the specified shape. Read more
Source§

fn full_like(&self, val: T) -> Result<Self::Output, TensorError>

Creates a tensor filled with a specified value, having the same shape as the input tensor. Read more
Source§

fn arange<U>(start: U, end: U) -> Result<Self::Output, TensorError>
where usize: Cast<T>, U: Cast<i64> + Cast<T> + Copy,

Creates a tensor with values within a specified range. Read more
Source§

fn arange_step(start: T, end: T, step: T) -> Result<Self::Output, TensorError>
where T: Cast<f64> + Cast<usize>, usize: Cast<T>,

Creates a tensor with values within a specified range with a given step size. Read more
Source§

fn eye(n: usize, m: usize, k: usize) -> Result<Self::Output, TensorError>

Creates a 2D identity matrix with ones on a diagonal and zeros elsewhere. Read more
Source§

fn linspace<U>( start: U, end: U, num: usize, include_end: bool, ) -> Result<Self::Output, TensorError>
where U: Cast<f64> + Cast<T> + Copy, usize: Cast<T>, f64: Cast<T>,

Creates a tensor with evenly spaced values between start and end. Read more
Source§

fn logspace( start: T, end: T, num: usize, include_end: bool, base: T, ) -> Result<Self::Output, TensorError>
where T: Cast<f64> + Float + NormalOut<T, Output = T>, usize: Cast<T>, f64: Cast<T>,

Creates a tensor with logarithmically spaced values between start and end. Read more
Source§

fn geomspace( start: T, end: T, n: usize, include_end: bool, ) -> Result<Self::Output, TensorError>
where f64: Cast<T>, usize: Cast<T>, T: Cast<f64>,

Creates a tensor with geometrically spaced values between start and end. Read more
Source§

fn tri( n: usize, m: usize, k: i64, low_triangle: bool, ) -> Result<Self::Output, TensorError>
where u8: Cast<T>,

Creates a 2D triangular matrix of size n by m, with ones below or on the kth diagonal and zeros elsewhere. Read more
Source§

fn tril(&self, k: i64) -> Result<Self::Output, TensorError>
where T: NormalOut<bool, Output = T> + Cast<T> + TypeCommon, T::Vec: NormalOut<boolx16, Output = T::Vec>,

Returns the lower triangular part of the matrix, with all elements above the kth diagonal set to zero. Read more
Source§

fn triu(&self, k: i64) -> Result<Self::Output, TensorError>
where T: NormalOut<bool, Output = T> + Cast<T> + TypeCommon, T::Vec: NormalOut<boolx16, Output = T::Vec>,

Returns the upper triangular part of the matrix, with all elements below the kth diagonal set to zero. Read more
Source§

fn identity(n: usize) -> Result<Self::Output, TensorError>
where u8: Cast<T>,

Creates a 2D identity matrix of size n by n. Read more

Auto Trait Implementations§

§

impl<T, B, const DEVICE_ID: usize, A> Freeze for DiffTensor<T, B, DEVICE_ID, A>

§

impl<T, B = Cpu, const DEVICE_ID: usize = 0, A = HptAllocator<B>> !RefUnwindSafe for DiffTensor<T, B, DEVICE_ID, A>

§

impl<T, B = Cpu, const DEVICE_ID: usize = 0, A = HptAllocator<B>> !Send for DiffTensor<T, B, DEVICE_ID, A>

§

impl<T, B = Cpu, const DEVICE_ID: usize = 0, A = HptAllocator<B>> !Sync for DiffTensor<T, B, DEVICE_ID, A>

§

impl<T, B, const DEVICE_ID: usize, A> Unpin for DiffTensor<T, B, DEVICE_ID, A>

§

impl<T, B = Cpu, const DEVICE_ID: usize = 0, A = HptAllocator<B>> !UnwindSafe for DiffTensor<T, B, DEVICE_ID, A>

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> 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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,

Source§

impl<T, Base> RefNum<Base> for T
where T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>,