mematrica/
cmatrix_trait.rs

1pub mod cmatrix_trait {
2    extern crate num;
3    
4    use crate::{matrix::matrix::Error, Matrix2, Matrix3};
5    use self::num::Num;
6
7    pub trait CMatrixTrait<T: Num + Default + Clone + std::str::FromStr + std::cmp::PartialOrd + std::fmt::Debug + std::convert::Into<f64> + std::marker::Copy> {
8        /// Creates a matrix of custom size with zero as its elements
9        fn zero(rows: usize, columns: usize) -> Self;
10        /// Creates a matrix of custom size with one as its elements
11        fn one(rows: usize, columns: usize) -> Self;
12        /// Creates an identity matrix of custom size
13        fn identity(rows: usize, columns: usize) -> Self;
14        /// Reads matrix elements from file
15        fn from_file(filename: String, delimiter: char, rows: usize, columns: usize) -> Self
16        where <T as std::str::FromStr>::Err: std::fmt::Debug;
17        /// Try to read matrix elements from file
18        fn try_from_file(filename: String, delimiter: char, rows: usize, columns: usize) -> Result<Self, Error>
19        where <T as std::str::FromStr>::Err: std::fmt::Debug, Self : Sized;
20        /// Creates a matrix of custom size from element
21        fn from_element(rows: usize, columns: usize, e: T) -> Self;
22        /// Creates a matrix from this vector, using that elements as columns
23        fn from_vec_as_columns(columns: usize, v: Vec<T>) -> Self;
24        /// Creates a matrix from this vector, using that elements as rows
25        fn from_vec_as_rows(rows: usize, v: Vec<T>) -> Self;
26        /// Creates a matrix from this element on its diagonal. All off-diagonal elements are set to 0
27        fn from_diagonal(rows: usize, columns: usize, element: T) -> Self;
28        /// Converts matrix to Matrix2
29        fn to_matrix2(self) -> Matrix2<T>;
30        /// Converts matrix to Matrix3
31        fn to_matrix3(self) -> Matrix3<T>;
32        /// Add a row to matrix
33        fn push(&mut self, v: Vec<T>);
34        /// Delete last row to matrix
35        fn pop(&mut self);
36    }
37
38}