Struct DenseMatrix

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

Dense matrix

Implementations§

Source§

impl<T: Debug + Display + Copy + Sized> DenseMatrix<T>

Source

pub fn new( nrows: usize, ncols: usize, values: Vec<T>, column_major: bool, ) -> Result<Self, Failed>

Create new instance of DenseMatrix without copying data. values should be in column-major order.

Source

pub fn from_2d_array(values: &[&[T]]) -> Result<Self, Failed>

New instance of DenseMatrix from 2d array.

Source

pub fn from_2d_vec(values: &Vec<Vec<T>>) -> Result<Self, Failed>

New instance of DenseMatrix from 2d vector.

Source

pub fn iter(&self) -> Iter<'_, T>

Iterate over values of matrix

Trait Implementations§

Source§

impl<T: Number + RealNumber + AbsDiffEq> AbsDiffEq for DenseMatrix<T>
where T::Epsilon: Copy,

Source§

type Epsilon = <T as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
Source§

fn default_epsilon() -> T::Epsilon

The default tolerance to use when testing values that are close together. Read more
Source§

fn abs_diff_eq(&self, other: &Self, epsilon: T::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
Source§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
Source§

impl<T: Debug + Display + Copy + Sized> Array<T, (usize, usize)> for DenseMatrix<T>

Source§

fn get(&self, pos: (usize, usize)) -> &T

retrieve a reference to a value at position
Source§

fn shape(&self) -> (usize, usize)

return shape of the array
Source§

fn is_empty(&self) -> bool

return true if array is empty
Source§

fn iterator<'b>(&'b self, axis: u8) -> Box<dyn Iterator<Item = &'b T> + 'b>

iterate over array’s values
Source§

impl<T: Debug + Display + Copy + Sized> Array2<T> for DenseMatrix<T>

Source§

fn get_row<'a>(&'a self, row: usize) -> Box<dyn ArrayView1<T> + 'a>

get row from 2d array
Source§

fn get_col<'a>(&'a self, col: usize) -> Box<dyn ArrayView1<T> + 'a>

get column from 2d array
Source§

fn slice<'a>( &'a self, rows: Range<usize>, cols: Range<usize>, ) -> Box<dyn ArrayView2<T> + 'a>

get a view of the 2d array
Source§

fn slice_mut<'a>( &'a mut self, rows: Range<usize>, cols: Range<usize>, ) -> Box<dyn MutArrayView2<T> + 'a>
where Self: Sized,

get a mutable view of the 2d array
Source§

fn fill(nrows: usize, ncols: usize, value: T) -> Self

fill 2d array with a given value
Source§

fn from_iterator<I: Iterator<Item = T>>( iter: I, nrows: usize, ncols: usize, axis: u8, ) -> Self

create 2d array from iterator
Source§

fn transpose(&self) -> Self

transpose 2d array
Source§

fn zeros(nrows: usize, ncols: usize) -> Self
where T: Number,

create a zero 2d array
Source§

fn ones(nrows: usize, ncols: usize) -> Self
where T: Number,

create a 2d array of ones
Source§

fn eye(size: usize) -> Self
where T: Number,

create an identity matrix
Source§

fn rand(nrows: usize, ncols: usize) -> Self
where T: RealNumber,

create a 2d array of random values
Source§

fn from_slice(slice: &dyn ArrayView2<T>) -> Self

crate from 2d slice
Source§

fn from_row(slice: &dyn ArrayView1<T>) -> Self

create from row
Source§

fn from_column(slice: &dyn ArrayView1<T>) -> Self

create from column
Source§

fn reshape(&self, nrows: usize, ncols: usize, axis: u8) -> Self

change shape of 2d array
Source§

fn matmul(&self, other: &dyn ArrayView2<T>) -> Self
where T: Number,

multiply two 2d arrays
Source§

fn ab( &self, a_transpose: bool, b: &dyn ArrayView2<T>, b_transpose: bool, ) -> Self
where T: Number,

matrix multiplication
Source§

fn ax(&self, a_transpose: bool, x: &dyn ArrayView1<T>) -> Self
where T: Number,

matrix vector multiplication
Source§

fn concatenate_1d<'a>(arrays: &'a [&'a dyn ArrayView1<T>], axis: u8) -> Self

concatenate 1d array
Source§

fn concatenate_2d<'a>(arrays: &'a [&'a dyn ArrayView2<T>], axis: u8) -> Self

concatenate 2d array
Source§

fn merge_1d<'a>( &'a self, arrays: &'a [&'a dyn ArrayView1<T>], axis: u8, append: bool, ) -> Self

merge 1d arrays
Source§

fn v_stack(&self, other: &dyn ArrayView2<T>) -> Self

Stack arrays in sequence vertically
Source§

fn h_stack(&self, other: &dyn ArrayView2<T>) -> Self

Stack arrays in sequence horizontally
Source§

fn map<O: Debug + Display + Copy + Sized, A: Array2<O>, F: FnMut(&T) -> O>( self, f: F, ) -> A

map array values
Source§

fn row_iter<'a>( &'a self, ) -> Box<dyn Iterator<Item = Box<dyn ArrayView1<T> + 'a>> + 'a>

iter rows
Source§

fn col_iter<'a>( &'a self, ) -> Box<dyn Iterator<Item = Box<dyn ArrayView1<T> + 'a>> + 'a>

iter cols
Source§

fn take(&self, index: &[usize], axis: u8) -> Self

take elements from 2d array
Source§

fn take_column(&self, column_index: usize) -> Self

Take an individual column from the matrix.
Source§

fn add_scalar(&self, x: T) -> Self
where T: Number,

add a scalar to the array
Source§

fn sub_scalar(&self, x: T) -> Self
where T: Number,

subtract a scalar from the array
Source§

fn div_scalar(&self, x: T) -> Self
where T: Number,

divide a scalar from the array
Source§

fn mul_scalar(&self, x: T) -> Self
where T: Number,

multiply a scalar to the array
Source§

fn add(&self, other: &dyn Array<T, (usize, usize)>) -> Self
where T: Number,

sum of two arrays
Source§

fn sub(&self, other: &dyn Array<T, (usize, usize)>) -> Self
where T: Number,

subtract two arrays
Source§

fn mul(&self, other: &dyn Array<T, (usize, usize)>) -> Self
where T: Number,

multiply two arrays
Source§

fn div(&self, other: &dyn Array<T, (usize, usize)>) -> Self
where T: Number,

divide two arrays
Source§

fn abs(&self) -> Self
where T: Number + Signed,

absolute values of the array
Source§

fn neg(&self) -> Self
where T: Number + Neg<Output = T>,

negation of the array
Source§

fn pow(&self, p: T) -> Self
where T: RealNumber,

values at power p
Source§

fn column_mean(&self) -> Vec<f64>
where T: Number + ToPrimitive,

compute mean for each column
Source§

fn copy_col_as_vec(&self, col: usize, result: &mut Vec<T>)

copy column as a vector
Source§

fn approximate_eq(&self, other: &Self, error: T) -> bool
where T: Number + RealNumber,

approximate equality of the elements of a matrix according to a given error
Source§

impl<T: Debug + Display + Copy + Sized> ArrayView2<T> for DenseMatrix<T>

Source§

fn max(&self, axis: u8) -> Vec<T>
where T: Number + PartialOrd,

return max value in array
Source§

fn sum(&self, axis: u8) -> Vec<T>
where T: Number,

return sum of element of array
Source§

fn min(&self, axis: u8) -> Vec<T>
where T: Number + PartialOrd,

return min value of array
Source§

fn argmax(&self, axis: u8) -> Vec<usize>
where T: Number + PartialOrd,

return positions of max values in both rows
Source§

fn mean_by(&self, axis: u8) -> Vec<f64>
where T: Number,

return mean value TODO: this can be made more readable and efficient using the methods in linalg::traits::stats
Source§

fn variance(&self, axis: u8) -> Vec<f64>
where T: Number + RealNumber,

return variance
Source§

fn std_dev(&self, axis: u8) -> Vec<f64>
where T: Number + RealNumber,

return standard deviation
Source§

fn cov(&self, cov: &mut dyn MutArrayView2<f64>)
where T: Number,

return covariance
Source§

fn display(&self, f: &mut Formatter<'_>) -> Result

print out array
Source§

fn norm(&self, p: f64) -> f64
where T: Number,

return norm
Source§

fn diag(&self) -> Vec<T>

return array diagonal
Source§

impl<T: Number + RealNumber> CholeskyDecomposable<T> for DenseMatrix<T>

Source§

fn cholesky(&self) -> Result<Cholesky<T, Self>, Failed>

Compute the Cholesky decomposition of a matrix.
Source§

fn cholesky_mut(self) -> Result<Cholesky<T, Self>, Failed>

Compute the Cholesky decomposition of a matrix. The input matrix will be used for factorization.
Source§

fn cholesky_solve_mut(self, b: Self) -> Result<Self, Failed>

Solves Ax = b
Source§

impl<T: Clone> Clone for DenseMatrix<T>

Source§

fn clone(&self) -> DenseMatrix<T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for DenseMatrix<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Debug + Display + Copy + Sized> Display for DenseMatrix<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Number + RealNumber> EVDDecomposable<T> for DenseMatrix<T>

Source§

fn evd(&self, symmetric: bool) -> Result<EVD<T, Self>, Failed>

Compute the eigen decomposition of a square matrix. Read more
Source§

fn evd_mut(self, symmetric: bool) -> Result<EVD<T, Self>, Failed>

Compute the eigen decomposition of a square matrix. The input matrix will be used for factorization. Read more
Source§

impl<T: Number + RealNumber> LUDecomposable<T> for DenseMatrix<T>

Source§

fn lu(&self) -> Result<LU<T, Self>, Failed>

Compute the LU decomposition of a square matrix.
Source§

fn lu_mut(self) -> Result<LU<T, Self>, Failed>

Compute the LU decomposition of a square matrix. The input matrix will be used for factorization.
Source§

fn lu_solve_mut(self, b: Self) -> Result<Self, Failed>

Solves Ax = b
Source§

impl<T: RealNumber> MatrixPreprocessing<T> for DenseMatrix<T>

Source§

fn binarize_mut(&mut self, threshold: T)

Each element of the matrix greater than the threshold becomes 1, while values less than or equal to the threshold become 0 Read more
Source§

fn binarize(self, threshold: T) -> Self
where Self: Sized,

Returns new matrix where elements are binarized according to a given threshold. Read more
Source§

impl<T: RealNumber> MatrixStats<T> for DenseMatrix<T>

Source§

fn mean(&self, axis: u8) -> Vec<T>

Computes the arithmetic mean along the specified axis.
Source§

fn var(&self, axis: u8) -> Vec<T>

Computes variance along the specified axis.
Source§

fn std(&self, axis: u8) -> Vec<T>

Computes the standard deviation along the specified axis.
Source§

fn _mean_of_vector(v: &[T]) -> T

http://en.wikipedia.org/wiki/Arithmetic_mean Taken from statistical The MIT License (MIT) Copyright (c) 2015 Jeff Belgum
Source§

fn _sum_square_deviations_vec(v: &[T], c: Option<T>) -> T

Taken from statistical The MIT License (MIT) Copyright (c) 2015 Jeff Belgum
Source§

fn _var_of_vec(v: &[T], xbar: Option<T>) -> T

http://en.wikipedia.org/wiki/Variance#Sample_variance Taken from statistical The MIT License (MIT) Copyright (c) 2015 Jeff Belgum
Source§

fn standard_scale_mut(&mut self, mean: &[T], std: &[T], axis: u8)

standardize values by removing the mean and scaling to unit variance
Source§

impl<T: Debug + Display + Copy + Sized> MutArray<T, (usize, usize)> for DenseMatrix<T>

Source§

fn set(&mut self, pos: (usize, usize), x: T)

assign value to a position
Source§

fn iterator_mut<'b>( &'b mut self, axis: u8, ) -> Box<dyn Iterator<Item = &'b mut T> + 'b>

iterate over mutable values
Source§

fn swap(&mut self, a: S, b: S)
where S: Copy,

swap values between positions
Source§

fn div_element_mut(&mut self, pos: S, x: T)
where T: Number, S: Copy,

divide element by a given value
Source§

fn mul_element_mut(&mut self, pos: S, x: T)
where T: Number, S: Copy,

multiply element for a given value
Source§

fn add_element_mut(&mut self, pos: S, x: T)
where T: Number, S: Copy,

add a given value to an element
Source§

fn sub_element_mut(&mut self, pos: S, x: T)
where T: Number, S: Copy,

subtract a given value to an element
Source§

fn sub_scalar_mut(&mut self, x: T)
where T: Number,

subtract a given value to all the elements
Source§

fn add_scalar_mut(&mut self, x: T)
where T: Number,

add a given value to all the elements
Source§

fn mul_scalar_mut(&mut self, x: T)
where T: Number,

multiply a given value to all the elements
Source§

fn div_scalar_mut(&mut self, x: T)
where T: Number,

divide a given value to all the elements
Source§

fn add_mut(&mut self, other: &dyn Array<T, S>)
where T: Number, S: Eq,

add values from another array to the values of initial array
Source§

fn sub_mut(&mut self, other: &dyn Array<T, S>)
where T: Number, S: Eq,

subtract values from another array to the values of initial array
Source§

fn mul_mut(&mut self, other: &dyn Array<T, S>)
where T: Number, S: Eq,

multiply values from another array to the values of initial array
Source§

fn div_mut(&mut self, other: &dyn Array<T, S>)
where T: Number, S: Eq,

divide values from another array to the values of initial array
Source§

impl<T: Debug + Display + Copy + Sized> MutArrayView2<T> for DenseMatrix<T>

Source§

fn copy_from(&mut self, other: &dyn Array<T, (usize, usize)>)

copy values from another array
Source§

fn abs_mut(&mut self)
where T: Number + Signed,

update view with absolute values
Source§

fn neg_mut(&mut self)
where T: Number + Neg<Output = T>,

update view values with opposite sign
Source§

fn pow_mut(&mut self, p: T)
where T: RealNumber,

update view values at power p
Source§

fn scale_mut(&mut self, mean: &[T], std: &[T], axis: u8)
where T: Number,

scale view values
Source§

impl<T: Debug + Display + Copy + Sized + PartialEq> PartialEq for DenseMatrix<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Number + RealNumber> QRDecomposable<T> for DenseMatrix<T>

Source§

fn qr(&self) -> Result<QR<T, Self>, Failed>

Compute the QR decomposition of a matrix.
Source§

fn qr_mut(self) -> Result<QR<T, Self>, Failed>

Compute the QR decomposition of a matrix. The input matrix will be used for factorization.
Source§

fn qr_solve_mut(self, b: Self) -> Result<Self, Failed>

Solves Ax = b
Source§

impl<T: Number + RealNumber + RelativeEq> RelativeEq for DenseMatrix<T>
where T::Epsilon: Copy,

Source§

fn default_max_relative() -> T::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
Source§

fn relative_eq( &self, other: &Self, epsilon: T::Epsilon, max_relative: T::Epsilon, ) -> bool

A test for equality that uses a relative comparison if the values are far apart.
Source§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

The inverse of RelativeEq::relative_eq.
Source§

impl<T: Number + RealNumber> SVDDecomposable<T> for DenseMatrix<T>

Source§

fn svd_solve_mut(self, b: Self) -> Result<Self, Failed>

Solves Ax = b. Overrides original matrix in the process.
Source§

fn svd_solve(&self, b: Self) -> Result<Self, Failed>

Solves Ax = b
Source§

fn svd(&self) -> Result<SVD<T, Self>, Failed>

Compute the SVD decomposition of a matrix.
Source§

fn svd_mut(self) -> Result<SVD<T, Self>, Failed>

Compute the SVD decomposition of a matrix. The input matrix will be used for factorization.

Auto Trait Implementations§

§

impl<T> Freeze for DenseMatrix<T>

§

impl<T> RefUnwindSafe for DenseMatrix<T>
where T: RefUnwindSafe,

§

impl<T> Send for DenseMatrix<T>
where T: Send,

§

impl<T> Sync for DenseMatrix<T>
where T: Sync,

§

impl<T> Unpin for DenseMatrix<T>
where T: Unpin,

§

impl<T> UnwindSafe for DenseMatrix<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.