pub struct GenTensor<T> { /* private fields */ }
Expand description

Naive tensor implementation, single thread

Implementations

Creation Ops

Create a tensor with given Vec.

Convert 1 dim index to multi-dim index.

Convert multi-dim index to 1 dim index.

Create a tensor filled with the same value d

let m1 = GenTensor::<f64>::fill(1., &vec![3,5,2]);

assign a row.

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]);

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.);

dump the underlying vec

dump the single value in the tensor if it is the single value in the tensor.

get NCHW elements, always return the size of left most dimension.

get NCHW elements, always return the size of second left most dimension.

get NCDHW elements, will require the self.dim has 5 dimensions.

get NCDHW elements, will require the self.dim has 5 dimensions or 4 dimensions.

get NCDHW elements, will require the self.dim has 5 dimensions or 4 dimensions.

Returns the size of the self tensor.

Returns the total number of elements in the input tensor

Returns the total number of elements in the input tensor

Return portion of the image. Every range of each dim with inclusive start and exclusive end.

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.);

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]), "");

Project a vector onto another one.

matrix multiplication of two tensor This is also for dot/inner product.

outer product of right-most dimensions.

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.);

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)

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Concatenates the given sequence of seq tensors in the given dimension.

Splits a tensor into a specific number of chunks.

Splits the tensor into chunks. Each chunk is a view of the original tensor.

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 = m1.stack(&vec![m2], 1);
let raw = result.get_raw();
for i in raw {
    println!("{}", i);
}
assert_eq!(*result.size(), vec![3,2,2]);

Returns a new tensor with the elements of input at the given indices. The input tensor is treated as if it were viewed as a 1-D tensor. The result takes the same shape as the indices.

Permute the dimensions of this tensor.

let mut m1 = GenTensor::<f64>::fill(1., &vec![2, 3, 5]);
m1.permute(&vec![2, 0, 1]);

Pick elements on the given dimension by the index given in index, and gather them in the output. A restriction os that self size and index size should be the same. Read more

Select on dim and collect those subtensor by index.

Inverse of index_select, remove those subtensor by index along dim.

Just change the index boundary.

Remove dimension with length of 1.

Transpose

Add size 1 dimension at dim.

Self is the bool condition, at each position of self, select from x if self at the position is true, Otherwise , use value from y. The restriction is that, self, x, and y all have the same size. Read more

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)

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Generate a random int close on left, open on right.

Returns the mean value of the tensor along dim row.

Returns the sum of all elements.

let m1 = GenTensor::<f64>::new_raw(&vec![1.,2.,3.,4.,], &vec![2,2]);
assert_eq!(m1.sum(None, false).get_scale(), 10.);

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.