@@ 13,7 13,6 @@ mod persistence;
use persistence::Variant::*;
use persistence::{compute_alpha_values_2d, reduce, Persistence, Simplex};
-
// consts
const R_CUTOFF: f64 = 250.0;
const MAX_DIM: usize = 3;
@@ 305,43 304,26 @@ fn main() {
(about: crate_description!())
(version: crate_version!())
(author: crate_authors!())
- (@arg triangulation: -t --triangulation<FILE> "Input a 2D triangulation in text form.")
+ (@arg triangulation: -t --triangulation[FILE] "Input a 2D triangulation in text form.")
(@arg exhaustive: -e --exhaustive "Run the exhaustive variant of the algorithm.")
- (@arg svg: --svg<FILE> "Draw the compex to an .svg.")
+ (@arg svg: --svg[FILE] "Draw the compex to an .svg.")
(@arg alpha: -a --alpha "Ignore the ordering of the simplices given and calculate and use the alpha ordering.")
(@arg stats: -s --stats "Print out statistics.")
- (@arg graphviz: --graphiviz<FILE> "Use `graphviz` to graph out which simplices are added together.")
+ (@arg graphviz: --graphiviz[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.")
).get_matches();
if let Some(path) = matches.value_of("triangulation") {
- // TODO: input triangulation thing here
+ // TODO: input triangulation thing here
println!("{:?}", path);
}
- if let Some(path) = matches.value_of("svg") {
- // TODO: `output::svg()` here
- }
-
-
-
-
- return;
-
- let mut args = std::env::args();
- let name = match args.nth(1) {
- Some(name) => name,
- None => {
- eprintln!("No name given! Defaulting to 'default'");
- "default".to_string()
- }
- };
- let out_path = Path::new("output").join(&name);
- let sentinel_path = Path::new("output").join(format!(".{}", name));
- std::fs::create_dir_all(&out_path).expect("Failed to create dir");
- File::create(sentinel_path).expect("Failed to create sentinel file");
+ // By here we should have a `Persistence`
let mut persistence = read_input_stdin2().unwrap();
+ // TODO: this should be done somewhere else!
{
// Fix the ordering of the simplices!
persistence.simplices.sort_by(|a, b| {
@@ 372,21 354,21 @@ fn main() {
}
s.j = j;
}
- }
- // Since our sorting is not really numerically stable at all, we still need this assertion.
- for (j, s) in persistence.simplices.iter().enumerate() {
- if let Some(&face) = s.faces.iter().max() {
- if face >= j {
- eprintln!("face is after simplex! {} >= {}", face, j);
- eprintln!("{:?}", persistence.simplices[face]);
- eprintln!("{:?}", persistence.simplices[j]);
- eprintln!(
- "{:#?}",
- &persistence.simplices
- [(j.saturating_sub(3)..((face + 4).min(persistence.simplices.len())))]
- );
- panic!("The ordering is not right!");
+ // Since our sorting is not really numerically stable at all, we still need this assertion.
+ for (j, s) in persistence.simplices.iter().enumerate() {
+ if let Some(&face) = s.faces.iter().max() {
+ if face >= j {
+ eprintln!("face is after simplex! {} >= {}", face, j);
+ eprintln!("{:?}", persistence.simplices[face]);
+ eprintln!("{:?}", persistence.simplices[j]);
+ eprintln!(
+ "{:#?}",
+ &persistence.simplices
+ [(j.saturating_sub(3)..((face + 4).min(persistence.simplices.len())))]
+ );
+ panic!("The ordering is not right!");
+ }
}
}
}
@@ 412,66 394,76 @@ fn main() {
.unwrap();
}
- let mut stats_file = File::create(out_path.join("perf-stats")).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();
-
- let mut tex_file = File::create(out_path.join("perf-stats.tex")).unwrap();
- output::tex_table(&r_stats, &e_stats, &mut tex_file).unwrap();
-
- output::histogram(
- &e_stats.ex_searches,
- "Iters for finding k=low(i) for any i",
- &out_path.join("ex_searches.pdf"),
- );
- output::histogram(
- &e_stats.ex_reductions,
- "Iters for exhaustively reducing a column",
- &out_path.join("ex_reductions.pdf"),
- );
-
- output::histogram2(
- &r_stats.add_size_sum,
- &e_stats.add_size_sum,
- "Cost estimate for column additions",
- &out_path.join("add_size_sum.pdf"),
- );
- output::histogram2(
- &r_stats.num_iters,
- &e_stats.num_iters,
- "Number of column additions before fully reducing one column",
- &out_path.join("num_iters.pdf"),
- );
-
- let mut f = File::create("test.dot").unwrap();
- output::graphviz(
- &persistence,
- &standard_reduction,
- &exhaustive_reduction,
- &mut f,
- )
- .unwrap();
-
- let birth_death_pairs = standard_reduction
- .pairings
- .iter()
- .map(|&(a, b)| {
- (
- persistence.simplices[a].r_when_born,
- persistence.simplices[b].r_when_born,
- )
- })
- .collect::<Vec<(f64, f64)>>();
- output::persistence(&birth_death_pairs, &out_path.join("persistence.pdf"));
-
- output::svg(
- &persistence,
- &standard_reduction,
- &exhaustive_reduction,
- &out_path.join("rendering.svg"),
- );
+ if let Some(path) = matches.value_of("stats") {
+ let mut stats_file = File::create(Path::new(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();
+ }
+
+ 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::histogram(
+ // &e_stats.ex_searches,
+ // "Iters for finding k=low(i) for any i",
+ // &out_path.join("ex_searches.pdf"),
+ // );
+ // output::histogram(
+ // &e_stats.ex_reductions,
+ // "Iters for exhaustively reducing a column",
+ // &out_path.join("ex_reductions.pdf"),
+ // );
+ //
+ // output::histogram2(
+ // &r_stats.add_size_sum,
+ // &e_stats.add_size_sum,
+ // "Cost estimate for column additions",
+ // &out_path.join("add_size_sum.pdf"),
+ // );
+ // output::histogram2(
+ // &r_stats.num_iters,
+ // &e_stats.num_iters,
+ // "Number of column additions before fully reducing one column",
+ // &out_path.join("num_iters.pdf"),
+ // );
+
+ if let Some(path) = matches.value_of("graphviz") {
+ let mut f = File::create("test.dot").unwrap();
+ output::graphviz(
+ &persistence,
+ &standard_reduction,
+ &exhaustive_reduction,
+ &mut f,
+ )
+ .unwrap();
+ }
+
+ if let Some(path) = matches.value_of("diagram") {
+ let birth_death_pairs = standard_reduction
+ .pairings
+ .iter()
+ .map(|&(a, b)| {
+ (
+ persistence.simplices[a].r_when_born,
+ persistence.simplices[b].r_when_born,
+ )
+ })
+ .collect::<Vec<(f64, f64)>>();
+ output::persistence(&birth_death_pairs, &Path::new(path));
+ }
+
+ if let Some(path) = matches.value_of("svg") {
+ output::svg(
+ &persistence,
+ &standard_reduction,
+ &exhaustive_reduction,
+ &Path::new(path),
+ );
+ }
}