Struct ktensor::math::Matrix [] [src]

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

A structure of values

Methods

impl<T> Matrix<T>
[src]

Returns a new Matrix

Arguments

  • dimensions - dimensions of Matrix
  • buffer - Vec of values

Example

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

Returns the total number of items in the Matrix

Returns the dimensions of the Matrix

Gives ownership to the buffer

Example

let vector = ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).collect()).to_flattened();
let result = vec![0, 1, 2, 3, 4, 5];
for (&i, &j) in vector.iter().zip(result.iter()) {
    assert_eq!(i, j);
}

Returns Vec of indicies from (0, 0) to (x, y) (inclusive and exclusive)

Arguments

  • Vec2 - bottom corner of indicies

Example

let matrix = ktensor::math::Matrix::new(ktensor::math::Vec2(3, 3), (0..9).collect());
let indicies = matrix.get_indicies(ktensor::math::Vec2(2, 2));
let result = vec![0, 1, 3, 4];
for (&i, &j) in indicies.iter().zip(result.iter()) {
    assert_eq!(i, j);
}

Returns Vec of indicies across the entire Matrix up to (x, y) with the specified stride length

Arguments

  • Vec2 - number of strides in directions x, y
  • stride - length of stride

Example

let matrix = ktensor::math::Matrix::new(ktensor::math::Vec2(6, 6), (0..36).collect());
let indicies = matrix.get_indicies_stride(ktensor::math::Vec2(2, 2), 2);
let matrix = matrix.to_flattened();
assert_eq!(indicies.len(), 4);
for &i in indicies.iter() {
    assert_eq!(i, matrix[i]);
}

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

Returns value at Vec2

Arguments

  • Vec2 - coordinates of the value in the Matrix

Example

let matrix = ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).collect());
assert_eq!(matrix.get(ktensor::math::Vec2(1, 2)), 5);
assert_eq!(matrix.get(ktensor::math::Vec2(1, 2)), 5);

Returns Matrix of values from [vec1 to vec2) (inclusive and exclusive)

Arguments

  • Vec2 - coordinates of the first corner
  • Vec2 - coordinates of the second corner

Example

let matrix = ktensor::math::Matrix::new(ktensor::math::Vec2(3, 3), (0..9).collect());
let slice = matrix.get_submatrix(ktensor::math::Vec2(1, 1), ktensor::math::Vec2(3, 3)).to_flattened();
let result = vec![4, 5, 7, 8];
for (&i, &j) in slice.iter().zip(result.iter()) {
    assert_eq!(i, j);
}

Consumes Matrix and returns transposed Matrix

Example

let vector = ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).collect());
let vector = vector.transpose();
assert_eq!(vector.get(ktensor::math::Vec2(2, 0)), 2);

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

Hadamard Product of Matricies by reference

Arguments

  • self - this matrix reference
  • rhs - another matrix reference

Example

let matrix1 = ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect());
let matrix2 = ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).rev().collect());
let matrix3 = &matrix1.product(&matrix2);
assert_eq!(matrix1.get(ktensor::math::Vec2(0, 2)), 2.0);
assert_eq!(matrix2.get(ktensor::math::Vec2(0, 2)), 3.0);
assert_eq!(matrix3.get(ktensor::math::Vec2(0, 2)), 6.0);

Trait Implementations

impl<T> Clone for Matrix<T> where
    T: Copy
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

The resulting type after applying the + operator

Add Matricies

Arguments

  • self - this matrix
  • rhs - another matrix

Example

let matrix1 = ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect());
let matrix2 = ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).rev().collect());
let matrix3 = matrix1 + matrix2;
assert_eq!(matrix3.get(ktensor::math::Vec2(0, 0)), 5.0);

impl<'a, 'b, T> Add<&'b Matrix<T>> for &'a Matrix<T> where
    T: Add<Output = T> + Copy
[src]

The resulting type after applying the + operator

Add Matricies by reference

Arguments

  • self - this matrix reference
  • rhs - another matrix reference

Example

let matrix1 = ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect());
let matrix2 = ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).rev().collect());
let matrix3 = &matrix1 + &matrix2;
assert_eq!(matrix1.get(ktensor::math::Vec2(0, 0)), 0.0);
assert_eq!(matrix2.get(ktensor::math::Vec2(0, 0)), 5.0);
assert_eq!(matrix3.get(ktensor::math::Vec2(0, 0)), 5.0);

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

The resulting type after applying the + operator

Add Matrix and a constant

Arguments

  • self - this matrix
  • rhs - a constant

Example

let matrix1 = ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect());
let float = 1.0;
let matrix2 = matrix1 + float;
assert_eq!(matrix2.get(ktensor::math::Vec2(0, 0)), 1.0);

impl<'a, 'b, T> Add<&'b T> for &'a Matrix<T> where
    T: Add<Output = T> + Copy
[src]

The resulting type after applying the + operator

Add Matrix and a constant

Arguments

  • self - this matrix reference
  • rhs - a constant reference

Example

let matrix1 = ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect());
let float = 1.0;
let matrix2 = &matrix1 + &float;
assert_eq!(matrix1.get(ktensor::math::Vec2(0, 0)), 0.0);
assert_eq!(matrix2.get(ktensor::math::Vec2(0, 0)), 1.0);
assert_eq!(float, 1.0);

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

The resulting type after applying the * operator

Multiply Matricies

Arguments

  • self - this matrix
  • rhs - another matrix

Example

let matrix1 = ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect());
let matrix2 = ktensor::math::Matrix::new(ktensor::math::Vec2(3, 2), (0..6).map(|i| i as f64).rev().collect());
let matrix3 = matrix1 * matrix2;
assert_eq!(matrix3.len(), 4);
assert_eq!(matrix3.get(ktensor::math::Vec2(0, 0)), 5.0);

impl<'a, 'b, T> Mul<&'b Matrix<T>> for &'a Matrix<T> where
    T: Mul<Output = T> + Add<Output = T> + Copy
[src]

The resulting type after applying the * operator

Multiply Matricies by reference

Arguments

  • self - this matrix reference
  • rhs - another matrix reference

Example

let matrix1 = ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect());
let matrix2 = ktensor::math::Matrix::new(ktensor::math::Vec2(3, 2), (0..6).map(|i| i as f64).rev().collect());
let matrix3 = &matrix1 * &matrix2;
assert_eq!(matrix3.len(), 4);
assert_eq!(matrix1.get(ktensor::math::Vec2(0, 0)), 0.0);
assert_eq!(matrix2.get(ktensor::math::Vec2(0, 0)), 5.0);
assert_eq!(matrix3.get(ktensor::math::Vec2(0, 0)), 5.0);

impl<T> Mul<T> for Matrix<T> where
    T: Mul<Output = T> + Copy
[src]

The resulting type after applying the * operator

Multiply Matrix and a constant

Arguments

  • self - this matrix
  • rhs - a constant

Example

let matrix1 = ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect());
let float = 2.0;
let matrix2 = matrix1 * float;
assert_eq!(matrix2.get(ktensor::math::Vec2(0, 2)), 4.0);

impl<'a, 'b, T> Mul<&'b T> for &'a Matrix<T> where
    T: Mul<Output = T> + Copy
[src]

The resulting type after applying the * operator

Multiply Matrix and a constant

Arguments

  • self - this matrix reference
  • rhs - a constant reference

Example

let matrix1 = ktensor::math::Matrix::new(ktensor::math::Vec2(2, 3), (0..6).map(|i| i as f64).collect());
let float = 2.0;
let matrix2 = &matrix1 * &float;
assert_eq!(matrix1.get(ktensor::math::Vec2(0, 2)), 2.0);
assert_eq!(matrix2.get(ktensor::math::Vec2(0, 2)), 4.0);
assert_eq!(float, 2.0);