Struct ktensor::tensor::Tensor
[−]
[src]
pub struct Tensor<T> { /* fields omitted */ }
Encapsulates a matrix for transfer between nodes
Methods
impl<T> Tensor<T>
[src]
fn new(dimensions: Vec2, matrix: Matrix<T>) -> Tensor<T>
returns a new Tensor
Arguments
dimensions
- dimensions of thematrix
matrix
-Matrix
encapsulated by theTensor
Example
let tensor = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).collect()));
fn from_vec(dimensions: Vec2, vector: Vec<T>) -> Tensor<T>
fn dim(&self) -> Vec2
Returns the dimensions of the Tensor
fn to_flattened(self) -> Vec<T>
Gives ownership to the matrix
buffer
Example
let tensor = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).collect())); let tensor = tensor.to_flattened(); let result = vec![0, 1, 2, 3, 4, 5]; for (&i, &j) in tensor.iter().zip(result.iter()) { assert_eq!(i, j); }
fn buffer(&self) -> &Vec<T>
fn get_convolutions()
max_num_strides = (dim - width) / stride + 1
impl<T> Tensor<T> where
T: Copy,
[src]
T: Copy,
fn transpose(&self) -> Tensor<T>
Transpose Tensor
Example
let tensor = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).collect())); let tensor2 = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).collect())); let tensor2 = tensor2.transpose(); let tensor3 = tensor * tensor2; let tensor3 = tensor3.to_flattened(); assert_eq!(tensor3[2], 14);
fn get(&self, vec2: Vec2) -> T
impl Tensor<f64>
[src]
fn from_gaussian(dimensions: Vec2, input_dim: usize) -> Tensor<f64>
impl Tensor<f32>
[src]
fn from_gaussian(dimensions: Vec2, input_dim: usize) -> Tensor<f32>
impl<'a, T> Tensor<T> where
T: Mul<Output = T> + Copy,
[src]
T: Mul<Output = T> + Copy,
fn product(&self, rhs: &'a Tensor<T>) -> Tensor<T>
Hadamard Product of Tensors by reference
Arguments
self
- this tensor referencerhs
- another tensor reference
Example
let tensor1 = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect())); let tensor2 = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).rev().collect())); let tensor3 = tensor1.product(&tensor2); let tensor1 = tensor1.to_flattened(); let tensor2 = tensor2.to_flattened(); let tensor3 = tensor3.to_flattened(); assert_eq!(tensor1[2], 2.0); assert_eq!(tensor2[2], 3.0); assert_eq!(tensor3[2], 6.0);
Trait Implementations
impl<T> Clone for Tensor<T> where
T: Copy,
[src]
T: Copy,
fn clone(&self) -> Tensor<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<T> Add<Tensor<T>> for Tensor<T> where
T: Add<Output = T> + Copy,
[src]
T: Add<Output = T> + Copy,
type Output = Tensor<T>
The resulting type after applying the +
operator
fn add(self, rhs: Tensor<T>) -> Tensor<T>
Add Tensor
s
Arguments
self
- this tensorrhs
- another tensor
Example
let tensor1 = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect())); let tensor2 = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).rev().collect())); let tensor3 = tensor1 + tensor2; let tensor3 = tensor3.to_flattened(); assert_eq!(tensor3[0], 5.0);
impl<'a, 'b, T> Add<&'b Tensor<T>> for &'a Tensor<T> where
T: Add<Output = T> + Copy,
[src]
T: Add<Output = T> + Copy,
type Output = Tensor<T>
The resulting type after applying the +
operator
fn add(self, rhs: &'b Tensor<T>) -> Tensor<T>
Add Tensor
s by reference
Arguments
self
- this tensor referencerhs
- another tensor reference
Example
let tensor1 = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect())); let tensor2 = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).rev().collect())); let tensor3 = &tensor1 + &tensor2; let tensor1 = tensor1.to_flattened(); let tensor2 = tensor2.to_flattened(); let tensor3 = tensor3.to_flattened(); assert_eq!(tensor1[0], 0.0); assert_eq!(tensor2[0], 5.0); assert_eq!(tensor3[0], 5.0);
impl<T> Add<T> for Tensor<T> where
T: Add<Output = T> + Copy,
[src]
T: Add<Output = T> + Copy,
type Output = Tensor<T>
The resulting type after applying the +
operator
fn add(self, rhs: T) -> Tensor<T>
Add Tensor
and a constant
Arguments
self
- thisTensor
rhs
- a constant
Example
let tensor1 = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect())); let float = 1.0; let tensor2 = tensor1 + float; let tensor2 = tensor2.to_flattened(); assert_eq!(tensor2[0], 1.0);
impl<'a, 'b, T> Add<&'b T> for &'a Tensor<T> where
T: Add<Output = T> + Copy,
[src]
T: Add<Output = T> + Copy,
type Output = Tensor<T>
The resulting type after applying the +
operator
fn add(self, rhs: &'b T) -> Tensor<T>
Add Tensor
and a constant
Arguments
self
- this tensor referencerhs
- a constant reference
Example
let tensor1 = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect())); let float = 1.0; let tensor2 = &tensor1 + &float; let tensor1 = tensor1.to_flattened(); let tensor2 = tensor2.to_flattened(); assert_eq!(tensor1[0], 0.0); assert_eq!(tensor2[0], 1.0); assert_eq!(float, 1.0);
impl<T> Mul<Tensor<T>> for Tensor<T> where
T: Mul<Output = T> + Add<Output = T> + Copy,
[src]
T: Mul<Output = T> + Add<Output = T> + Copy,
type Output = Tensor<T>
The resulting type after applying the *
operator
fn mul(self, rhs: Tensor<T>) -> Tensor<T>
Multiply Tensor
s`
Arguments
self
- this tensorrhs
- another tensor
Example
let tensor1 = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect())); let tensor2 = ktensor::Tensor::new(ktensor::math::Vec2(3, 2), ktensor::math::Matrix::new(ktensor::math::Vec2(3, 2), (0..6).map(|i| i as f64).rev().collect())); let tensor3 = tensor1 * tensor2; let tensor3 = tensor3.to_flattened(); assert_eq!(tensor3.len(), 4); assert_eq!(tensor3[0], 5.0);
impl<'a, 'b, T> Mul<&'b Tensor<T>> for &'a Tensor<T> where
T: Mul<Output = T> + Add<Output = T> + Copy,
[src]
T: Mul<Output = T> + Add<Output = T> + Copy,
type Output = Tensor<T>
The resulting type after applying the *
operator
fn mul(self, rhs: &'b Tensor<T>) -> Tensor<T>
Multiply Tensor
s` by reference
Arguments
self
- this tensor referencerhs
- another tensor reference
Example
let tensor1 = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect())); let tensor2 = ktensor::Tensor::new(ktensor::math::Vec2(3, 2), ktensor::math::Matrix::new(ktensor::math::Vec2(3, 2), (0..6).map(|i| i as f64).rev().collect())); let tensor3 = &tensor1 * &tensor2; let tensor1 = tensor1.to_flattened(); let tensor2 = tensor2.to_flattened(); let tensor3 = tensor3.to_flattened(); assert_eq!(tensor3.len(), 4); assert_eq!(tensor1[0], 0.0); assert_eq!(tensor2[0], 5.0); assert_eq!(tensor3[0], 5.0);
impl<T> Mul<T> for Tensor<T> where
T: Mul<Output = T> + Copy,
[src]
T: Mul<Output = T> + Copy,
type Output = Tensor<T>
The resulting type after applying the *
operator
fn mul(self, rhs: T) -> Tensor<T>
Multiply Tensor
and a constant
Arguments
self
- this tensorrhs
- a constant
Example
let tensor1 = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect())); let float = 2.0; let tensor2 = tensor1 * float; let tensor2 = tensor2.to_flattened(); assert_eq!(tensor2[2], 4.0);
impl<'a, 'b, T> Mul<&'b T> for &'a Tensor<T> where
T: Mul<Output = T> + Copy,
[src]
T: Mul<Output = T> + Copy,
type Output = Tensor<T>
The resulting type after applying the *
operator
fn mul(self, rhs: &'b T) -> Tensor<T>
Multiply Tensor
and a constant
Arguments
self
- this tensor referencerhs
- a constant reference
Example
let tensor1 = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect())); let float = 2.0; let tensor2 = &tensor1 * &float; let tensor1 = tensor1.to_flattened(); let tensor2 = tensor2.to_flattened(); assert_eq!(tensor1[2], 2.0); assert_eq!(tensor2[2], 4.0); assert_eq!(float, 2.0);