~mht/cra

f74d5c6646ad32e8056e384fd4149f34238e15e5 — Martin Hafskjold Thoresen 2 years ago 77dcba4
Improve tex table output
1 files changed, 54 insertions(+), 87 deletions(-)

M cra/src/main.rs
M cra/src/main.rs => cra/src/main.rs +54 -87
@@ 8,7 8,7 @@ use std::iter;
use std::path::Path;
use std::process::{Command, Stdio};

const R_CUTOFF: f64 = 30000.0;
const R_CUTOFF: f64 = 200.0;

fn f64_eq(a: f64, b: f64) -> bool {
    let u = 1_000_000.0;


@@ 1113,7 1113,7 @@ plot '{file_path}' using ($0):(cum_a($1, $0)) with lines   lc rgb"gray20" title 
    std::fs::remove_file(file_path).unwrap();
}

fn tex_table<W: Write>(reg: &Statistics, exh: &Statistics, writer: &mut W) {
fn tex_table<W: Write>(reg: &Statistics, exh: &Statistics, writer: &mut W) -> Result<(), std::io::Error> {
    fn sum(s: &[usize]) -> f64 {
        s.iter().sum::<usize>() as f64
    }


@@ 1122,9 1122,54 @@ fn tex_table<W: Write>(reg: &Statistics, exh: &Statistics, writer: &mut W) {
        sum(s) / s.len() as f64
    }

    fn percent(a: f64, b: f64) -> String {
        format!("{:.2}\\%", 100.0 * b / a)
    fn percent(hundred: f64, ours: f64) -> String {
        if hundred == 0.0 {
            format!("")
        } else {
            format!("{:.2}\\%", 100.0 * ours / hundred)
        }
    }

    let header_align = std::iter::repeat("r l").take(MAX_DIM).collect::<Vec<&str>>().join(" ");
    let header_top = (0..MAX_DIM).map(|d| format!("\\multicolumn{{2}}{{c}}{{$d={}$}} ", d)).collect::<Vec<_>>().join(" & ");
    write!(
        writer,
        r#"\begin{{tabular}}{{r r {}}}
  Name & Total & {} \\
  \toprule
"#, header_align, header_top
    )?;

    let total = reg.num_of_dimens.iter().sum::<usize>();
    let mut line = format!("Simplices & {}", total);
    for &n in reg.num_of_dimens.iter() {
        line.push_str(&format!("& \\hspace{{0.5cm}}{} & {}", thousand_split(n), percent(total as f64, n as f64)));
    }
    writeln!(writer, "{}\\\\", line)?;

    let total = reg.skip_d.iter().sum::<usize>();
    let mut line = format!("Skipped & {}", total);
    for &n in reg.skip_d.iter() {
        line.push_str(&format!("& {} & {}", thousand_split(n), percent(total as f64, n as f64)));
    }
    writeln!(writer, "{}\\\\", line)?;

    let total = reg.zeroed_d.iter().sum::<usize>();
    let mut line = format!("Zeroed & {}", total);
    for &n in reg.zeroed_d.iter() {
        line.push_str(&format!("& {} & {}", thousand_split(n), percent(total as f64, n as f64)));
    }
    writeln!(writer, "{}\\\\", line)?;

    let total = reg.placed_full_d.iter().sum::<usize>();
    let mut line = format!("Stored & {}", total);
    for &n in reg.placed_full_d.iter() {
        line.push_str(&format!("& {} & {}", thousand_split(n), percent(total as f64, n as f64)));
    }
    writeln!(writer, "{}\\\\", line)?;

    writeln!(writer, "\\end{{tabular}}\n")?;
    writeln!(writer, "\\vspace{{1cm}}")?;

    let mut v: Vec<(String, String, String, String)> = Vec::new();



@@ 1228,92 1273,13 @@ fn tex_table<W: Write>(reg: &Statistics, exh: &Statistics, writer: &mut W) {
  Counter & Regular & Exhausitve & Difference \\
  \toprule
"#
    )
    .unwrap();
    )?;
    for (l, a, b, p) in v {
        write!(writer, "  {} & {} & {} & {}\\\\\n", l, a, b, p).unwrap();
    }
    writeln!(writer, "\\end{{tabular}}").unwrap();

    let mut s: Vec<(String, String, String)> = Vec::new();

    s.push((
        format!("Simplices"),
        thousand_split(reg.num_of_dimens.iter().sum::<usize>()),
        format!("")
    ));
    for (d, &n) in reg.num_of_dimens.iter().enumerate() {
        s.push((
            format!("$d={}$", d),
            thousand_split(n),
            format!("")
        ));
    }

    s.push((
        format!("Skipped simplices"),
        thousand_split(reg.skip_d.iter().sum::<usize>()),
        format!("")
    ));
    for (d, &r) in reg.skip_d.iter().enumerate() {
        s.push((
            format!("\\ldots $d={}$", d),
            thousand_split(r),
            if reg.num_of_dimens[d] > 0 {
                percent(reg.num_of_dimens[d] as f64, r as f64)
            } else {
                format!("")
            }
        ));
    }

    s.push((
        format!("Zeroed simplices"),
        thousand_split(reg.zeroed),
        format!("")
    ));
    for (d, &r) in reg.zeroed_d.iter().enumerate() {
        s.push((
            format!("\\ldots $d={}$", d),
            thousand_split(r),
            if reg.num_of_dimens[d] > 0 {
                percent(reg.num_of_dimens[d] as f64, r as f64)
            } else {
                format!("")
            }
        ));
    }

    s.push((
        format!("Stored simplices"),
        thousand_split(reg.placed_full),
        format!("")
    ));

    for (d, &r) in reg.placed_full_d.iter().enumerate() {
        s.push((
            format!("\\ldots $d={}$", d),
            thousand_split(r),
            if reg.num_of_dimens[d] > 0 {
                percent(reg.num_of_dimens[d] as f64, r as f64)
            } else {
                format!("")
            }
        ));
        write!(writer, "  {} & {} & {} & {}\\\\\n", l, a, b, p)?;
    }
    writeln!(writer, "\\end{{tabular}}")?;

    write!(
        writer,
        r#"\begin{{tabular}}{{r r r r}}
  Counter & Value & \\
  \toprule
"#
    )
    .unwrap();
    for (l, a, p) in s {
        write!(writer, "  {} & {} & {}\\\\\n", l, a, p).unwrap();
    }
    writeln!(writer, "\\end{{tabular}}\n").unwrap();
    Ok(())
}

/// Write out a dotfile with the directed edges given by `simplex_with_low`


@@ 1399,6 1365,7 @@ fn get_triangle_xyz(simplex: &Simplex, simplices: &[Simplex]) -> (usize, usize, 
        // xy, xz
        (xy.faces[0], xy.faces[1], zx.faces[1])
    } else if xy.faces[0] == zx.faces[1] {

        // xy, zx
        (xy.faces[0], xy.faces[1], zx.faces[0])
    } else if xy.faces[1] == zx.faces[0] {