pub struct Tensor { /* private fields */ }
Implementations§
Source§impl Tensor
impl Tensor
pub fn new() -> Tensor
pub fn data_copy(&self, o: &Tensor)
pub fn swap(&self, o: &Tensor)
pub fn ref_copy(&self) -> Tensor
Sourcepub fn index2dimpos(&self, index: usize) -> Vec<usize>
pub fn index2dimpos(&self, index: usize) -> Vec<usize>
Right most is the continous indexing, This method convert continuous index to index along each dimension.
Sourcepub fn dimpos2index(&self, dimpos: &[usize]) -> usize
pub fn dimpos2index(&self, dimpos: &[usize]) -> usize
Right most is the continous indexing, This method convert index along each dimension to continuous index.
pub fn is_empty() -> bool
pub fn size(&self) -> Vec<usize>
pub fn numel(&self) -> usize
pub fn get_scale_f32(&self) -> f32
pub fn get_scale_f64(&self) -> f64
pub fn get_n(&self) -> Tensor
pub fn get_c(&self) -> Tensor
pub fn get_d(&self) -> Tensor
pub fn get_h(&self) -> Tensor
pub fn get_w(&self) -> Tensor
pub fn numel_tensor(&self) -> Tensor
pub fn get_patch( &self, range: &[(usize, usize)], step: Option<&[usize]>, ) -> Tensor
pub fn set_patch( &self, other: &Tensor, range: &[(usize, usize)], step: Option<&[usize]>, ) -> Tensor
pub fn same_shape(&self, o: &Tensor) -> bool
pub fn from_vec_usize(input: &[usize], dim: &[usize]) -> Tensor
Sourcepub fn from_vec_f32(input: &[f32], dim: &[usize]) -> Tensor
pub fn from_vec_f32(input: &[f32], dim: &[usize]) -> Tensor
Create a tensor from a Vec,
let t1 = Tensor::from_vec_f32(&vec![0., 1., 2., 4.,], &vec![2,2]);
Sourcepub fn get_raw_f32(&self) -> Vec<f32>
pub fn get_raw_f32(&self) -> Vec<f32>
return the internal buffer May fail if the underlying data is f64
pub fn from_vec_f64(input: &[f64], dim: &[usize]) -> Tensor
Sourcepub fn get_raw_f64(&self) -> Vec<f64>
pub fn get_raw_f64(&self) -> Vec<f64>
return the internal buffer May fail if the underlying data is f32
pub fn from_record_f32( &self, row: usize, record: &[f32], ) -> Result<(), &'static str>
pub fn from_record_f64( &self, row: usize, record: &[f64], ) -> Result<(), &'static str>
pub fn get_f32(&self, o: &[usize]) -> f32
pub fn set_f32(&mut self, o: &[usize], v: f32)
pub fn get_f64(&self, o: &[usize]) -> f64
pub fn set_f64(&mut self, o: &[usize], v: f64)
Sourcepub fn fill(size: &[usize], fill_value: &Tensor) -> Tensor
pub fn fill(size: &[usize], fill_value: &Tensor) -> Tensor
Returns a tensor of size size filled with fill_value.
pub fn fill_f32(size: &[usize], fill_value: f32) -> Tensor
pub fn fill_f64(size: &[usize], fill_value: f64) -> Tensor
pub fn zeros(dim: &[usize]) -> Tensor
pub fn zeros_like(&self) -> Tensor
pub fn ones(dim: &[usize]) -> Tensor
pub fn twos(dim: &[usize]) -> Tensor
pub fn int_n(dim: &[usize], n: isize) -> Tensor
pub fn ones_like(&self) -> Tensor
pub fn range(start: f32, end: f32, step: Option<f32>) -> Tensor
pub fn linspace(start: f32, end: f32, steps: usize) -> Tensor
pub fn logspace(start: f32, end: f32, steps: usize, base: f32) -> Tensor
pub fn eye(n: usize, m: usize) -> Tensor
pub fn empty(shape: &[usize]) -> Tensor
pub fn log10_like(&self) -> Tensor
pub fn log2_like(&self) -> Tensor
pub fn cat(&self, tensors: &[Tensor], dim: usize) -> Tensor
pub fn chunk(&self, chunks: usize, dim: usize) -> Vec<Tensor>
pub fn gather(&self, dim: usize, index: &Tensor) -> Tensor
pub fn spread(&self, dim: usize, index: &Tensor, value: &Tensor) -> Tensor
pub fn index_select(&self, dim: usize, index: &Tensor) -> Tensor
pub fn index_exclude(&self, dim: usize, index: &Tensor) -> Tensor
pub fn masked_select()
pub fn narrow()
pub fn nonzero()
pub fn reshape(&self, new_shape: &[usize]) -> Tensor
pub fn split(&self, sections: &[usize], dim: usize) -> Vec<Tensor>
pub fn squeeze(&self, dim: Option<usize>) -> Tensor
pub fn stack(&self, tensors: &[Tensor], dim: usize) -> Tensor
pub fn t(&self) -> Tensor
pub fn take(&self, index: &[usize]) -> Tensor
pub fn transpose()
pub fn unbind()
pub fn permute(&self, dim: &[usize]) -> Tensor
Sourcepub fn unsqueeze(&self, dim: usize) -> Tensor
pub fn unsqueeze(&self, dim: usize) -> Tensor
Returns a new tensor with a dimension of size one inserted at the specified position.
The returned tensor shares the same underlying data with this tensor.
pub fn conditional_select(&self, x: &Tensor, y: &Tensor) -> Tensor
pub fn repeat(&self, dim: &[usize]) -> Tensor
pub fn to_f64(&mut self)
pub fn to_f32(&mut self)
pub fn abs(&self) -> Tensor
pub fn acos(&self) -> Tensor
pub fn asin(&self) -> Tensor
pub fn atan(&self) -> Tensor
pub fn ceil(&self) -> Tensor
pub fn cos(&self) -> Tensor
pub fn cosh(&self) -> Tensor
pub fn exp(&self) -> Tensor
pub fn expm1(&self) -> Tensor
pub fn floor(&self) -> Tensor
pub fn frac(&self) -> Tensor
pub fn lerp(&self, end: &Tensor, weight: &Tensor) -> Tensor
pub fn log(&self) -> Tensor
pub fn log10(&self) -> Tensor
pub fn log1p(&self) -> Tensor
pub fn log1pexp(&self) -> Tensor
pub fn log2(&self) -> Tensor
pub fn neg(&self) -> Tensor
pub fn pow_f32(&self, n: f32) -> Tensor
pub fn reciprocal(&self) -> Tensor
pub fn round(&self) -> Tensor
pub fn rsqrt(&self) -> Tensor
pub fn sigmoid(&self) -> Tensor
pub fn sign(&self) -> Tensor
pub fn sin(&self) -> Tensor
pub fn sinh(&self) -> Tensor
pub fn sqrt(&self) -> Tensor
pub fn square(&self) -> Tensor
pub fn tan(&self) -> Tensor
pub fn tanh(&self) -> Tensor
pub fn trunc(&self) -> Tensor
pub fn add(&self, o: &Tensor) -> Tensor
pub fn sub(&self, o: &Tensor) -> Tensor
pub fn mul(&self, o: &Tensor) -> Tensor
pub fn div(&self, o: &Tensor) -> Tensor
pub fn mm(&self, o: &Tensor) -> Tensor
pub fn matmul(&self, o: &Tensor) -> Tensor
pub fn outer(&self, o: &Tensor, avg: Option<bool>) -> Tensor
pub fn argmax(&self, dim: Option<&[usize]>, keepdim: bool) -> Tensor
pub fn argmin(&self, dim: Option<&[usize]>, keepdim: bool) -> Tensor
pub fn logsumexp(&self, dim: Option<&[usize]>, keepdim: bool) -> Tensor
pub fn mean(&self, dim: Option<&[usize]>, keepdim: bool) -> Tensor
pub fn prod(&self, dim: Option<&[usize]>, keepdim: bool) -> Tensor
pub fn std(&self, dim: Option<&[usize]>, keepdim: bool) -> Tensor
pub fn sum(&self, dim: Option<&[usize]>, keepdim: bool) -> Tensor
pub fn var(&self, dim: Option<&[usize]>, keepdim: bool) -> Tensor
pub fn max(&self, dim: Option<&[usize]>, keepdim: bool) -> Tensor
pub fn min(&self, dim: Option<&[usize]>, keepdim: bool) -> Tensor
pub fn normalize_unit(&self) -> Tensor
pub fn lu(&self) -> Option<[Tensor; 2]>
pub fn lu_solve(&self, o: &Tensor) -> Option<Tensor>
pub fn qr(&self) -> Option<[Tensor; 2]>
pub fn eigen(&self) -> Option<[Tensor; 2]>
pub fn cholesky(&self) -> Option<Tensor>
pub fn det(&self) -> Option<Tensor>
pub fn svd(&self) -> Option<[Tensor; 3]>
pub fn inv(&self) -> Option<Tensor>
pub fn pinv(&self) -> Tensor
pub fn tr(&self) -> Tensor
pub fn all_close(&self, o: &Tensor) -> Tensor
pub fn arg_sort(&self, dim: usize, descending: bool) -> Tensor
pub fn eq_t(&self, o: &Tensor) -> Tensor
pub fn equal(&self, o: &Tensor) -> bool
pub fn ge(&self, o: &Tensor) -> Tensor
pub fn gt(&self, o: &Tensor) -> Tensor
pub fn le(&self, o: &Tensor) -> Tensor
pub fn lt(&self, o: &Tensor) -> Tensor
pub fn max_pair(&self, o: &Tensor) -> Tensor
pub fn min_pair(&self, o: &Tensor) -> Tensor
pub fn ne(&self, o: &Tensor) -> Tensor
pub fn rand_usize( rng: &mut StdRng, dim: &[usize], left: usize, right: usize, ) -> Tensor
pub fn normal_f64( rng: &mut StdRng, dim: &[usize], mean: f64, std: f64, ) -> Tensor
pub fn normal_f32( rng: &mut StdRng, dim: &[usize], mean: f32, std: f32, ) -> Tensor
pub fn uniform_f64( rng: &mut StdRng, dim: &[usize], from: f64, to: f64, ) -> Tensor
pub fn uniform_f32( rng: &mut StdRng, dim: &[usize], from: f32, to: f32, ) -> Tensor
pub fn conv2d( &self, weight: &Tensor, stride: (usize, usize), padding: (usize, usize), dilation: (usize, usize), padding_mode: PaddingMode, ) -> Tensor
pub fn conv2d_grad( &self, weight: &Tensor, stride: (usize, usize), padding: (usize, usize), dilation: (usize, usize), padding_mode: PaddingMode, output_grad: &Tensor, ) -> (Tensor, Tensor)
pub fn inner(&self) -> Rc<RefCell<TypedTensor>>
pub fn set_inner(tt: TypedTensor) -> Tensor
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Tensor
impl<'de> Deserialize<'de> for Tensor
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Tensor
Auto Trait Implementations§
impl Freeze for Tensor
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> 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