pub struct Matrix<T> { /* private fields */ }Implementations§
Source§impl<T> Matrix<T>
impl<T> Matrix<T>
Sourcepub fn new<F>(width: usize, height: usize, address_value_converter: F) -> Selfwhere
F: Fn(MatrixAddress) -> T,
pub fn new<F>(width: usize, height: usize, address_value_converter: F) -> Selfwhere
F: Fn(MatrixAddress) -> T,
Creates a new Matrix based on dimensions and a mapper function.
§Arguments
width: The width, or number of columns in the matrixheight: The height, or number of rows in the matrixaddress_value_converter: Converts a matrix address to a value.
Returns: Matrix
§Examples
use rust_tensors::matrix::Matrix;
use rust_tensors::tensor::Tensor;
// Creates a 1000x1000 zero matrix
let (width, height) = (1000, 1000);
let mut matrix = Matrix::new(width, height, |_address| 0usize);
matrix.address_iter()
.for_each(|address| assert_eq!(matrix[address], 0));
// Creates a 50x10 matrix where the value is the index of the array
let (width, height) = (1000, 1000);
let mut matrix = Matrix::new(width, height, |address| address.y * width as i32 + address.x);
matrix.address_iter()
.for_each(|address| assert_eq!(matrix[address], address.y * width as i32 + address.x));Sourcepub fn to_display_string<T1: Display, F: Fn(&T) -> T1>(
&self,
display_func: F,
row_delimiter: &str,
column_delimiter: &str,
) -> String
pub fn to_display_string<T1: Display, F: Fn(&T) -> T1>( &self, display_func: F, row_delimiter: &str, column_delimiter: &str, ) -> String
Makes a string fit for displaying the contents of the matrix
§Arguments
display_func: Converts a value to a stringrow_delimiter: Separates the rows in the matrixcolumn_delimiter: Separates the columns in the matrix
Returns: the formatted string
§Examples
use rust_tensors::matrix::Matrix;
let mut matrix =
Matrix::<i32>::parse_matrix("1 2 3|4 5 6|7 8 9", " ", "|", |s| s.parse().unwrap())
.unwrap();
assert_eq!(
matrix.to_display_string(|i| i.to_string(), "-", "|"),
"1-2-3|4-5-6|7-8-9"
);Sourcepub fn parse_matrix<F>(
data_str: &str,
column_delimiter: &str,
row_delimiter: &str,
str_to_t_converter: F,
) -> Result<Matrix<T>, String>
pub fn parse_matrix<F>( data_str: &str, column_delimiter: &str, row_delimiter: &str, str_to_t_converter: F, ) -> Result<Matrix<T>, String>
Parses a matrix from a string. Fallible, and will return an Err if the matrix cannot be parsed, or if the matrix does not have a uniform row length
§Arguments
data_str: The string to be parsedcolumn_delimiter: The string which separates the items in the columnsrow_delimiter: The string which separates the rowsstr_to_t_converter: The function which converts the item strings to a value
Returns: Result<Matrix
§Examples
use rust_tensors::matrix::Matrix;
let mut matrix =
Matrix::<i32>::parse_matrix("0 1 2|3 4 5|6 7 8", " ", "|", |s| s.parse().unwrap())
.unwrap();
assert_eq!(
matrix, Matrix::new(3, 3, |address| address.x + 3 * address.y)
);Trait Implementations§
impl<T: Eq> Eq for Matrix<T>
Source§impl<T> Index<MatrixAddress> for Matrix<T>
impl<T> Index<MatrixAddress> for Matrix<T>
Source§impl<T> IndexMut<MatrixAddress> for Matrix<T>
impl<T> IndexMut<MatrixAddress> for Matrix<T>
impl<T> StructuralPartialEq for Matrix<T>
Source§impl<T> Tensor<T, i32, MatrixAddress, 2> for Matrix<T>
impl<T> Tensor<T, i32, MatrixAddress, 2> for Matrix<T>
fn smallest_contained_address(&self) -> MatrixAddress
fn largest_contained_address(&self) -> MatrixAddress
Source§fn get(&self, address: A) -> Result<&T, String>
fn get(&self, address: A) -> Result<&T, String>
Attempts to get a reference of the value at the given address. Will return Err if the address
is not contained in the matrix. Read more
Source§fn get_mut(&mut self, address: A) -> Result<&mut T, String>
fn get_mut(&mut self, address: A) -> Result<&mut T, String>
Attempts to get a mutable reference of the value at the given address. Will return Err if the
address is not contained in the matrix. Read more
Source§fn contains_address(&self, address: A) -> bool
fn contains_address(&self, address: A) -> bool
Evaluates whether an address is valid and has an associated value in the tensor. Read more
Source§fn address_iter(&self) -> AddressIterator<V, A, DIMENSION>
fn address_iter(&self) -> AddressIterator<V, A, DIMENSION>
Creates an iterator over the addresses within the bounds of the tensor. Read more
Auto Trait Implementations§
impl<T> Freeze for Matrix<T>
impl<T> RefUnwindSafe for Matrix<T>where
T: RefUnwindSafe,
impl<T> Send for Matrix<T>where
T: Send,
impl<T> Sync for Matrix<T>where
T: Sync,
impl<T> Unpin for Matrix<T>where
T: Unpin,
impl<T> UnsafeUnpin for Matrix<T>
impl<T> UnwindSafe for Matrix<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more