persistence/
persistence.rs

1use std::fs::File;
2use std::io::BufReader;
3use teia::Persistence;
4use teia::traits::*;
5use teia::reader::simpcomp;
6use teia::z2reduce::Z2ColumnReduce;
7use teia::z2vector::{Z2Chain, Z2VectorVec, Z2Vector};
8use teia::pair::Pair;
9
10fn main() {
11    let file = File::open("examples/torus.txt").unwrap();
12
13    let comp = simpcomp::read_simpcomp_text(BufReader::new(file)).unwrap();
14
15    let reduce = Z2ColumnReduce::<Z2Chain<Z2VectorVec>>
16            ::from_complex_with(&comp, |index, chain| Z2Chain::new(index, chain)).unwrap();
17
18    for (pers, chain) in Pair::new(&reduce, reduce.cycles()) {
19        match pers {
20            Persistence(birth, Some(death)) => {
21                print!("{} {}", birth, death);
22            },
23            Persistence(birth, None) => {
24                print!("{} inf", birth);
25            },
26        };
27        println!(" {}", comp.basis[chain.chain.lowest().unwrap()].dimension());
28    }
29}