diff options
-rw-r--r-- | include/phat/compute_persistence_pairs.h | 14 | ||||
-rw-r--r-- | include/phat/helpers/dualize.h | 9 | ||||
-rw-r--r-- | include/phat/persistence_pairs.h | 4 | ||||
-rw-r--r-- | src/phat.cpp | 22 |
4 files changed, 33 insertions, 16 deletions
diff --git a/include/phat/compute_persistence_pairs.h b/include/phat/compute_persistence_pairs.h index e782bd7..d3e61dd 100644 --- a/include/phat/compute_persistence_pairs.h +++ b/include/phat/compute_persistence_pairs.h @@ -41,18 +41,10 @@ namespace phat { template< typename ReductionAlgorithm, typename Representation > void compute_persistence_pairs_dualized( persistence_pairs& pairs, boundary_matrix< Representation >& boundary_matrix ) { - ReductionAlgorithm reduce; - const index nr_columns = boundary_matrix.get_num_cols(); + dualize( boundary_matrix ); - reduce( boundary_matrix ); - pairs.clear(); - for( index idx = 0; idx < nr_columns; idx++ ) { - if( !boundary_matrix.is_empty( idx ) ) { - index death = nr_columns - 1 - boundary_matrix.get_max_index( idx ); - index birth = nr_columns - 1 - idx; - pairs.append_pair( birth, death ); - } - } + compute_persistence_pairs( pairs, boundary_matrix ); + dualize_persistence_pairs( pairs, boundary_matrix.get_num_cols() ); } template< typename Representation > diff --git a/include/phat/helpers/dualize.h b/include/phat/helpers/dualize.h index 5a9baf7..e3ae9ed 100644 --- a/include/phat/helpers/dualize.h +++ b/include/phat/helpers/dualize.h @@ -20,6 +20,8 @@ #include <phat/helpers/misc.h>
#include <phat/boundary_matrix.h>
+#include <phat/persistence_pairs.h>
+
namespace phat {
template< typename Representation >
@@ -60,4 +62,11 @@ namespace phat { boundary_matrix.load_vector_vector( dual_matrix, dual_dims );
}
+
+ void dualize_persistence_pairs( persistence_pairs& pairs, const index n ) {
+ for (index i = 0; i < pairs.get_num_pairs(); ++i) {
+ std::pair< index, index > pair = pairs.get_pair( i );
+ pairs.set_pair( i , n - 1 - pair.second, n - 1 - pair.first);
+ }
+ }
}
diff --git a/include/phat/persistence_pairs.h b/include/phat/persistence_pairs.h index b808a28..eafc638 100644 --- a/include/phat/persistence_pairs.h +++ b/include/phat/persistence_pairs.h @@ -39,6 +39,10 @@ namespace phat { return pairs[ idx ];
}
+ void set_pair( index idx, index birth, index death ) {
+ pairs[ idx ] = std::make_pair( birth, death );
+ }
+
void clear() {
pairs.clear();
}
diff --git a/src/phat.cpp b/src/phat.cpp index a955b54..c19aea8 100644 --- a/src/phat.cpp +++ b/src/phat.cpp @@ -30,6 +30,7 @@ #include <phat/algorithms/row_reduction.h>
#include <phat/algorithms/chunk_reduction.h>
+#include <phat/helpers/dualize.h>
enum Representation_type {VECTOR_VECTOR, VECTOR_SET, SPARSE_PIVOT_COLUMN, FULL_PIVOT_COLUMN, BIT_TREE_PIVOT_COLUMN, VECTOR_LIST};
enum Algorithm_type {STANDARD, TWIST, ROW, CHUNK, CHUNK_SEQUENTIAL };
@@ -108,17 +109,28 @@ void compute_pairing( std::string input_filename, std::string output_filename, b std::cerr << "Error opening file " << input_filename << std::endl;
print_help_and_exit();
}
-
+
+ phat::index num_cols = matrix.get_num_cols();
+
+ if( dualize ) {
+ double dualize_timer = omp_get_wtime();
+ LOG( "Dualizing ..." )
+ phat::dualize ( matrix );
+ double dualize_time = omp_get_wtime() - dualize_timer;
+ double dualize_time_rounded = floor( dualize_time * 10.0 + 0.5 ) / 10.0;
+ LOG( "Dualizing took " << setiosflags( std::ios::fixed ) << setiosflags( std::ios::showpoint ) << std::setprecision( 1 ) << dualize_time_rounded <<"s" )
+ }
+
double pairs_timer = omp_get_wtime();
phat::persistence_pairs pairs;
LOG( "Computing persistence pairs ..." )
- if( dualize )
- phat::compute_persistence_pairs_dualized< Algorithm > ( pairs, matrix );
- else
- phat::compute_persistence_pairs < Algorithm > ( pairs, matrix );
+ phat::compute_persistence_pairs < Algorithm > ( pairs, matrix );
double pairs_time = omp_get_wtime() - pairs_timer;
double pairs_time_rounded = floor( pairs_time * 10.0 + 0.5 ) / 10.0;
LOG( "Computing persistence pairs took " << setiosflags( std::ios::fixed ) << setiosflags( std::ios::showpoint ) << std::setprecision( 1 ) << pairs_time_rounded <<"s" )
+
+ if( dualize ) dualize_persistence_pairs( pairs, num_cols );
+
double write_timer = omp_get_wtime();
if( use_binary ) {
|