From c3f3b627da09dc85616ae4a43787ea5f1fdeaf1f Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 30 Mar 2016 05:45:58 +0000 Subject: Fix cppcheck/cpplint Add TBB for parallel sort git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/bitmap@1077 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 8d4692b14e59bf7a6556bc7f69dbdc18582d6c0d --- .../include/gudhi/Bitmap_cubical_complex.h | 16 +- .../include/gudhi/Bitmap_cubical_complex/counter.h | 244 +++++++++------------ .../include/gudhi/Bitmap_cubical_complex_base.h | 40 ++-- ...cal_complex_periodic_boundary_conditions_base.h | 2 +- 4 files changed, 137 insertions(+), 165 deletions(-) (limited to 'src/Bitmap_cubical_complex/include') diff --git a/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex.h b/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex.h index adfe33b5..86bfbd56 100644 --- a/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex.h +++ b/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex.h @@ -26,6 +26,10 @@ #include #include +#ifdef GUDHI_USE_TBB +#include +#endif + #include #include // for pair<> #include // for sort @@ -129,7 +133,7 @@ class Bitmap_cubical_complex : public T { /** * Destructor of the Bitmap_cubical_complex class. **/ - virtual ~Bitmap_cubical_complex(){} + virtual ~Bitmap_cubical_complex() {} //*********************************************// // Other 'easy' functions @@ -259,7 +263,7 @@ class Bitmap_cubical_complex : public T { public: Filtration_simplex_iterator(Bitmap_cubical_complex* b) : b(b), position(0) { } - Filtration_simplex_iterator() : b(NULL) { } + Filtration_simplex_iterator() : b(NULL), position(0) { } Filtration_simplex_iterator operator++() { if (globalDbg) { @@ -537,9 +541,11 @@ void Bitmap_cubical_complex::initialize_simplex_associated_to_key() { } this->simplex_associated_to_key = std::vector(this->data.size()); std::iota(std::begin(simplex_associated_to_key), std::end(simplex_associated_to_key), 0); - std::sort(simplex_associated_to_key.begin(), - simplex_associated_to_key.end(), - is_before_in_filtration(this)); +#ifdef GUDHI_USE_TBB + tbb::parallel_sort(filtration_vect_, is_before_in_filtration(this)); +#else + std::sort(simplex_associated_to_key.begin(), simplex_associated_to_key.end(), is_before_in_filtration(this)); +#endif // we still need to deal here with a key_associated_to_simplex: for ( size_t i = 0 ; i != simplex_associated_to_key.size() ; ++i ) diff --git a/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex/counter.h b/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex/counter.h index c13d96e1..266ce051 100644 --- a/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex/counter.h +++ b/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex/counter.h @@ -20,152 +20,124 @@ * along with this program. If not, see . */ -#pragma once +#ifndef BITMAP_CUBICAL_COMPLEX_COUNTER_H_ +#define BITMAP_CUBICAL_COMPLEX_COUNTER_H_ #include #include -using namespace std; +namespace Gudhi { -namespace Gudhi -{ - -namespace Cubical_complex -{ +namespace Cubical_complex { /** -* This is an implementation of a counter being a vector of integers. -* The constructor of the class takes as an input two vectors W and V. -* It assumes that W < V coordinatewise. -* If the initial counter W is not specified, it is assumed to be vector of zeros. -* The class allows to iterate between W and V by using increment() function. -* The increment() function returns a bool value. -* The current counter reach the end counter V if the value returned by the increment function is FALSE. -* This class is needed for the implementation of a bitmapCubicalComplex. -**/ - -class counter -{ -public: - /** - * Constructor of a counter class. It takes only the parameter which is the end value of the counter. - * The default beginning value is a vector of the same length as the endd, filled-in with zeros. - **/ - counter(const std::vector& endd): begin(endd.size(),0), end(endd), current(endd.size(),0){} - //counter(std::vector< int >& endd) - //{ - // for ( size_t i = 0 ; i != endd.size() ; ++i ) - // { - // this->current.push_back(0); - // this->begin.push_back(0); - // this->end.push_back( endd[i] ); - // } - //} - - - /** - * Constructor of a counter class. It takes as the input beginn and end vector. - * It assumes that begin vector is lexicographically below the end vector. - **/ - counter(const std::vector< unsigned >& beginn , const std::vector< unsigned >& endd):begin(beginn),end(endd),current(endd.size(),0) - { - if ( beginn.size() != endd.size() ) - throw "In constructor of a counter, begin and end vectors do not have the same size. Program terminate"; - } - - /** - * Function to increment the counter. If the value returned by the function is true, - * then the incrementation process was successful. - * If the value of the function is false, that means, that the counter have reached its end-value. - **/ - bool increment() - { - size_t i = 0; - while( (i != this->end.size()) && (this->current[i] == this->end[i]) ) - { - ++i; - } - - if ( i == this->end.size() )return false; - ++this->current[i]; - for ( size_t j = 0 ; j != i ; ++j ) - { - this->current[j] = this->begin[j]; - } - return true; - } - - /** - * Function to check if we are at the end of counter. - **/ - bool isFinal() - { - for ( size_t i = 0 ; i != this->current.size() ; ++i ) - { - if ( this->current[i] == this->end[i] )return true; - } - return false; - } - - /** - * Function required in the implementation of bitmapCubicalComplexWPeriodicBoundaryCondition. - * Its aim is to find an counter corresponding to the element the following - * boundary element is identified with when periodic boundary conditions are imposed. - **/ - std::vector< unsigned > find_opposite( const std::vector< bool >& directionsForPeriodicBCond ) - { - std::vector< unsigned > result; - for ( size_t i = 0 ; i != this->current.size() ; ++i ) - { - if ( (this->current[i] == this->end[i]) && (directionsForPeriodicBCond[i] == true) ) - { - result.push_back( this->begin[i] ); - } - else - { - result.push_back( this->current[i] ); - } - } - return result; + * This is an implementation of a counter being a vector of integers. + * The constructor of the class takes as an input two vectors W and V. + * It assumes that W < V coordinatewise. + * If the initial counter W is not specified, it is assumed to be vector of zeros. + * The class allows to iterate between W and V by using increment() function. + * The increment() function returns a bool value. + * The current counter reach the end counter V if the value returned by the increment function is FALSE. + * This class is needed for the implementation of a bitmapCubicalComplex. + **/ + +class counter { + public: + /** + * Constructor of a counter class. It takes only the parameter which is the end value of the counter. + * The default beginning value is a vector of the same length as the endd, filled-in with zeros. + **/ + counter(const std::vector& endd) : begin(endd.size(), 0), end(endd), current(endd.size(), 0) { } + + /** + * Constructor of a counter class. It takes as the input beginn and end vector. + * It assumes that begin vector is lexicographically below the end vector. + **/ + counter(const std::vector< unsigned >& beginn, const std::vector< unsigned >& endd) : begin(beginn), end(endd), current(endd.size(), 0) { + if (beginn.size() != endd.size()) + throw "In constructor of a counter, begin and end vectors do not have the same size. Program terminate"; + } + + /** + * Function to increment the counter. If the value returned by the function is true, + * then the incrementation process was successful. + * If the value of the function is false, that means, that the counter have reached its end-value. + **/ + bool increment() { + size_t i = 0; + while ((i != this->end.size()) && (this->current[i] == this->end[i])) { + ++i; } - /** - * Function checking at which positions the current value of a counter is the final value of the counter. - **/ - std::vector< bool > directions_of_finals() - { - std::vector< bool > result; - for ( size_t i = 0 ; i != this->current.size() ; ++i ) - { - if ( this->current[i] == this->end[i] ) - { - result.push_back( true ); - } - else - { - result.push_back( false ); - } - } - return result; + if (i == this->end.size())return false; + ++this->current[i]; + for (size_t j = 0; j != i; ++j) { + this->current[j] = this->begin[j]; } - - /** - * Function to write counter to the stream. - **/ - friend std::ostream& operator<<(std::ostream& out , const counter& c ) - { - //cerr << "c.current.size() : " << c.current.size() << endl; - for ( size_t i = 0 ; i != c.current.size() ; ++i ) - { - out << c.current[i] << " "; - } - return out; + return true; + } + + /** + * Function to check if we are at the end of counter. + **/ + bool isFinal() { + for (size_t i = 0; i != this->current.size(); ++i) { + if (this->current[i] == this->end[i])return true; + } + return false; + } + + /** + * Function required in the implementation of bitmapCubicalComplexWPeriodicBoundaryCondition. + * Its aim is to find an counter corresponding to the element the following + * boundary element is identified with when periodic boundary conditions are imposed. + **/ + std::vector< unsigned > find_opposite(const std::vector< bool >& directionsForPeriodicBCond) { + std::vector< unsigned > result; + for (size_t i = 0; i != this->current.size(); ++i) { + if ((this->current[i] == this->end[i]) && (directionsForPeriodicBCond[i] == true)) { + result.push_back(this->begin[i]); + } else { + result.push_back(this->current[i]); + } + } + return result; + } + + /** + * Function checking at which positions the current value of a counter is the final value of the counter. + **/ + std::vector< bool > directions_of_finals() { + std::vector< bool > result; + for (size_t i = 0; i != this->current.size(); ++i) { + if (this->current[i] == this->end[i]) { + result.push_back(true); + } else { + result.push_back(false); + } } -private: - std::vector< unsigned > begin; - std::vector< unsigned > end; - std::vector< unsigned > current; + return result; + } + + /** + * Function to write counter to the stream. + **/ + friend std::ostream& operator<<(std::ostream& out, const counter& c) { + // std::cerr << "c.current.size() : " << c.current.size() << endl; + for (size_t i = 0; i != c.current.size(); ++i) { + out << c.current[i] << " "; + } + return out; + } + + private: + std::vector< unsigned > begin; + std::vector< unsigned > end; + std::vector< unsigned > current; }; -} -} \ No newline at end of file +} // namespace Cubical_complex + +} // namespace Gudhi + +#endif // BITMAP_CUBICAL_COMPLEX_COUNTER_H_ diff --git a/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_base.h b/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_base.h index 62776019..d858f3c5 100644 --- a/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_base.h +++ b/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_base.h @@ -204,7 +204,7 @@ class Bitmap_cubical_complex_base { } All_cells_iterator operator++() { - //first find first element of the counter that can be increased: + // first find first element of the counter that can be increased: ++this->counter; return *this; } @@ -317,14 +317,13 @@ class Bitmap_cubical_complex_base { **/ class Top_dimensional_cells_iterator : std::iterator< std::input_iterator_tag, T > { public: - Top_dimensional_cells_iterator(Bitmap_cubical_complex_base& b) : b(b) { this->counter = std::vector(b.dimension()); - //std::fill( this->counter.begin() , this->counter.end() , 0 ); + // std::fill( this->counter.begin() , this->counter.end() , 0 ); } Top_dimensional_cells_iterator operator++() { - //first find first element of the counter that can be increased: + // first find first element of the counter that can be increased: size_t dim = 0; while ((dim != this->b.dimension()) && (this->counter[dim] == this->b.sizes[dim] - 1))++dim; @@ -499,7 +498,7 @@ void Bitmap_cubical_complex_base::put_data_to_bins(size_t number_of_bins) { std::pair< T, T > min_max = this->min_max_filtration(); T dx = (min_max.second - min_max.first) / (T) number_of_bins; - //now put the data into the appropriate bins: + // now put the data into the appropriate bins: for (size_t i = 0; i != this->data.size(); ++i) { if (bdg) { std::cerr << "Before binning : " << this->data[i] << std::endl; @@ -518,7 +517,7 @@ void Bitmap_cubical_complex_base::put_data_to_bins(T diameter_of_bin) { std::pair< T, T > min_max = this->min_max_filtration(); size_t number_of_bins = (min_max.second - min_max.first) / diameter_of_bin; - //now put the data into the appropriate bins: + // now put the data into the appropriate bins: for (size_t i = 0; i != this->data.size(); ++i) { if (bdg) { std::cerr << "Before binning : " << this->data[i] << std::endl; @@ -542,7 +541,7 @@ std::pair< T, T > Bitmap_cubical_complex_base::min_max_filtration() { } template -ostream& operator<<(ostream & out, const Bitmap_cubical_complex_base& b) { +std::ostream& operator<<(std::ostream & out, const Bitmap_cubical_complex_base& b) { for (typename Bitmap_cubical_complex_base::all_cells_const_iterator it = b.all_cells_const_begin(); it != b.all_cells_const_end(); ++it) { out << *it << " "; @@ -565,16 +564,13 @@ void Bitmap_cubical_complex_base::setup_bitmap_based_on_top_dimensional_cells number_of_top_dimensional_elements *= sizes_in_following_directions[i]; } if (number_of_top_dimensional_elements != top_dimensional_cells.size()) { - std::cerr << - "Error in constructor\ - Bitmap_cubical_complex_base\ - ( std::vector sizes_in_following_directions , std::vector top_dimensional_cells ).\ - Number of top dimensional elements that follow from sizes_in_following_directions vector is different\ - than the size of top_dimensional_cells vector." << std::endl; - throw ("Error in constructor Bitmap_cubical_complex_base( std::vector sizes_in_following_directions,\ - std::vector top_dimensional_cells )\ - . Number of top dimensional elements that follow from sizes_in_following_directions vector is different than the\ - size of top_dimensional_cells vector."); + std::cerr << "Error in constructor Bitmap_cubical_complex_base ( std::vector sizes_in_following_directions" + << ", std::vector top_dimensional_cells ). Number of top dimensional elements that follow from " + << "sizes_in_following_directions vector is different than the size of top_dimensional_cells vector." + << std::endl; + throw ("Error in constructor Bitmap_cubical_complex_base( std::vector sizes_in_following_directions," + "std::vector top_dimensional_cells ). Number of top dimensional elements that follow from " + "sizes_in_following_directions vector is different than the size of top_dimensional_cells vector."); } Bitmap_cubical_complex_base::Top_dimensional_cells_iterator it(*this); @@ -610,7 +606,6 @@ void Bitmap_cubical_complex_base::read_perseus_style_file(const char* perseus for (size_t i = 0; i != dimensionOfData; ++i) { unsigned size_in_this_dimension; inFiltration >> size_in_this_dimension; - size_in_this_dimension = size_in_this_dimension; sizes.push_back(size_in_this_dimension); if (dbg) { std::cerr << "size_in_this_dimension : " << size_in_this_dimension << std::endl; @@ -738,8 +733,7 @@ template void Bitmap_cubical_complex_base::impose_lower_star_filtration() { bool dbg = false; - //this vector will be used to check which elements have already been taken care of - //in imposing lower star filtration: + // this vector will be used to check which elements have already been taken care of in imposing lower star filtration std::vector is_this_cell_considered(this->data.size(), false); size_t size_to_reserve = 1; @@ -749,8 +743,8 @@ void Bitmap_cubical_complex_base::impose_lower_star_filtration() { std::vector indices_to_consider; indices_to_consider.reserve(size_to_reserve); - //we assume here that we already have a filtration on the top dimensional cells and - //we have to extend it to lower ones. + // we assume here that we already have a filtration on the top dimensional cells and + // we have to extend it to lower ones. typename Bitmap_cubical_complex_base::Top_dimensional_cells_iterator it(*this); for (it = this->top_dimensional_cells_iterator_begin(); it != this->top_dimensional_cells_iterator_end(); ++it) { indices_to_consider.push_back(it.compute_index_in_bitmap()); @@ -799,7 +793,7 @@ bool compareFirstElementsOfTuples(const std::pair< std::pair< T, size_t >, char if (first.first.first > second.first.first) { return false; } - //in this case first.first.first == second.first.first, so we need to compare dimensions + // in this case first.first.first == second.first.first, so we need to compare dimensions return first.second < second.second; } } diff --git a/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h b/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h index 2c0d77fe..8afa342e 100644 --- a/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h +++ b/src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h @@ -84,7 +84,7 @@ class Bitmap_cubical_complex_periodic_boundary_conditions_base : public Bitmap_c /** * Destructor of the Bitmap_cubical_complex_periodic_boundary_conditions_base class. **/ - virtual ~Bitmap_cubical_complex_periodic_boundary_conditions_base(){} + virtual ~Bitmap_cubical_complex_periodic_boundary_conditions_base() {} // overwritten methods co compute boundary and coboundary /** -- cgit v1.2.3