~mht/cra

a9f2af5decc8d6d8e7a214cfc1d22fe58463410f — Martin Hafskjold Thoresen 2 years ago d4f1ee3
Output column adds for different dims in the tex table
1 files changed, 44 insertions(+), 13 deletions(-)

M cra/src/main.rs
M cra/src/main.rs => cra/src/main.rs +44 -13
@@ 23,6 23,7 @@ fn f64_eq(a: f64, b: f64) -> bool {
#[derive(Debug)]
pub struct Statistics {
    col_adds: usize,
    col_add_dimens: Vec<usize>,
    add_size: Vec<(usize, usize)>,
    add_size_sum: Vec<usize>,
    num_iters: Vec<usize>,


@@ 43,6 44,7 @@ impl Statistics {
    pub fn new() -> Self {
        Self {
            col_adds: 0,
            col_add_dimens: Vec::new(),
            add_size: Vec::new(),
            add_size_sum: Vec::new(),
            num_iters: Vec::new(),


@@ 58,6 60,13 @@ impl Statistics {
        }
    }

    /// Record that there was a column addition, and the dimension of the simplices that were added
    /// together.
    pub fn col_add(&mut self, dim: usize) {
        self.col_adds += 1;
        self.col_add_dimens.push(dim);
    }

    /// Record the number of iterations we needed to find a index containing a low in another
    /// column, while in the exhaustive variant.
    pub fn ex_search(&mut self, c: usize) {


@@ 567,6 576,7 @@ pub fn reduce(p: &Persistence, variant: Variant, stats: &mut Statistics) -> Redu
        if simplex.faces.last().is_none() || simplex.r_when_born >= R_CUTOFF {
            continue;
        }
        let s_dim = simplex.dim();

        let mut current_simplex = simplex.faces.clone();
        current_simplex.sort();


@@ 611,7 621,7 @@ pub fn reduce(p: &Persistence, variant: Variant, stats: &mut Statistics) -> Redu
                            };

                            additions.push((j_stored_at[this_index], j));
                            column_add(this_mut, other.get(), stats);
                            column_add(this_mut, other.get(), s_dim, stats);
                            iter += 1;
                            stats.ex_search(iter_i + 1);
                            continue 'search;


@@ 626,7 636,7 @@ pub fn reduce(p: &Persistence, variant: Variant, stats: &mut Statistics) -> Redu
            }

            additions.push((j_stored_at[low], j));
            column_add(&mut current_simplex, cand.get(), stats);
            column_add(&mut current_simplex, cand.get(), s_dim, stats);
            if current_simplex.is_empty() {
                stats.zeroed();
                break;


@@ 711,7 721,7 @@ impl IndList {

/// Add the `other` column into the `this` column. Since we're in (mod 2) arithmetic, this `xor`s
/// together the two vectors.
fn column_add(this: &mut Vec<usize>, other: &Vec<usize>, stats: &mut Statistics) {
fn column_add(this: &mut Vec<usize>, other: &Vec<usize>, simplex_dim: isize, stats: &mut Statistics) {
    // TODO: hehe
    static mut BUFFER: Option<Vec<usize>> = None;
    let buffer: &mut Vec<usize> = unsafe {


@@ 721,7 731,9 @@ fn column_add(this: &mut Vec<usize>, other: &Vec<usize>, stats: &mut Statistics)
        BUFFER.as_mut().unwrap()
    };
    debug_assert_eq!(buffer.len(), 0);
    stats.col_adds += 1;
    if simplex_dim >= 0 {
        stats.col_add(simplex_dim as usize);
    }
    stats.add_sizes(this.len(), other.len());

    let mut our_i = 0;


@@ 750,7 762,7 @@ fn column_add(this: &mut Vec<usize>, other: &Vec<usize>, stats: &mut Statistics)
}

fn output_svg(persistence: &Persistence, std: &Reduction, exh: &Reduction, out_path: &Path) {
    const DRAW_TEXT: bool = true;
    const DRAW_TEXT: bool = false;
    let mut f = std::io::BufWriter::new(std::fs::File::create(out_path).unwrap());

    const PADDING: f64 = 50f64;


@@ 1170,32 1182,51 @@ fn tex_table<W: Write>(reg: &Statistics, exh: &Statistics, writer: &mut W) {

    v.push((
        "Average iterations to exh.\\ reduce a col",
        format!("N/A"),
        format!(""),
        format!("{:.4}", avg(&exh.ex_reductions)),
        "N/A".to_string(),
        format!(""),
    ));

    v.push((
        "Average searches to find \\texttt{j=low(k)}",
        format!("N/A"),
        format!(""),
        format!("{:.4}", avg(&exh.ex_searches)),
        "N/A".to_string(),
        format!(""),
    ));

    v.push((
        "Number of zeroed simplices",
        thousand_split(reg.zeroed),
        thousand_split(exh.zeroed),
        percent(reg.zeroed as f64, exh.zeroed as f64),
        format!("")
    ));

    v.push((
        "Number of stored simplices",
        thousand_split(reg.placed_full),
        thousand_split(exh.placed_full),
        percent(reg.placed_full as f64, exh.placed_full as f64),
        format!("")
    ));

    // TODO: 4 could be bigger!
    let mut reg_counts = [0; 4];
    for &d in &reg.col_add_dimens {
        reg_counts[(d + 1) as usize] += 1;
    }
    let mut exh_counts = [0; 4];
    for &d in &exh.col_add_dimens {
        exh_counts[(d + 1) as usize] += 1;
    }
    let strs = (0..exh_counts.len()).map(|d1| format!("Column adds with $d={}$", d1 as isize - 1)).collect::<Vec<_>>();
    for (d1, (&r, &e)) in reg_counts.iter().zip(exh_counts.iter()).enumerate().skip(1) {
        v.push((
            &strs[d1],
            thousand_split(r),
            thousand_split(e),
            percent(r as f64, e as f64)
        ));
    }

    let mut last_pos = 0;
    for (i, (&a, &b)) in reg
        .num_of_dimens


@@ 1217,7 1248,7 @@ fn tex_table<W: Write>(reg: &Statistics, exh: &Statistics, writer: &mut W) {
            &strs[d],
            thousand_split(r),
            thousand_split(e),
            percent(r as f64, e as f64),
            format!("")
        ));
    }



@@ 1405,7 1436,7 @@ fn main() {
    let exhaustive_reduction = reduce(&persistence, Exhaustive, &mut e_stats);
    assert_eq!(standard_reduction.pairings, exhaustive_reduction.pairings);

    if true {
    if false {
        let mut out = std::io::stderr();
        standard_reduction.write_table(&mut out, &persistence.simplices).unwrap();
        write!(out, "\n\n");