[−][src]Struct ml_rust_cuda::math::linear::Matrix
A representation of a 32-bit float matrix.
A matrix's elements are stored as a flat, 1-dimensional vector, with an internal tuple which defines the dimensions of the matrix, i.e. how the matrix's elements are interpreted, in (rows, columns) format.
use ml_rust_cuda::math::linear::Matrix; let elements = vec![vec![1_f32, 3_f32, 4_f32], vec![2_f32, 5_f32, 8_f32]]; let matrix = Matrix::new(elements); // "Matrix { elements: [ 1.0, 3.0, 4.0, 2.0, 5.0, 8.0 ], dims: (2, 3) }" println!("{:?}", matrix);
Implementations
impl Matrix
[src]
pub fn new(elements: Vec<Vec<f32>>) -> Self
[src]
Returns a matrix representation from a supplied 2-dimensional f32 vector.
Arguments
Examples
use ml_rust_cuda::math::linear::Matrix; let vec_of_vecs = vec![vec![1_f32, 3_f32, 4_f32], vec![2_f32, 5_f32, 8_f32], vec![9_f32, 5_f32, 8_f32], vec![3_f32, 4_f32, 0_f32]]; let matrix = Matrix::new(vec_of_vecs); println!("{}", matrix);
Panics
Panics if all Vecs within elements
are not of equal length.
pub fn from_flat(elements: Vec<f32>, dims: (usize, usize)) -> Self
[src]
Returns a matrix representation from a flat 1-dimensional f32 vector of specified dimensions.
Arguments
elements
- A flat vector of f32s stored in row-major form (i.e. elements in the same row are adjacent to each other inelements
).dims
- The dimensions of the matrix in (rows, columns).
Examples
use ml_rust_cuda::math::linear::Matrix; let flat_vec = vec![1_f32, 3_f32, 4_f32, 2_f32, 5_f32, 8_f32, 9_f32, 5_f32, 8_f32, 3_f32, 4_f32, 0_f32]; let matrix = Matrix::from_flat(flat_vec, (4, 3)); println!("{}", matrix);
pub fn zero(dims: (usize, usize)) -> Self
[src]
Returns a matrix of specified dimensions filled with zeros.
Arguments
dims
- The dimensions of the matrix in (rows, columns).
Examples
use ml_rust_cuda::math::linear::Matrix; let matrix = Matrix::zero((4, 3)); println!("{}", matrix);
pub fn get(&self, pos: (usize, usize)) -> Option<f32>
[src]
Returns the element of the matrix at a given position, or None
if the index
is out of bounds of the matrix.
Arguments
pos
- The target element's position in (row, column) form, zero-indexed.
Examples
use ml_rust_cuda::math::linear::Matrix; let vec_of_vecs = vec![vec![1_f32, 3_f32, 4_f32], vec![2_f32, 5_f32, 8_f32]]; let matrix = Matrix::new(vec_of_vecs); assert_eq!(matrix.get((1, 2)), Some(8_f32)); assert!(matrix.get((2, 0)).is_none());
pub fn set(&mut self, pos: (usize, usize), val: f32)
[src]
Replaces the element of the matrix at a given position with a given value. Does nothing if the position is out of bounds of the matrix.
Arguments
pos
- The target element's position in (row, column) form, zero-indexed.val
- The value with which to replace the target element.
Examples
use ml_rust_cuda::math::linear::Matrix; let vec_of_vecs = vec![vec![1_f32, 3_f32, 4_f32], vec![2_f32, 5_f32, 8_f32]]; let mut matrix = Matrix::new(vec_of_vecs); matrix.set((1, 2), 5_f32); assert_eq!(matrix.get((1, 2)), Some(5_f32));
pub fn elements(&self) -> &Vec<f32>
[src]
Returns a reference to the matrix's internal flat element vector.
pub fn dims(&self) -> &(usize, usize)
[src]
Returns a reference to the matrix's dimension tuple in the form (rows, columns), zero-indexed.
pub fn zero_padded(&self, target: usize) -> Self
[src]
Returns a copy of the matrix padded with zeros such that each dimension of the resulting matrix is a multiple of a specified value.
Arguments
target
- The number by which the resulting matrix's dimensions should be divisible by.
Examples
use ml_rust_cuda::math::linear::Matrix; let vec_of_vecs = vec![vec![1_f32, 3_f32], vec![2_f32, 5_f32], vec![0_f32, 7_f32], vec![8_f32, 4_f32]]; let matrix = Matrix::new(vec_of_vecs); println!("{}", matrix.zero_padded(3));
pub fn truncated(&self, new_dims: (usize, usize)) -> Self
[src]
Returns a copy of the matrix truncated such that the resulting matrix's dimensions match the provided dimensions.
Arguments
new_dims
- The dimensions of the new matrix in (rows, columns).
Examples
use ml_rust_cuda::math::linear::Matrix; let vec_of_vecs = vec![vec![1_f32, 3_f32, 0_f32, 0_f32], vec![2_f32, 5_f32, 0_f32, 0_f32], vec![0_f32, 7_f32, 0_f32, 0_f32], vec![8_f32, 4_f32, 0_f32, 0_f32], vec![0_f32, 0_f32, 0_f32, 0_f32], vec![0_f32, 0_f32, 0_f32, 0_f32]]; let matrix = Matrix::new(vec_of_vecs); println!("{}", matrix.truncated((4, 2)));
pub fn transposed(&self) -> Self
[src]
Returns a transposed copy of the matrix.
Uses a CUDA kernel under the hood.
Examples
use ml_rust_cuda::math::linear::Matrix; let vec_of_vecs = vec![vec![1_f32, 3_f32], vec![2_f32, 5_f32], vec![0_f32, 7_f32], vec![8_f32, 4_f32]]; let matrix = Matrix::new(vec_of_vecs); println!("{}", matrix.transposed());
Trait Implementations
impl<'_> Add<&'_ Matrix> for &'_ Matrix
[src]
type Output = Matrix
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self::Output
[src]
Uses a CUDA kernel under the hood.
Panics
Panics if both operand matrices are not of the same dimension.
impl Clone for Matrix
[src]
impl Debug for Matrix
[src]
impl Display for Matrix
[src]
impl<'_> Mul<&'_ Matrix> for f32
[src]
type Output = Matrix
The resulting type after applying the *
operator.
fn mul(self, other: &Matrix) -> Self::Output
[src]
Uses a CUDA kernel under the hood.
impl<'_> Mul<&'_ Matrix> for &'_ Matrix
[src]
type Output = Matrix
The resulting type after applying the *
operator.
fn mul(self, other: Self) -> Self::Output
[src]
Uses a CUDA kernel under the hood.
Panics
Panics if the number of columns in the first operand is not equal to the number of rows in the second operand.
impl<'_, '_> Mul<&'_ Vector> for &'_ Matrix
[src]
type Output = Vector
The resulting type after applying the *
operator.
fn mul(self, other: &Vector) -> Self::Output
[src]
Uses the same CUDA kernel as matrix multiplication.
Panics
Panics if the number of columns in the matrix is not equal to the dimension of the vector.
impl PartialEq<Matrix> for Matrix
[src]
fn eq(&self, other: &Self) -> bool
[src]
Uses a CUDA kernel under the hood.
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'_> Sub<&'_ Matrix> for &'_ Matrix
[src]
Auto Trait Implementations
impl RefUnwindSafe for Matrix
impl Send for Matrix
impl Sync for Matrix
impl Unpin for Matrix
impl UnwindSafe for Matrix
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,