rustml::mat!
[−]
[src]
macro_rules! mat { ( $( $( $x:expr ),+ ) ;* ) => { { let mut v = Vec::new(); let mut cols; let mut cols_old = 0; let mut rows = 0; $( rows += 1; cols = 0; $( cols += 1; v.push($x); )+ if rows > 1 && cols != cols_old { panic!("Invalid matrix."); } cols_old = cols; )* Matrix::from_vec(v, rows, cols_old) } }; }
Macro to create a matrix.
Example
#[macro_use] extern crate rustml; use rustml::matrix::Matrix; // creates a matrix with 2 rows and 3 columns let m = mat![ 1.0, 2.0, 3.0; 4.0, 5.0, 6.0 ]; assert_eq!(m.rows(), 2); assert_eq!(m.cols(), 3);