diff options
author | Ulrich Bauer <mail@ulrich-bauer.org> | 2016-09-29 23:03:31 +0200 |
---|---|---|
committer | Ulrich Bauer <mail@ulrich-bauer.org> | 2016-09-29 23:03:31 +0200 |
commit | d9dd55298050b116aa955fd4a3db512b114cf043 (patch) | |
tree | cff75f48067285b6351b9cf51523f3a3bd82cfb9 | |
parent | 77deb431e86bab1b4d3716909fc061ac52f692f1 (diff) | |
parent | 5adf0472e278034d155395cb8a95c017b30f0acb (diff) |
Merge commit '5adf0472e278034d155395cb8a95c017b30f0acb' into sparse-distance-matrix
* commit '5adf0472e278034d155395cb8a95c017b30f0acb':
rearranged reduction columns code
suppress output of 0-persistence pairs in dim 0
fixed license header
-rw-r--r-- | ripser.cpp | 59 |
1 files changed, 32 insertions, 27 deletions
@@ -1,19 +1,23 @@ -/* Ripser: a lean C++ code for the computation of Vietoris-Rips persistence barcodes +/* - Copyright 2015-2016 Ulrich Bauer. +Ripser: a lean C++ code for computation of Vietoris-Rips persistence barcodes - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. +Copyright 2015-2016 Ulrich Bauer. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU Lesser General Public License as published by the +Free Software Foundation, either version 3 of the License, or (at your option) +any later version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program. If not, see <http://www.gnu.org/licenses/>. + +*/ - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. */ //#define ASSEMBLE_REDUCTION_MATRIX //#define USE_COEFFICIENTS @@ -602,7 +606,7 @@ void compute_pairs(std::vector<diameter_index_t>& columns_to_reduce, hash_map<in #endif #ifdef ASSEMBLE_REDUCTION_MATRIX - compressed_sparse_matrix<diameter_entry_t> reduction_matrix; + compressed_sparse_matrix<diameter_entry_t> reduction_coefficients; #else #ifdef USE_COEFFICIENTS std::vector<diameter_entry_t> reduction_coefficients; @@ -640,9 +644,9 @@ void compute_pairs(std::vector<diameter_index_t>& columns_to_reduce, hash_map<in diameter_entry_t pivot(0, -1, -1 + modulus); #ifdef ASSEMBLE_REDUCTION_MATRIX - // initialize reduction_matrix as identity matrix - reduction_matrix.append_column(); - reduction_matrix.push_back(diameter_entry_t(column_to_reduce, 1)); + // initialize reduction_coefficients as identity matrix + reduction_coefficients.append_column(); + reduction_coefficients.push_back(diameter_entry_t(column_to_reduce, 1)); #else #ifdef USE_COEFFICIENTS reduction_coefficients.push_back(diameter_entry_t(column_to_reduce, 1)); @@ -655,18 +659,18 @@ void compute_pairs(std::vector<diameter_index_t>& columns_to_reduce, hash_map<in const coefficient_t factor = modulus - get_coefficient(pivot); #ifdef ASSEMBLE_REDUCTION_MATRIX - for (auto it = reduction_matrix.cbegin(j); it != reduction_matrix.cend(j); ++it) -#endif - { -#ifdef ASSEMBLE_REDUCTION_MATRIX - diameter_entry_t simplex = *it; + auto coeffs_begin = reduction_coefficients.cbegin(j), coeffs_end = reduction_coefficients.cend(j); #else #ifdef USE_COEFFICIENTS - diameter_entry_t simplex = reduction_coefficients[j]; + auto coeffs_begin = &reduction_coefficients[j], coeffs_end = &reduction_coefficients[j] + 1; #else - diameter_entry_t simplex = columns_to_reduce[j]; + auto coeffs_begin = &columns_to_reduce[j], coeffs_end = &columns_to_reduce[j] + 1; #endif #endif + + for (auto it = coeffs_begin; it != coeffs_end; ++it) + { + diameter_entry_t simplex = *it; set_coefficient(simplex, get_coefficient(simplex) * factor % modulus); #ifdef ASSEMBLE_REDUCTION_MATRIX @@ -734,9 +738,9 @@ void compute_pairs(std::vector<diameter_index_t>& columns_to_reduce, hash_map<in #endif #ifdef ASSEMBLE_REDUCTION_MATRIX - // replace current column of reduction_matrix (with a single diagonal 1 entry) + // replace current column of reduction_coefficients (with a single diagonal 1 entry) // by reduction_column (possibly with a different entry on the diagonal) - reduction_matrix.pop_back(); + reduction_coefficients.pop_back(); while (true) { diameter_entry_t e = pop_pivot(reduction_column, modulus); if (get_index(e) == -1) break; @@ -744,7 +748,7 @@ void compute_pairs(std::vector<diameter_index_t>& columns_to_reduce, hash_map<in set_coefficient(e, inverse * get_coefficient(e) % modulus); assert(get_coefficient(e) > 0); #endif - reduction_matrix.push_back(e); + reduction_coefficients.push_back(e); } #else #ifdef USE_COEFFICIENTS @@ -1010,7 +1014,8 @@ int main(int argc, char** argv) { if (u != v) { #ifdef PRINT_PERSISTENCE_PAIRS - std::cout << " [0," << get_diameter(e) << ")" << std::endl; + if (get_diameter(e) > 0) + std::cout << " [0," << get_diameter(e) << ")" << std::endl; #endif dset.link(u, v); } else |