pub struct Tensor(/* private fields */);
Implementations§
source§impl Tensor
impl Tensor
pub fn new( backend: impl Into<Box<dyn Backend>>, dtype: impl Into<Box<dyn DynDType>>, shape: impl Shape, primitive: impl Into<Box<dyn Primitive>>, inputs: impl Into<Vec<Tensor>> ) -> Self
pub fn from_safetensor( st: &TensorView<'_>, backend: impl Into<Box<dyn Backend>> ) -> Tensor
pub fn id(&self) -> usize
pub fn backend(&self) -> &dyn Backend
pub fn dtype(&self) -> &dyn DynDType
pub fn primitive(&self) -> &dyn Primitive
pub fn inputs(&self) -> impl Deref<Target = [Tensor]> + '_
pub fn full<T: ElemType>( val: T, shape: impl Shape, backend: impl Into<Box<dyn Backend>> + Debug ) -> Tensor
pub fn ones<D: DType>( shape: impl Shape, dtype: D, backend: impl Into<Box<dyn Backend>> + Debug ) -> Tensor
pub fn zeros<D: DType>( shape: impl Shape, dtype: D, backend: impl Into<Box<dyn Backend>> + Debug ) -> Tensor
pub fn full_like<T: ElemType>(&self, val: T) -> Tensor
pub fn zeros_like(&self) -> Tensor
pub fn ones_like(&self) -> Tensor
pub fn normal( shape: impl Shape, dtype: impl DType, backend: impl Into<Box<dyn Backend>> + Debug ) -> Tensor
pub fn arange<D: DType, T: ArangeArgs<D>>( args: T, backend: impl Into<Box<dyn Backend>> + Debug ) -> Tensor
pub fn from_array<T: ElemType>( data: impl Into<Vec<T>> + Debug, shape: impl Shape, backend: impl Into<Box<dyn Backend>> + Debug ) -> 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 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: &Tensor) -> Tensor
pub fn index_select(&self, dim: impl Dim, index: &Tensor) -> Tensor
pub fn as_type(&self, dtype: impl DType) -> Tensor
pub fn as_type_of(&self, rhs: &Tensor) -> 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 relu(&self) -> Tensor
pub fn gelu(&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 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: &Tensor, other: &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: ElemType>(&self) -> T
pub fn as_vec<T: ElemType>(&self) -> Vec<T>
pub fn is_evaluated(&self) -> bool
pub fn to_safetensors(&self, name: impl Into<String>, filename: &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 ndim(&self) -> usize
fn size(&self) -> usize
fn shape_at<I: Dim>(&self, i: I) -> usize
fn shape_until<I: Dim>(&self, i: I) -> &[usize]
fn shape_of<D: Dims>(&self, d: D) -> Vec<usize>
fn dim<I: Dim>(&self, i: I) -> usize
fn dims<D: Dims>(&self, d: D) -> Vec<usize>
fn size_of_dims<D: Dims>(&self, d: D) -> 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>
source§impl TensorIter for Tensor
impl TensorIter for Tensor
fn tensor_iter(&self) -> impl Iterator<Item = &Tensor>
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§
§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