~mht/cra

b960d2081d56f8bd7778b574b10cce1e3320c42a — Martin Hafskjold Thoresen 11 months ago 36bae91
Remove double reduction variant runs.

It's probably better to run just one of the variants, and output the data
to some other format. For the stats things we could use some other standard
format, and have a script patch things back together.
2 files changed, 21 insertions(+), 48 deletions(-)

M cra/src/main.rs
M cra/src/persistence.rs
M cra/src/main.rs => cra/src/main.rs +21 -35
@@ 374,6 374,17 @@ fn open_file_or_stdin(
    }
}

/// Open the file given, or if the filename is "-", open `stdin`.
fn open_file_or_stdout(
    filename: &str,
) -> Result<Box<dyn std::io::Write>, Box<dyn std::error::Error>> {
    if filename == "-" {
        Ok(Box::new(std::io::stdout()))
    } else {
        Ok(Box::new(File::create(Path::new(filename))?))
    }
}

fn main() {
    use clap::*;
    let matches = clap_app!(


@@ 386,7 397,7 @@ fn main() {
        (@arg exhaustive: -e --exhaustive "Run the exhaustive variant of the algorithm.")
        (@arg svg: --svg[FILE] requires[points] "Draw the compex to an .svg.")
        (@arg alpha: -a --alpha requires[points] "Ignore the ordering of the simplices given and calculate and use the alpha ordering.")
        (@arg stats: -s --stats "Print out statistics.")
        (@arg stats: -s --stats[FILE] "Print out statistics.")
        (@arg graphviz: --graphviz[FILE] "Use `graphviz` to graph out which simplices are added together.")
        (@arg diagram: --diagram[FILE] "Use `gnuplot` to print out the persistence diagram.")
        (@arg textable: --("tex-table")[FILE] "Output a `tex` formatted table of statistics.")


@@ 431,40 442,26 @@ the first boundaries in the list should be that of the 1-simplices.
        alphas: alphas.unwrap_or(Vec::new()),
    };

    let mut e_stats = Statistics::new();
    let mut r_stats = Statistics::new();

    persistence.register_stats(&mut e_stats);
    persistence.register_stats(&mut r_stats);
    let mut stats = Statistics::new();

    let standard_reduction = reduce(&persistence, Standard, &mut r_stats);
    let exhaustive_reduction = reduce(&persistence, Exhaustive, &mut e_stats);
    assert_eq!(standard_reduction.pairings, exhaustive_reduction.pairings);
    let reduction = reduce(&persistence, Standard, &mut stats);

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

    if let Some(path) = matches.value_of("stats") {
        let mut stats_file = File::create(Path::new(path)).unwrap();

        let mut stats_file = open_file_or_stdout(path).unwrap();
        write!(stats_file, "# Standard\n").unwrap();
        output::stats(&r_stats, &mut stats_file).unwrap();
        write!(stats_file, "\n\n").unwrap();
        write!(stats_file, "# Exhaustive\n").unwrap();
        output::stats(&e_stats, &mut stats_file).unwrap();
        output::stats(&stats, &mut stats_file).unwrap();
    }

    if let Some(path) = matches.value_of("textable") {
        let mut tex_file = File::create(Path::new(path)).unwrap();
        output::tex_table(&r_stats, &e_stats, &mut tex_file).unwrap();
        output::tex_table(&stats, &stats, &mut tex_file).unwrap();
    }

    //    output::histogram(


@@ 493,17 490,11 @@ the first boundaries in the list should be that of the 1-simplices.

    if let Some(path) = matches.value_of("graphviz") {
        let mut f = File::create(Path::new(path)).unwrap();
        output::graphviz(
            &persistence,
            &standard_reduction,
            &exhaustive_reduction,
            &mut f,
        )
        .unwrap();
        output::graphviz(&persistence, &reduction, &reduction, &mut f).unwrap();
    }

    if let Some(path) = matches.value_of("diagram") {
        let birth_death_pairs = standard_reduction
        let birth_death_pairs = reduction
            .pairings
            .iter()
            .map(|&(a, b)| (persistence.alphas[a], persistence.alphas[b]))


@@ 512,11 503,6 @@ the first boundaries in the list should be that of the 1-simplices.
    }

    if let Some(path) = matches.value_of("svg") {
        output::svg(
            &persistence,
            &standard_reduction,
            &exhaustive_reduction,
            &Path::new(path),
        );
        output::svg(&persistence, &reduction, &reduction, &Path::new(path));
    }
}

M cra/src/persistence.rs => cra/src/persistence.rs +0 -13
@@ 49,18 49,6 @@ pub struct Persistence {
    pub alphas: Vec<f64>,
}

impl Persistence {
    /// Fill in some stats
    pub fn register_stats(&self, stats: &mut Statistics) {
        for s in &self.simplices {
            if s.dim() < 0 {
                continue;
            }
            stats.num_of_dimens[s.dim() as usize] += 1;
        }
    }
}

/// The result from reducing.
#[derive(Debug)]
pub struct Reduction {


@@ 243,7 231,6 @@ fn simplex_reduce(this: &mut Simplex, other: &Simplex) {
        for &n in &buf[..buffer_i] {
            this.faces.push(n);
        }

    } else {
        std::mem::swap(&mut this.faces, &mut slow_vec);
    }