Struct rusty_machine::prelude::MatrixSlice [] [src]

pub struct MatrixSlice<'a, T> where T: 'a {
    // some fields omitted
}

A MatrixSlice

This struct provides a slice into a matrix.

The struct contains the upper left point of the slice and the width and height of the slice.

Methods

impl<'a, T> MatrixSlice<'a, T>

fn iter_rows(&self) -> Rows<T>

Iterate over the rows of the matrix slice.

Examples

use rulinalg::matrix::{Matrix, MatrixSlice};

let a = Matrix::new(3, 2, (0..6).collect::<Vec<usize>>());
let b = MatrixSlice::from_matrix(&a, [0,0], 2, 2);

// Prints "2" two times.
for row in b.iter_rows() {
    println!("{}", row.len());
}

impl<'a, T> MatrixSlice<'a, T>

fn from_matrix(mat: &'a Matrix<T>, start: [usize; 2], rows: usize, cols: usize) -> MatrixSlice<'a, T>

Produce a matrix slice from a matrix

Examples

use rulinalg::matrix::Matrix;
use rulinalg::matrix::MatrixSlice;

let a = Matrix::new(3,3, (0..9).collect::<Vec<usize>>());
let slice = MatrixSlice::from_matrix(&a, [1,1], 2, 2);

unsafe fn from_raw_parts(ptr: *const T, rows: usize, cols: usize, row_stride: usize) -> MatrixSlice<'a, T>

Creates a matrix slice from raw parts.

Examples

use rulinalg::matrix::MatrixSlice;

let mut a = vec![4.0; 16];

unsafe {
    // Create a matrix slice with 3 rows, and 3 cols
    // The row stride of 4 specifies the distance between the start of each row in the data.
    let b = MatrixSlice::from_raw_parts(a.as_ptr(), 3, 3, 4);
}

Safety

The pointer must be followed by a contiguous slice of data larger than row_stride * rows. If not then other operations will produce undefined behaviour.

Additionally cols should be less than the row_stride. It is possible to use this function safely whilst violating this condition. So long as max(cols, row_stride) * rows is less than the data size.

fn reslice(self, start: [usize; 2], rows: usize, cols: usize) -> MatrixSlice<'a, T>

Produce a matrix slice from an existing matrix slice.

Examples

use rulinalg::matrix::Matrix;
use rulinalg::matrix::MatrixSlice;

let a = Matrix::new(3,3, (0..9).collect::<Vec<usize>>());
let slice = MatrixSlice::from_matrix(&a, [1,1], 2, 2);
let new_slice = slice.reslice([0,0], 1, 1);

fn iter(&self) -> SliceIter<'a, T>

Returns an iterator over the matrix slice.

Examples

use rulinalg::matrix::Matrix;
use rulinalg::matrix::MatrixSlice;

let a = Matrix::new(3,3, (0..9).collect::<Vec<usize>>());
let slice = MatrixSlice::from_matrix(&a, [1,1], 2, 2);

let slice_data = slice.iter().map(|v| *v).collect::<Vec<usize>>();
assert_eq!(slice_data, vec![4,5,7,8]);

impl<'a, T> MatrixSlice<'a, T> where T: Copy

fn into_matrix(self) -> Matrix<T>

Convert the matrix slice into a new Matrix.

Trait Implementations

impl<'a, T> Index<[usize; 2]> for MatrixSlice<'a, T>

Indexes matrix slice. Takes row index first then column.

type Output = T

fn index(&self, idx: [usize; 2]) -> &T

impl<'a, T> Mul<T> for MatrixSlice<'a, T> where T: Copy + Mul<T, Output=T>

Scalar multiplication with matrix slice.

type Output = Matrix<T>

The resulting type after applying the * operator

fn mul(self, f: T) -> Matrix<T>

The method for the * operator

impl<'a, 'b, T> Mul<&'b T> for MatrixSlice<'a, T> where T: Copy + Mul<T, Output=T>

Scalar multiplication with matrix slice.

type Output = Matrix<T>

The resulting type after applying the * operator

fn mul(self, f: &T) -> Matrix<T>

The method for the * operator

impl<'a, 'b, T> Mul<T> for &'b MatrixSlice<'a, T> where T: Copy + Mul<T, Output=T>

Scalar multiplication with matrix slice.

type Output = Matrix<T>

The resulting type after applying the * operator

fn mul(self, f: T) -> Matrix<T>

The method for the * operator

impl<'a, 'b, 'c, T> Mul<&'c T> for &'b MatrixSlice<'a, T> where T: Copy + Mul<T, Output=T>

Scalar multiplication with matrix slice.

type Output = Matrix<T>

The resulting type after applying the * operator

fn mul(self, f: &T) -> Matrix<T>

The method for the * operator

impl<'a, T> Div<T> for MatrixSlice<'a, T> where T: Copy + Div<T, Output=T>

Scalar division with matrix slice.

type Output = Matrix<T>

fn div(self, f: T) -> Matrix<T>

impl<'a, 'b, T> Div<&'b T> for MatrixSlice<'a, T> where T: Copy + Div<T, Output=T>

Scalar division with matrix slice.

type Output = Matrix<T>

fn div(self, f: &T) -> Matrix<T>

impl<'a, 'b, T> Div<T> for &'b MatrixSlice<'a, T> where T: Copy + Div<T, Output=T>

Scalar division with matrix slice.

type Output = Matrix<T>

fn div(self, f: T) -> Matrix<T>

impl<'a, 'b, 'c, T> Div<&'c T> for &'b MatrixSlice<'a, T> where T: Copy + Div<T, Output=T>

Scalar division with matrix slice.

type Output = Matrix<T>

fn div(self, f: &T) -> Matrix<T>

impl<'a, T> Add<T> for MatrixSlice<'a, T> where T: Copy + Add<T, Output=T>

Scalar addition with matrix slice.

type Output = Matrix<T>

The resulting type after applying the + operator

fn add(self, f: T) -> Matrix<T>

The method for the + operator

impl<'a, 'b, T> Add<&'b T> for MatrixSlice<'a, T> where T: Copy + Add<T, Output=T>

Scalar addition with matrix slice.

type Output = Matrix<T>

The resulting type after applying the + operator

fn add(self, f: &T) -> Matrix<T>

The method for the + operator

impl<'a, 'b, T> Add<T> for &'b MatrixSlice<'a, T> where T: Copy + Add<T, Output=T>

Scalar addition with matrix slice.

type Output = Matrix<T>

The resulting type after applying the + operator

fn add(self, f: T) -> Matrix<T>

The method for the + operator

impl<'a, 'b, 'c, T> Add<&'c T> for &'b MatrixSlice<'a, T> where T: Copy + Add<T, Output=T>

Scalar addition with matrix slice.

type Output = Matrix<T>

The resulting type after applying the + operator

fn add(self, f: &T) -> Matrix<T>

The method for the + operator

impl<'a, T> Sub<T> for MatrixSlice<'a, T> where T: Copy + Sub<T, Output=T>

Scalar subtraction with matrix slice.

type Output = Matrix<T>

fn sub(self, f: T) -> Matrix<T>

impl<'a, 'b, T> Sub<&'b T> for MatrixSlice<'a, T> where T: Copy + Sub<T, Output=T>

Scalar subtraction with matrix slice.

type Output = Matrix<T>

fn sub(self, f: &T) -> Matrix<T>

impl<'a, 'b, T> Sub<T> for &'b MatrixSlice<'a, T> where T: Copy + Sub<T, Output=T>

Scalar subtraction with matrix slice.

type Output = Matrix<T>

fn sub(self, f: T) -> Matrix<T>

impl<'a, 'b, 'c, T> Sub<&'c T> for &'b MatrixSlice<'a, T> where T: Copy + Sub<T, Output=T>

Scalar subtraction with matrix slice.

type Output = Matrix<T>

fn sub(self, f: &T) -> Matrix<T>

impl<'a, 'b, T> Add<MatrixSlice<'b, T>> for MatrixSlice<'a, T> where T: Copy + Add<T, Output=T>

Performs elementwise addition between the slices.

type Output = Matrix<T>

The resulting type after applying the + operator

fn add(self, s: MatrixSlice<T>) -> Matrix<T>

The method for the + operator

impl<'a, 'b, 'c, T> Add<MatrixSlice<'b, T>> for &'c MatrixSlice<'a, T> where T: Copy + Add<T, Output=T>

Performs elementwise addition between the slices.

type Output = Matrix<T>

The resulting type after applying the + operator

fn add(self, s: MatrixSlice<T>) -> Matrix<T>

The method for the + operator

impl<'a, 'b, 'c, T> Add<&'c MatrixSlice<'b, T>> for MatrixSlice<'a, T> where T: Copy + Add<T, Output=T>

Performs elementwise addition between the slices.

type Output = Matrix<T>

The resulting type after applying the + operator

fn add(self, s: &MatrixSlice<T>) -> Matrix<T>

The method for the + operator

impl<'a, 'b, 'c, 'd, T> Add<&'d MatrixSlice<'b, T>> for &'c MatrixSlice<'a, T> where T: Copy + Add<T, Output=T>

Performs elementwise addition between the slices.

type Output = Matrix<T>

The resulting type after applying the + operator

fn add(self, s: &MatrixSlice<T>) -> Matrix<T>

The method for the + operator

impl<'a, 'b, T> Add<MatrixSliceMut<'b, T>> for MatrixSlice<'a, T> where T: Copy + Add<T, Output=T>

Performs elementwise addition between the slices.

type Output = Matrix<T>

The resulting type after applying the + operator

fn add(self, s: MatrixSliceMut<T>) -> Matrix<T>

The method for the + operator

impl<'a, 'b, 'c, T> Add<MatrixSliceMut<'b, T>> for &'c MatrixSlice<'a, T> where T: Copy + Add<T, Output=T>

Performs elementwise addition between the slices.

type Output = Matrix<T>

The resulting type after applying the + operator

fn add(self, s: MatrixSliceMut<T>) -> Matrix<T>

The method for the + operator

impl<'a, 'b, 'c, T> Add<&'c MatrixSliceMut<'b, T>> for MatrixSlice<'a, T> where T: Copy + Add<T, Output=T>

Performs elementwise addition between the slices.

type Output = Matrix<T>

The resulting type after applying the + operator

fn add(self, s: &MatrixSliceMut<T>) -> Matrix<T>

The method for the + operator

impl<'a, 'b, 'c, 'd, T> Add<&'d MatrixSliceMut<'b, T>> for &'c MatrixSlice<'a, T> where T: Copy + Add<T, Output=T>

Performs elementwise addition between the slices.

type Output = Matrix<T>

The resulting type after applying the + operator

fn add(self, s: &MatrixSliceMut<T>) -> Matrix<T>

The method for the + operator

impl<'a, 'b, T> Sub<MatrixSlice<'b, T>> for MatrixSlice<'a, T> where T: Copy + Sub<T, Output=T>

Performs elementwise subtraction between the slices.

type Output = Matrix<T>

fn sub(self, s: MatrixSlice<T>) -> Matrix<T>

impl<'a, 'b, 'c, T> Sub<MatrixSlice<'b, T>> for &'c MatrixSlice<'a, T> where T: Copy + Sub<T, Output=T>

Performs elementwise subtraction between the slices.

type Output = Matrix<T>

fn sub(self, s: MatrixSlice<T>) -> Matrix<T>

impl<'a, 'b, 'c, T> Sub<&'c MatrixSlice<'b, T>> for MatrixSlice<'a, T> where T: Copy + Sub<T, Output=T>

Performs elementwise subtraction between the slices.

type Output = Matrix<T>

fn sub(self, s: &MatrixSlice<T>) -> Matrix<T>

impl<'a, 'b, 'c, 'd, T> Sub<&'d MatrixSlice<'b, T>> for &'c MatrixSlice<'a, T> where T: Copy + Sub<T, Output=T>

Performs elementwise subtraction between the slices.

type Output = Matrix<T>

fn sub(self, s: &MatrixSlice<T>) -> Matrix<T>

impl<'a, 'b, T> Sub<MatrixSliceMut<'b, T>> for MatrixSlice<'a, T> where T: Copy + Sub<T, Output=T>

Performs elementwise subtraction between the slices.

type Output = Matrix<T>

fn sub(self, s: MatrixSliceMut<T>) -> Matrix<T>

impl<'a, 'b, 'c, T> Sub<MatrixSliceMut<'b, T>> for &'c MatrixSlice<'a, T> where T: Copy + Sub<T, Output=T>

Performs elementwise subtraction between the slices.

type Output = Matrix<T>

fn sub(self, s: MatrixSliceMut<T>) -> Matrix<T>

impl<'a, 'b, 'c, T> Sub<&'c MatrixSliceMut<'b, T>> for MatrixSlice<'a, T> where T: Copy + Sub<T, Output=T>

Performs elementwise subtraction between the slices.

type Output = Matrix<T>

fn sub(self, s: &MatrixSliceMut<T>) -> Matrix<T>

impl<'a, 'b, 'c, 'd, T> Sub<&'d MatrixSliceMut<'b, T>> for &'c MatrixSlice<'a, T> where T: Copy + Sub<T, Output=T>

Performs elementwise subtraction between the slices.

type Output = Matrix<T>

fn sub(self, s: &MatrixSliceMut<T>) -> Matrix<T>

impl<'a, T> Add<Matrix<T>> for MatrixSlice<'a, T> where T: Copy + Add<T, Output=T>

Performs elementwise addition between Matrix and MatrixSlice.

type Output = Matrix<T>

The resulting type after applying the + operator

fn add(self, m: Matrix<T>) -> Matrix<T>

The method for the + operator

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

Performs elementwise addition between Matrix and MatrixSlice.

type Output = Matrix<T>

The resulting type after applying the + operator

fn add(self, m: Matrix<T>) -> Matrix<T>

The method for the + operator

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

Performs elementwise addition between Matrix and MatrixSlice.

type Output = Matrix<T>

The resulting type after applying the + operator

fn add(self, m: &Matrix<T>) -> Matrix<T>

The method for the + operator

impl<'a, 'b, 'c, T> Add<&'c Matrix<T>> for &'b MatrixSlice<'a, T> where T: Copy + Add<T, Output=T>

Performs elementwise addition between Matrix and MatrixSlice.

type Output = Matrix<T>

The resulting type after applying the + operator

fn add(self, m: &Matrix<T>) -> Matrix<T>

The method for the + operator

impl<'a, T> Sub<Matrix<T>> for MatrixSlice<'a, T> where T: Copy + Sub<T, Output=T>

Performs elementwise subtraction between Matrix and MatrixSlice.

type Output = Matrix<T>

fn sub(self, m: Matrix<T>) -> Matrix<T>

impl<'a, 'b, T> Sub<Matrix<T>> for &'b MatrixSlice<'a, T> where T: Copy + Sub<T, Output=T>

Performs elementwise subtraction between Matrix and MatrixSlice.

type Output = Matrix<T>

fn sub(self, m: Matrix<T>) -> Matrix<T>

impl<'a, 'b, T> Sub<&'b Matrix<T>> for MatrixSlice<'a, T> where T: Copy + Sub<T, Output=T>

Performs elementwise subtraction between Matrix and MatrixSlice.

type Output = Matrix<T>

fn sub(self, m: &Matrix<T>) -> Matrix<T>

impl<'a, 'b, 'c, T> Sub<&'c Matrix<T>> for &'b MatrixSlice<'a, T> where T: Copy + Sub<T, Output=T>

Performs elementwise subtraction between Matrix and MatrixSlice.

type Output = Matrix<T>

fn sub(self, m: &Matrix<T>) -> Matrix<T>

impl<'a, T> Neg for MatrixSlice<'a, T> where T: Copy + Neg<Output=T>

Gets negative of matrix slice.

type Output = Matrix<T>

fn neg(self) -> Matrix<T>

impl<'a, 'b, T> Neg for &'b MatrixSlice<'a, T> where T: Copy + Neg<Output=T>

Gets negative of matrix slice.

type Output = Matrix<T>

fn neg(self) -> Matrix<T>

impl<'a, T> Mul<Matrix<T>> for MatrixSlice<'a, T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any

Multiplies two matrices together.

type Output = Matrix<T>

The resulting type after applying the * operator

fn mul(self, m: Matrix<T>) -> Matrix<T>

The method for the * operator

impl<'a, 'b, T> Mul<&'b Matrix<T>> for MatrixSlice<'a, T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any

Multiplies two matrices together.

type Output = Matrix<T>

The resulting type after applying the * operator

fn mul(self, m: &Matrix<T>) -> Matrix<T>

The method for the * operator

impl<'a, 'b, T> Mul<Matrix<T>> for &'b MatrixSlice<'a, T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any

Multiplies two matrices together.

type Output = Matrix<T>

The resulting type after applying the * operator

fn mul(self, m: Matrix<T>) -> Matrix<T>

The method for the * operator

impl<'a, 'b, 'c, T> Mul<&'c Matrix<T>> for &'b MatrixSlice<'a, T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any

Multiplies two matrices together.

type Output = Matrix<T>

The resulting type after applying the * operator

fn mul(self, m: &Matrix<T>) -> Matrix<T>

The method for the * operator

impl<'a, 'b, T> Mul<MatrixSlice<'b, T>> for MatrixSlice<'a, T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any

Multiplies two matrices together.

type Output = Matrix<T>

The resulting type after applying the * operator

fn mul(self, m: MatrixSlice<T>) -> Matrix<T>

The method for the * operator

impl<'a, 'b, 'c, T> Mul<&'c MatrixSlice<'b, T>> for MatrixSlice<'a, T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any

Multiplies two matrices together.

type Output = Matrix<T>

The resulting type after applying the * operator

fn mul(self, m: &MatrixSlice<T>) -> Matrix<T>

The method for the * operator

impl<'a, 'b, 'c, T> Mul<MatrixSlice<'b, T>> for &'c MatrixSlice<'a, T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any

Multiplies two matrices together.

type Output = Matrix<T>

The resulting type after applying the * operator

fn mul(self, m: MatrixSlice<T>) -> Matrix<T>

The method for the * operator

impl<'a, 'b, 'c, 'd, T> Mul<&'d MatrixSlice<'b, T>> for &'c MatrixSlice<'a, T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any

Multiplies two matrices together.

type Output = Matrix<T>

The resulting type after applying the * operator

fn mul(self, m: &MatrixSlice<T>) -> Matrix<T>

The method for the * operator

impl<'a, 'b, T> Mul<MatrixSliceMut<'b, T>> for MatrixSlice<'a, T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any

Multiplies two matrices together.

type Output = Matrix<T>

The resulting type after applying the * operator

fn mul(self, m: MatrixSliceMut<T>) -> Matrix<T>

The method for the * operator

impl<'a, 'b, 'c, T> Mul<&'c MatrixSliceMut<'b, T>> for MatrixSlice<'a, T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any

Multiplies two matrices together.

type Output = Matrix<T>

The resulting type after applying the * operator

fn mul(self, m: &MatrixSliceMut<T>) -> Matrix<T>

The method for the * operator

impl<'a, 'b, 'c, T> Mul<MatrixSliceMut<'b, T>> for &'c MatrixSlice<'a, T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any

Multiplies two matrices together.

type Output = Matrix<T>

The resulting type after applying the * operator

fn mul(self, m: MatrixSliceMut<T>) -> Matrix<T>

The method for the * operator

impl<'a, 'b, 'c, 'd, T> Mul<&'d MatrixSliceMut<'b, T>> for &'c MatrixSlice<'a, T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any

Multiplies two matrices together.

type Output = Matrix<T>

The resulting type after applying the * operator

fn mul(self, m: &MatrixSliceMut<T>) -> Matrix<T>

The method for the * operator

impl<'a, T> IntoIterator for MatrixSlice<'a, T>

type Item = &'a T

type IntoIter = SliceIter<'a, T>

fn into_iter(self) -> MatrixSlice<'a, T>::IntoIter

impl<'a, T> IntoIterator for &'a MatrixSlice<'a, T>

type Item = &'a T

type IntoIter = SliceIter<'a, T>

fn into_iter(self) -> &'a MatrixSlice<'a, T>::IntoIter

impl<'a, T> IntoIterator for &'a mut MatrixSlice<'a, T>

type Item = &'a T

type IntoIter = SliceIter<'a, T>

fn into_iter(self) -> &'a mut MatrixSlice<'a, T>::IntoIter

impl<'a, T> BaseSlice<T> for MatrixSlice<'a, T>

fn rows(&self) -> usize

Rows in the slice.

fn cols(&self) -> usize

Columns in the slice.

fn row_stride(&self) -> usize

Row stride in the slice.

fn as_ptr(&self) -> *const T

Top left index of the slice.

unsafe fn get_unchecked(&self, index: [usize; 2]) -> &T

Get a reference to a point in the slice without bounds checking.

fn get_row(&self, index: usize) -> Option<&[T]>

Returns the row of a Matrix at the given index. None if the index is out of bounds. Read more

unsafe fn get_row_unchecked(&self, index: usize) -> &[T]

Returns the row of a BaseSlice at the given index without doing unbounds checking Read more

impl<'a, T> Copy for MatrixSlice<'a, T> where T: Copy + 'a

impl<'a, T> Clone for MatrixSlice<'a, T> where T: 'a + Clone

fn clone(&self) -> MatrixSlice<'a, 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<'a, T> Debug for MatrixSlice<'a, T> where T: 'a + Debug

fn fmt(&self, __arg_0: &mut Formatter) -> Result<()Error>

Formats the value using the given formatter.

impl<'a, T> Metric<T> for MatrixSlice<'a, T> where T: Float

fn norm(&self) -> T

Compute euclidean norm for matrix.

Examples

use rulinalg::matrix::{Matrix, MatrixSlice};
use rulinalg::Metric;

let a = Matrix::new(2,1, vec![3.0,4.0]);
let b = MatrixSlice::from_matrix(&a, [0,0], 2, 1);
let c = b.norm();

assert_eq!(c, 5.0);