~mht/cra

2277c12c6ee7393feb6237465e7e1e23f6f4a19c — Martin Hafskjold Thoresen 11 months ago 9b5383c
Fix warnings with old code
2 files changed, 18 insertions(+), 65 deletions(-)

M cra/src/main.rs
M cra/src/persistence.rs
M cra/src/main.rs => cra/src/main.rs +1 -1
@@ 424,7 424,7 @@ the first boundaries in the list should be that of the 1-simplices.
        simplices = ordered_simplices;
    }

    let mut persistence = Persistence {
    let persistence = Persistence {
        simplices,
        points: points.unwrap_or(Vec::new()),
        alphas: alphas.unwrap_or(Vec::new()),

M cra/src/persistence.rs => cra/src/persistence.rs +17 -64
@@ 10,8 10,6 @@ pub enum Variant {
    /// The exhaustive variant tries to lower the indices of the reduces simplcides after the max
    /// has been found.
    Exhaustive,
    /// It's not clear why this is interesting?
    ExhaustiveWhenD1,
}
use self::Variant::*;



@@ 149,6 147,7 @@ pub fn reduce(p: &Persistence, variant: Variant, _stats: &mut Statistics) -> Red
    let mut reduced_with_low: Vec<Option<Simplex>> = vec![None; p.simplices.len()];
    // We're reducing each simplex.
    for simplex in &p.simplices {
        // we'll store an index here, if we don't fully reduce the simplex
        let mut place_index = None;
        // With no boundary we're done.
        if simplex.faces.last().is_none() {


@@ 158,30 157,27 @@ pub fn reduce(p: &Persistence, variant: Variant, _stats: &mut Statistics) -> Red
        current_reduced.faces.sort();

        while current_reduced.faces.len() > 0 {
            let low: usize = *current_reduced.faces.last().unwrap();
            match reduced_with_low[low] {
                None => {
                    place_index = Some(low);
                    break;
                }
                Some(ref other) => {
                    simplex_reduce(&mut current_reduced, other);
                }
            let low = *current_reduced.faces.last().unwrap();
            if let Some(ref other) = reduced_with_low[low] {
                simplex_reduce(&mut current_reduced, other);
            } else {
                place_index = Some(low);
                break;
            }
        }

        if variant == Exhaustive {
            // Reduce the rest of the simplex. Go backwards. We can skip the last index, since
            // that's us. Then we count the numbers of boundary simplices we know we can't reduce any
            // further. Since we're going bottom up and looking at `reduced_with_low`, these cannot
            // change with later redutions.
            // that's us. Then we count the numbers of boundary simplices we know we can't reduce
            // any further. Since we're going bottom up and looking at `reduced_with_low`, these
            // cannot change with later redutions.
            let mut safe_simplices = 1;
            let mut faces = current_reduced.faces.len();
            while faces > safe_simplices {
                let cand_i = current_reduced.faces[faces - 1 - safe_simplices];
            let mut n = current_reduced.faces.len();
            while safe_simplices < n {
                let cand_i = current_reduced.faces[n - 1 - safe_simplices];
                if let Some(ref cand) = reduced_with_low[cand_i] {
                    simplex_reduce(&mut current_reduced, cand);
                    faces = current_reduced.faces.len();
                    n = current_reduced.faces.len();
                } else {
                    safe_simplices += 1;
                }


@@ 189,7 185,9 @@ pub fn reduce(p: &Persistence, variant: Variant, _stats: &mut Statistics) -> Red
        }

        if current_reduced.faces.len() != 0 {
            let i = place_index.expect("Reduced simplex isn't empty, yet we haven't set the index in which to store it");
            let i = place_index.expect(
                "Reduced simplex isn't empty, yet we haven't set the index in which to store it",
            );
            reduced_with_low[i] = Some(current_reduced);
        }
    }


@@ 249,51 247,6 @@ fn simplex_reduce(this: &mut Simplex, other: &Simplex) {
    }
}

/// 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>,
    simplex_dim: usize,
    stats: &mut Statistics,
) {
    // TODO: hehe
    static mut BUFFER: Option<Vec<usize>> = None;
    let buffer: &mut Vec<usize> = unsafe {
        if BUFFER.is_none() {
            BUFFER = Some(Vec::with_capacity(1_000));
        }
        BUFFER.as_mut().unwrap()
    };
    debug_assert_eq!(buffer.len(), 0);
    stats.col_add(simplex_dim);
    stats.add_sizes(this.len(), other.len());

    let mut our_i = 0;
    let mut their_i = 0;
    let our_last = this.len();
    let their_last = other.len();

    while our_i < our_last && their_i < their_last {
        if this[our_i] < other[their_i] {
            buffer.push(this[our_i]);
            our_i += 1;
        } else if this[our_i] == other[their_i] {
            our_i += 1;
            their_i += 1;
        } else {
            buffer.push(other[their_i]);
            their_i += 1;
        }
    }

    buffer.extend(&other[their_i..]);
    buffer.extend(&this[our_i..]);
    this.clear();
    this.extend(&*buffer);
    buffer.clear();
}

/// Compute the alpha values for the simplices, given the point location.
/// As the name suggests, this is only for dimension 2 and less.
pub fn compute_alpha_values_2d(