arr_rs/macros/
eye.rs

1/// Create new 2d array with ones on the diagonal and zeros elsewhere
2///
3/// # Examples
4///
5/// ```
6/// use arr_rs::prelude::*;
7///
8/// let arr = array_eye!(i32, 2, 3, 3);
9/// assert_eq!(vec![2, 3], arr.get_shape().unwrap());
10/// let arr = array_eye!(i32, 4, 5, 3);
11/// assert_eq!(vec![4, 5], arr.get_shape().unwrap());
12/// ```
13#[macro_export]
14macro_rules! array_eye {
15    (Tuple2<$t1:ty, $t2:ty>, $($tt:tt)*) => {{
16        compile_error!("only `Numeric` types are supported")
17    }};
18    (Tuple3<$t1:ty, $t2:ty, $t3:ty>, $($tt:tt)*) => {{
19        compile_error!("only `Numeric` types are supported")
20    }};
21    (List<$t1:ty>, $($tt:tt)*) => {{
22        compile_error!("only `Numeric` types are supported")
23    }};
24    (char, $($tt:tt)*) => {{
25        compile_error!("only `Numeric` types are supported")
26    }};
27    (String, $($tt:tt)*) => {{
28        compile_error!("only `Numeric` types are supported")
29    }};
30    ($tt:ty, $n:expr) => {
31        array_eye!($tt, $n, $n, 0)
32    };
33    ($tt:ty, $n:expr, $m:expr) => {
34        array_eye!($tt, $n, $m, 0)
35    };
36    ($tt:ty, $n:expr, $m:expr, $k:expr) => {{
37        Array::<$tt>::eye($n, Some($m), Some($k))
38    }};
39}