~mht/cra

adb9ec970458207b92bea6640233d2b200219e3a — Martin Hafskjold Thoresen 2 years ago e4ca49b
Comment out code we don't need

For some reason, the regular is faster than the exhaustive. Weird.
2 files changed, 40 insertions(+), 38 deletions(-)

M cra/Cargo.toml
M cra/src/main.rs
M cra/Cargo.toml => cra/Cargo.toml +0 -3
@@ 5,6 5,3 @@ authors = ["Martin Hafskjold Thoresen <git@mht.technology>"]

[dependencies]
time = "0.1.42"

[profile.release]
debug = true

M cra/src/main.rs => cra/src/main.rs +40 -35
@@ 1,5 1,4 @@
use std::cmp::Ordering::*;
use std::collections::HashSet;
use std::fmt::Write as fmtWrite;
use std::fs::File;
use std::io::{BufRead, BufReader, Write};


@@ 420,13 419,18 @@ pub fn reduce(p: &Persistence, exhaustive: bool, stats: &mut Statistics) -> Vec<

    let mut pairings = Vec::new();

    let mut killed = HashSet::new();
    let mut zeroed = HashSet::new();
    // use std::collections::HashSet;
    // let mut killed = vec![false; n];
    // let mut zeroed = HashSet::new();

    let mut gives_death = vec![false; n];
    let mut got_zeroed = Vec::new();
    // let mut gives_death = vec![false; n];
    // let mut got_zeroed = Vec::new();

    for simplex in p.simplices.iter() {
        if simplex.faces.last().is_none() {
            continue;
        }

        let j = simplex.j;
        // eprintln!("== {:?}", simplex);
        if simplex.r_when_born >= R_CUTOFF {


@@ 435,26 439,22 @@ pub fn reduce(p: &Persistence, exhaustive: bool, stats: &mut Statistics) -> Vec<
            // eprintln!("Skipping simplex with `r_when_born == {}`", simplex.r_when_born);
            continue;
        }
        // We probably want to copy the face data anyways, since we're chaning the columns and we
        // want to still have the original data in the `Persistence` struct.

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

        if j > 0 && *current_simplex.iter().max().unwrap() >= j {
            eprintln!("OH NO!! {:?}", simplex);
            for &face in &simplex.faces {
                eprintln!("        {:?}", p.simplices[face]);
            }
            eprintln!("    {:?}", current_simplex);
            panic!(
                "This list is not well formed! j={} {:?}",
                j, current_simplex
            );
        }

        if current_simplex.last().is_none() {
            continue;
        }
        // DEBUG:
        // if j > 0 && *current_simplex.iter().max().unwrap() >= j {
        //     eprintln!("OH NO!! {:?}", simplex);
        //     for &face in &simplex.faces {
        //         eprintln!("        {:?}", p.simplices[face]);
        //     }
        //     eprintln!("    {:?}", current_simplex);
        //     panic!(
        //         "This list is not well formed! j={} {:?}",
        //         j, current_simplex
        //     );
        // }

        let mut iter = 0;
        loop {


@@ 463,10 463,12 @@ pub fn reduce(p: &Persistence, exhaustive: bool, stats: &mut Statistics) -> Vec<

            if simplex_with_low[low].is_null() {
                // We have found a simplex that no other dimen=d simplex have yet.
                assert!(low <= j);
                debug_assert!(low <= j);
                pairings.push((low, j));
                gives_death[j] = true;
                killed.insert(low);

                // TODO: reinsert at some point.
                // gives_death[j] = true;
                // killed.insert(low);

                if current_simplex.len() == 1 {
                    stats.placed_single();


@@ 487,7 489,7 @@ pub fn reduce(p: &Persistence, exhaustive: bool, stats: &mut Statistics) -> Vec<
                            let list_len = this.len();
                            for (iter_i, face_i) in (0..list_len).rev().enumerate() {
                                let this_index = this[face_i];
                                assert!(this_index != low);
                                debug_assert!(this_index != low);
                                let other = &simplex_with_low[this_index];
                                if other.is_null() {
                                    // nothing to see here


@@ 530,7 532,7 @@ pub fn reduce(p: &Persistence, exhaustive: bool, stats: &mut Statistics) -> Vec<
            } else {
                // Add `low` to `j`.
                let other = simplex_with_low[low].get();
                assert!(*other.iter().max().unwrap() <= low);
                debug_assert!(*other.iter().max().unwrap() <= low);
                column_add(&mut current_simplex, other, stats);
                pop(&mut current_simplex, stats); // xor out the implicit value as well.
            }


@@ 541,8 543,11 @@ pub fn reduce(p: &Persistence, exhaustive: bool, stats: &mut Statistics) -> Vec<
                // essential cycle. Since we're storing a simplex with its `low` (low) implicit in
                // that index, this is `simplex_with_low[j]`.
                stats.zeroed();
                got_zeroed.push(j);
                zeroed.insert(j);

                // TODO:
                // got_zeroed.push(j);
                // zeroed.insert(j);

                break;
            }
        }


@@ 554,10 559,10 @@ pub fn reduce(p: &Persistence, exhaustive: bool, stats: &mut Statistics) -> Vec<
    // Find the essential cycles: these are entries that did not give death, and are `null` in the
    // `simplex_with_low` (in matrix terms, this means that row `i` has no `low`s in it).

    for &cyc in zeroed.difference(&killed) {
        let s = p.simplices.iter().find(|&s| s.j == cyc).unwrap();
        eprintln!("[reduce] Essential cycle: {:?}", s);
    }
    // for &cyc in zeroed.difference(&killed) {
    //     let s = p.simplices.iter().find(|&s| s.j == cyc).unwrap();
    //     eprintln!("[reduce] Essential cycle: {:?}", s);
    // }

    // for (i, ptr) in simplex_with_low.iter().enumerate() {
    //     eprint!("{:2}: ", i);


@@ 630,7 635,7 @@ fn column_add(this: &mut Vec<usize>, other: &Vec<usize>, stats: &mut Statistics)
        }
        BUFFER.as_mut().unwrap()
    };
    assert_eq!(buffer.len(), 0);
    debug_assert_eq!(buffer.len(), 0);
    stats.col_adds += 1;
    stats.add_sizes(this.len(), other.len());
    // For now, let's just walk through both vecs trying to find matches, add new ones into


@@ 949,7 954,7 @@ fn main() {
    let mut persistence = read_input_stdin2().unwrap();

    for (i, s) in persistence.simplices.iter().enumerate() {
        assert_eq!(i, s.j);
        debug_assert_eq!(i, s.j);
    }

    persistence.simplices.sort_by(|a, b| {