[−][src]Struct auto_diff::tensor::gen_tensor::GenTensor
Naive tensor implementation, single thread
Methods
impl<T> GenTensor<T> where
T: Float,
[src]
T: Float,
pub fn new() -> GenTensor<T>
[src]
Creation Ops
pub fn new_raw(data: &[T], shape: &[usize]) -> GenTensor<T>
[src]
Create a tensor with given Vec.
pub fn zeros_like(&self) -> GenTensor<T>
[src]
pub fn ones_like(&self) -> GenTensor<T>
[src]
pub fn empty(shape: &[usize]) -> GenTensor<T>
[src]
pub fn fill(d: T, shape: &[usize]) -> GenTensor<T>
[src]
Create a tensor filled with the same value d
let m1 = GenTensor::<f64>::fill(1., &vec![3,5,2]);
pub fn stride(&self) -> Vec<usize>
[src]
Right dimension changes fastest. Right dimension has the stride 1.
let m1 = GenTensor::<f64>::new_raw(&vec![0.; 3*5*2], &vec![3,5,2]); assert_eq!(m1.stride(), vec![10,2,1]);
pub fn get(&self, o: &[usize]) -> T
[src]
Return value at the index of the tensor.
let m1 = GenTensor::<f64>::new_raw(&vec![1.,2.,3.,4.,5.,6.], &vec![2,3]); assert_eq!(m1.get(&vec![1,1]), 5.);
pub fn get_mut(&mut self, o: &[usize]) -> &mut T
[src]
pub fn get_raw(&self) -> Vec<T>
[src]
dump the underlying vec
pub fn get_scale(&self) -> T
[src]
dump the single value in the tensor if it is the single value in the tensor.
pub fn get_N(&self) -> GenTensor<T>
[src]
get NCHW elements, always return the size of left most dimension.
pub fn get_C(&self) -> GenTensor<T>
[src]
get NCHW elements, always return the size of second left most dimension.
pub fn get_D(&self) -> GenTensor<T>
[src]
get NCDHW elements, will require the self.dim has 5 dimensions.
pub fn get_H(&self) -> GenTensor<T>
[src]
get NCDHW elements, will require the self.dim has 5 dimensions or 4 dimensions.
pub fn get_W(&self) -> GenTensor<T>
[src]
get NCDHW elements, will require the self.dim has 5 dimensions or 4 dimensions.
pub fn size(&self) -> Vec<usize>
[src]
Returns the size of the self tensor.
pub fn numel(&self) -> usize
[src]
Returns the total number of elements in the input tensor
pub fn numel_tensor(&self) -> GenTensor<T>
[src]
Returns the total number of elements in the input tensor
pub fn sum(&self) -> GenTensor<T>
[src]
Returns the sum of all elements.
let m1 = GenTensor::<f64>::new_raw(&vec![1.,2.,3.,4.,], &vec![2,2]); assert_eq!(m1.sum().get_scale(), 10.);
pub fn mean(&self, dim: usize, keepdim: bool) -> GenTensor<T>
[src]
Returns the mean value of the tensor along dim row.
pub fn unsqueeze(&self, dim: &[usize])
[src]
pub fn log1pexp(&self) -> GenTensor<T>
[src]
Better log(1 + exp(x)) see https://cran.r-project.org/web/packages/Rmpfr/vignettes/log1mexp-note.pdf
pub fn neg(&self) -> GenTensor<T>
[src]
pub fn sigmoid(&self) -> GenTensor<T>
[src]
pub fn _right_broadcast<F>(&self, o: &GenTensor<T>, closure: F) -> GenTensor<T> where
F: Fn(&T, &T) -> T,
[src]
F: Fn(&T, &T) -> T,
pub fn add(&self, o: &GenTensor<T>) -> GenTensor<T>
[src]
element-wise add with right-hand broadcast.
let m1 = GenTensor::<f64>::new_raw(&vec![1.,2.,3.,4.,], &vec![2,2]); let m2 = GenTensor::<f64>::new_raw(&vec![1.,2.,3.,4.,], &vec![2,2]); let m3 = m1.add(&m2); assert_eq!(m3.get(&vec![0,0]), 2.); assert_eq!(m3.get(&vec![1,1]), 8.);
pub fn sub(&self, o: &GenTensor<T>) -> GenTensor<T>
[src]
pub fn mul(&self, o: &GenTensor<T>) -> GenTensor<T>
[src]
pub fn div(&self, o: &GenTensor<T>) -> GenTensor<T>
[src]
pub fn mm(&self, o: &GenTensor<T>) -> GenTensor<T>
[src]
matrix multiplication
let m1 = GenTensor::<f64>::new_raw(&vec![1.,2.,3.,4.,5.,6.], &vec![3,2]); let m2 = GenTensor::<f64>::new_raw(&vec![2.,3.,4.,5.,6.,7.], &vec![2,3]); let mut result = m1.mm(&m2); assert!(result == GenTensor::<f64>::new_raw(&vec![12.,15.,18.,26.,33.,40.,40.,51.,62.,], &vec![3,3]), "");
pub fn matmul(&self, o: &GenTensor<T>) -> GenTensor<T>
[src]
matrix multiplication of two tensor
pub fn outer(&self, o: &GenTensor<T>) -> GenTensor<T>
[src]
outer product of right-most dimensions.
pub fn squared_error(t1: &Self, t2: &Self) -> GenTensor<T>
[src]
pub fn stack(tensors: &[&Self], dim: usize) -> GenTensor<T>
[src]
Concatenates sequence of tensors along a new dimension.
All tensors need to be of the same size.
let m1 = GenTensor::<f64>::new_raw(&vec![1.,2.,3.,4.,5.,6.], &vec![3,2]); let m2 = GenTensor::<f64>::new_raw(&vec![2.,3.,4.,5.,6.,7.], &vec![3,2]); let result = GenTensor::<f64>::stack(&vec![&m1, &m2], 1); let raw = result.get_raw(); for i in raw { println!("{}", i); } assert_eq!(result.size(), vec![3,2,2]);
pub fn permute(&self, dims: &[usize]) -> GenTensor<T>
[src]
Permute the dimensions of this tensor.
let mut m1 = GenTensor::<f64>::fill(1., &vec![2, 3, 5]); m1.permute(&vec![2, 0, 1]);
pub fn all_close(&self, o: &GenTensor<T>) -> GenTensor<T>
[src]
pub fn arg_sort(&self, dim: usize, descending: bool) -> GenTensor<T>
[src]
pub fn eq_t(&self, o: &GenTensor<T>) -> GenTensor<T>
[src]
Computes element-wise equality use eq_t instead, as eq is reserved for == overloading.
let m1 = GenTensor::<f64>::new_raw(&vec![1.,2.,3.,4.,5.,6.], &vec![3,2]); let m2 = GenTensor::<f64>::new_raw(&vec![1.,2.,3.,4.,5.,6.], &vec![3,2]); assert_eq!(m1.eq_t(&m2).get(&vec![0,0]), 1.); assert_eq!(m1.eq_t(&m2).get(&vec![2,1]), 1.);
pub fn equal(&self, o: &GenTensor<T>) -> bool
[src]
true if two tensors have the same size and elements, false otherwise.
let m1 = GenTensor::<f64>::fill(1., &vec![3,5,2]); let m2 = GenTensor::<f64>::fill(1., &vec![3,5,2]); assert_eq!(m1.equal(&m2), true)
pub fn ge(&self, o: &GenTensor<T>) -> GenTensor<T>
[src]
pub fn gt(&self, o: &GenTensor<T>) -> GenTensor<T>
[src]
pub fn le(&self, o: &GenTensor<T>) -> GenTensor<T>
[src]
pub fn lt(&self, o: &GenTensor<T>) -> GenTensor<T>
[src]
pub fn ne(&self, o: &GenTensor<T>) -> GenTensor<T>
[src]
Trait Implementations
impl<T> Clone for GenTensor<T> where
T: Float,
[src]
T: Float,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for GenTensor<f32>
[src]
impl Debug for GenTensor<f64>
[src]
impl Display for GenTensor<f32>
[src]
impl Display for GenTensor<f64>
[src]
impl<T> Eq for GenTensor<T> where
T: Float,
[src]
T: Float,
impl<T> PartialEq<GenTensor<T>> for GenTensor<T> where
T: Float,
[src]
T: Float,
let m1 = GenTensor::<f64>::fill(1., &vec![3,5,2]); let m2 = GenTensor::<f64>::fill(1., &vec![3,5,2]); assert_eq!(m1==m2, true)
Auto Trait Implementations
impl<T> RefUnwindSafe for GenTensor<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for GenTensor<T> where
T: Send,
T: Send,
impl<T> Sync for GenTensor<T> where
T: Sync,
T: Sync,
impl<T> Unpin for GenTensor<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for GenTensor<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,