pub struct Tensor(/* private fields */);
Implementations§
source§impl Tensor
impl Tensor
pub fn new( device: impl AsDevice, dtype: impl AsDType, shape: impl Shape, primitive: impl Into<Box<dyn Primitive>>, inputs: impl Into<Vec<Tensor>> ) -> Self
pub fn id(&self) -> usize
pub fn device(&self) -> &dyn Device
pub fn dtype(&self) -> &dyn DType
pub fn primitive(&self) -> &dyn Primitive
pub fn inputs(&self) -> impl Deref<Target = [Tensor]> + '_
pub fn full<T: ElemType>( val: T, shape: impl Shape, device: impl AsDevice ) -> Tensor
pub fn full_like<T: ElemType>(&self, val: T) -> Tensor
pub fn ones( shape: impl Shape, dtype: impl AsDType, device: impl AsDevice ) -> Tensor
pub fn ones_like(&self) -> Tensor
pub fn zeros( shape: impl Shape, dtype: impl AsDType, device: impl AsDevice ) -> Tensor
pub fn zeros_like(&self) -> Tensor
pub fn rand<T: Type>( shape: impl Shape, dtype: T, device: impl AsDevice ) -> Tensor
pub fn rand_like(&self) -> Tensor
pub fn randn<T: Type>( shape: impl Shape, dtype: T, device: impl AsDevice ) -> Tensor
pub fn randn_like(&self) -> Tensor
pub fn arange<D: Type, T: ArangeArgs<D>>( args: T, device: impl AsDevice ) -> Tensor
pub fn from_array<T: ElemType>( data: impl Into<Vec<T>> + Debug, shape: impl Shape, device: impl AsDevice ) -> Tensor
sourcepub fn from_safetensor(view: &TensorView<'_>, device: impl AsDevice) -> Tensor
pub fn from_safetensor(view: &TensorView<'_>, device: impl AsDevice) -> Tensor
pub fn neg(&self) -> Tensor
pub fn cat<T: AsRef<Tensor> + Debug>(tensors: &[T], dim: impl Dim) -> Tensor
pub fn matmul<T: AsRef<Tensor>>(&self, rhs: T) -> Tensor
pub fn eq<T: AsRef<Tensor>>(&self, rhs: T) -> Tensor
pub fn ne<T: AsRef<Tensor>>(&self, rhs: T) -> Tensor
pub fn gt<T: AsRef<Tensor>>(&self, rhs: T) -> Tensor
pub fn ge<T: AsRef<Tensor>>(&self, rhs: T) -> Tensor
pub fn lt<T: AsRef<Tensor>>(&self, rhs: T) -> Tensor
pub fn le<T: AsRef<Tensor>>(&self, rhs: T) -> Tensor
pub fn maximum<T: AsRef<Tensor>>(&self, rhs: T) -> Tensor
pub fn minimum<T: AsRef<Tensor>>(&self, rhs: T) -> Tensor
pub fn t(&self) -> Tensor
pub fn transpose(&self, dim0: impl Dim, dim1: impl Dim) -> Tensor
pub fn broadcast_to(&self, shape: impl Shape) -> Tensor
pub fn broadcast_left(&self, shape: impl Shape) -> Tensor
pub fn reshape(&self, shape: impl Shape) -> Tensor
pub fn add<T>(&self, rhs: T) -> Tensor
pub fn mul<T>(&self, rhs: T) -> Tensor
pub fn sin(&self) -> Tensor
pub fn cos(&self) -> Tensor
pub fn tanh(&self) -> Tensor
pub fn square(&self) -> Tensor
pub fn powf(&self, exponent: f64) -> Tensor
pub fn sqrt(&self) -> Tensor
pub fn rsqrt(&self) -> Tensor
pub fn sign(&self) -> Tensor
pub fn abs(&self) -> Tensor
pub fn exp(&self) -> Tensor
pub fn log(&self) -> Tensor
pub fn log2(&self) -> Tensor
pub fn log10(&self) -> Tensor
pub fn sum<T: ReduceArgs>(&self, args: T) -> Tensor
pub fn max<T: ReduceArgs>(&self, args: T) -> Tensor
pub fn min<T: ReduceArgs>(&self, args: T) -> Tensor
pub fn mean<T: ReduceArgs>(&self, args: T) -> Tensor
pub fn var<T: VarArgs>(&self, args: T) -> Tensor
pub fn argmax<T: ArgReduceArgs>(&self, args: T) -> Tensor
pub fn argmin<T: ArgReduceArgs>(&self, args: T) -> Tensor
pub fn gather(&self, dim: impl Dim, index: impl AsRef<Tensor>) -> Tensor
pub fn index_add( &self, dim: impl Dim, index: &Tensor, source: &Tensor ) -> Tensor
pub fn index_select(&self, dim: impl Dim, index: impl AsRef<Tensor>) -> Tensor
pub fn to_dtype(&self, dtype: impl AsDType) -> Tensor
pub fn to_device(&self, device: impl AsDevice) -> Tensor
pub fn softmax<D: Dim>(&self, d: D) -> Tensor
pub fn log_softmax<D: Dim>(&self, d: D) -> Tensor
pub fn erf(&self) -> Tensor
pub fn clamp(&self, min: impl ClampBound, max: impl ClampBound) -> Tensor
pub fn relu(&self) -> Tensor
pub fn relu2(&self) -> Tensor
pub fn relu6(&self) -> Tensor
pub fn gelu(&self) -> Tensor
pub fn silu(&self) -> Tensor
pub fn new_gelu(&self) -> Tensor
pub fn flatten<T: FlattenArgs>(&self, args: T) -> Tensor
pub fn to_contiguous(&self) -> Tensor
pub fn squeeze(&self, d: impl Dims) -> Tensor
pub fn unsqueeze(&self, d: impl Dim) -> Tensor
pub fn permute(&self, d: impl Dims) -> Tensor
pub fn narrow(&self, dim: impl Dim, start: usize, len: usize) -> Tensor
pub fn chunk(&self, chunks: usize, dim: impl Dim) -> Vec<Tensor>
pub fn where_cond( &self, input: impl AsRef<Tensor>, other: impl AsRef<Tensor> ) -> Tensor
pub fn conv1d( &self, kernel: impl AsRef<Tensor>, padding: usize, stride: usize, dilation: usize, groups: usize ) -> Tensor
pub fn conv2d( &self, kernel: impl AsRef<Tensor>, padding: [usize; 2], stride: [usize; 2], dilation: [usize; 2], groups: usize ) -> Tensor
pub fn scatter_add( &self, dim: impl Dim, index: impl AsRef<Tensor>, source: impl AsRef<Tensor> ) -> Tensor
pub fn jvp(&self, tangent_cache: &mut HashMap<usize, Tensor>) -> Tensor
pub fn vjp(&self, cotangent_cache: &mut HashMap<usize, Tensor>)
pub fn dot_graph(&self) -> String
pub fn detach(&self)
pub fn replace_data(&self, rhs: Tensor)
pub fn set_data<T: TensorLike + 'static>(&self, data: T)
pub fn get_data<T>(&self) -> Option<impl Deref<Target = T> + '_>where
T: 'static,
pub fn as_scalar<T: Type>(&self, dtype: T) -> T::Repr
pub fn as_vec<T: Type>(&self, dtype: T) -> Vec<T::Repr>
pub fn apply<M>(&self, module: M) -> M::Outputwhere
M: Module<Input = Self>,
Self: ApplyModule<M>,
pub fn is_evaluated(&self) -> bool
pub fn to_safetensors( &self, name: impl Into<String>, filename: impl AsRef<Path> )
Trait Implementations§
source§impl GenericValue<BasicValue, Tensor, Tensor> for Tensor
impl GenericValue<BasicValue, Tensor, Tensor> for Tensor
source§impl Ord for Tensor
impl Ord for Tensor
source§impl PartialEq for Tensor
impl PartialEq for Tensor
source§impl PartialOrd for Tensor
impl PartialOrd for Tensor
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moresource§impl Shape for Tensor
impl Shape for Tensor
fn shape(&self) -> &[usize]
fn size(&self) -> usize
fn shape_at<I: Dim>(&self, i: I) -> usize
fn shape_before<const N: usize>(&self) -> [usize; N]
fn shape_of<D: Dims>(&self, d: D) -> Vec<usize>
fn size_of<D: Dims>(&self, d: D) -> usize
fn ndim(&self) -> usize
fn dim<I: Dim>(&self, i: I) -> usize
fn dims<D: Dims>(&self, d: D) -> Vec<usize>
fn shape_transpose(&self, dim0: usize, dim1: usize) -> Vec<usize>
fn shape_eq<S: Shape + ?Sized>(&self, rhs: &S) -> bool
fn shape_ndim_eq<S: Shape + ?Sized>(&self, rhs: &S) -> bool
fn shape_size_eq<S: Shape + ?Sized>(&self, rhs: &S) -> bool
fn shape_expand_left<T: Shape + ?Sized>(&self, rhs: &T) -> Vec<usize>
fn shape_broadcast<T: Shape + ?Sized>(&self, rhs: &T) -> Result<Vec<usize>>
fn shape_broadcast_matmul<S: Shape + ?Sized>( &self, rhs: &S ) -> Result<Vec<usize>>
fn shape_reduce<T: AsRef<[usize]>>(&self, dims: T, keep_dim: bool) -> Vec<usize>
fn shape_conv<S: Shape + ?Sized>( &self, kernel: &S, padding: &[usize], stride: &[usize], dilation: &[usize], groups: usize ) -> Result<Vec<usize>>
source§impl TensorIter for Tensor
impl TensorIter for Tensor
fn tensor_iter(&self) -> impl Iterator<Item = &Tensor>
source§impl WithParams for Tensor
impl WithParams for Tensor
fn gather_by_id(&self, params: &mut HashMap<usize, Tensor>)
fn update_by_id(&self, params: &mut HashMap<usize, Tensor>)
fn gather_by_name( &self, params: &mut HashMap<String, Tensor>, prefix: &str, name: &str )
fn update_by_name( &self, params: &mut HashMap<String, Tensor>, prefix: &str, name: &str )
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, M> ApplyModule<M> for Twhere
M: Module<Input = T>,
impl<T, M> ApplyModule<M> for Twhere
M: Module<Input = T>,
§impl<'short, T, Target> AsGeneralizedRef<'short, &'short Target> for T
impl<'short, T, Target> AsGeneralizedRef<'short, &'short Target> for T
fn as_generalized_ref(&'short self) -> &'short Target
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