1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#[macro_export]
macro_rules! array {
($($x:expr),* $(,)*) => {{
let string = format!("{:?}", vec![$($x,)*]).replace(" ", "");
let ndim = string.find(|p| p != '[').unwrap_or(1) - 1;
let ndim = if ndim == 0 { 1 } else { ndim };
let mut _string = string.clone();
let mut shape = Vec::new();
for i in (0..ndim).rev() {
let tmp_str = _string.replace(&format!("{},{}", "]".repeat(i), "[".repeat(i)), "]#[");
_string = _string[0 .. _string.find(&"]".repeat(i)).unwrap() + i].to_string();
shape.push(tmp_str.split("#").count());
};
let elems = string
.replace("[", "").replace("]", "").replace(" ", "")
.split_terminator(',')
.map(|e| e.parse().unwrap())
.collect::<Vec<_>>();
Array::new(elems, shape)
}};
}