pretty_print_nalgebra/
lib.rs

1//! a small macro-only crate providing ability to pretty-print a 2D nalgebra array
2
3#[macro_export]
4macro_rules! pretty_print {
5    ($arr:expr) => {{
6        let indent = 4;
7        let prefix = String::from_utf8(vec![b' '; indent]).unwrap();
8        let mut result_els = vec!["".to_string()];
9        for i in 0..$arr.nrows() {
10            let mut row_els = vec![];
11            for j in 0..$arr.ncols() {
12                row_els.push(format!("{:12.3}", $arr[(i,j)]));
13            }
14            let row_str = row_els.into_iter().collect::<Vec<_>>().join(" ");
15            let row_str = format!("{}{}", prefix, row_str);
16            result_els.push( row_str );
17        }
18        result_els.into_iter().collect::<Vec<_>>().join("\n")
19    }}
20}