Macro dynamic_matrix

Source
macro_rules! dynamic_matrix {
    ($cols:expr) => { ... };
    ($($elem:expr),+; $cols:expr) => { ... };
    ($($($elem:expr),+);+$(;)?) => { ... };
}
Expand description

A macro to construct a DynamicMatrix

There are three ways to invoke this macro:

  1. With a single argument, the number of columns in this DynamicMatrix.
let mat: DynamicMatrix<isize> = dynamic_matrix!(3);

assert_eq!(mat.shape(), (0, 3));
  1. With a list of arguments followed the number of columns in this DynamicMatrix.
let mat = dynamic_matrix![1, 2, 3, 4, 5, 6, 7, 8, 9; 3];

assert_eq!(mat.shape(), (3, 3));
assert_eq!(mat.as_slice(), [1, 2, 3, 4, 5, 6, 7, 8, 9]);
  1. A “nested array”. “,” seperating elements at the row level and “;” at the column level.
let mat = dynamic_matrix![1, 2, 3; 4, 5, 6; 7, 8, 9];

assert_eq!(mat.shape(), (3, 3));
assert_eq!(mat.as_slice(), [1, 2, 3, 4, 5, 6, 7, 8, 9]);