Struct ktensor::tensor::Tensor [] [src]

pub struct Tensor<T> { /* fields omitted */ }

Encapsulates a matrix for transfer between nodes

Methods

impl<T> Tensor<T>
[src]

returns a new Tensor

Arguments

  • dimensions - dimensions of the matrix
  • matrix - Matrix encapsulated by the Tensor

Example

let tensor = ktensor::Tensor::new(ktensor::math::Vec2(2, 3), ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).collect()));

Returns the dimensions of the Tensor

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

max_num_strides = (dim - width) / stride + 1

impl<T> Tensor<T> where
    T: Copy
[src]

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

impl Tensor<f64>
[src]

generates a random valued Tensor with a standard deviation of 1

Arguments

  • dimensions - dimensions of Tensor

Example

let tensor = ktensor::Tensor::<f64>::from_gaussian(ktensor::math::Vec2(5, 5), 2);

impl Tensor<f32>
[src]

generates a random valued matrix with a standard deviation of 1

Arguments

  • dimensions - dimensions of Tensor

Example

let tensor = ktensor::Tensor::<f32>::from_gaussian(ktensor::math::Vec2(5, 5), 2);

impl<'a, T> Tensor<T> where
    T: Mul<Output = T> + Copy
[src]

Hadamard Product of Tensors by reference

Arguments

  • self - this tensor reference
  • rhs - 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]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T> Add<Tensor<T>> for Tensor<T> where
    T: Add<Output = T> + Copy
[src]

The resulting type after applying the + operator

Add Tensors

Arguments

  • self - this tensor
  • rhs - 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]

The resulting type after applying the + operator

Add Tensors by reference

Arguments

  • self - this tensor reference
  • rhs - 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]

The resulting type after applying the + operator

Add Tensor and a constant

Arguments

  • self - this Tensor
  • 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]

The resulting type after applying the + operator

Add Tensor and a constant

Arguments

  • self - this tensor reference
  • rhs - 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]

The resulting type after applying the * operator

Multiply Tensors`

Arguments

  • self - this tensor
  • rhs - 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]

The resulting type after applying the * operator

Multiply Tensors` by reference

Arguments

  • self - this tensor reference
  • rhs - 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]

The resulting type after applying the * operator

Multiply Tensor and a constant

Arguments

  • self - this tensor
  • 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 = 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]

The resulting type after applying the * operator

Multiply Tensor and a constant

Arguments

  • self - this tensor reference
  • rhs - 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);