From 1884df27964e344ac0004964c633ba01d4a6ae29 Mon Sep 17 00:00:00 2001 From: pdlotko Date: Sun, 27 Dec 2015 09:25:07 +0000 Subject: COrrestions suggested by Marc just before Chrismas. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/bitmap@948 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b5391c6584d8042646fea5ca17e250fcfc3dd85f --- .../include/gudhi/Bitmap_cubical_complex_base.h | 121 +++++++++------------ 1 file changed, 51 insertions(+), 70 deletions(-) (limited to 'src/Bitmap_cubical_complex/include/gudhi/Bitmap_cubical_complex_base.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 fdc8511c..54d60325 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 @@ -183,7 +183,7 @@ 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++() { @@ -327,7 +327,8 @@ protected: std::vector compute_counter_for_given_cell( size_t cell )const { - std::vector counter; + std::vector counter; + counter.reserve( this->sizes.size() ); for ( size_t dim = this->sizes.size() ; dim != 0 ; --dim ) { counter.push_back(cell/this->multipliers[dim-1]); @@ -380,11 +381,11 @@ Bitmap_cubical_complex_base::Bitmap_cubical_complex_base cerr << "Error in constructor\ Bitmap_cubical_complex_base\ - ( std::vector sizes_in_following_directions , std::vector top_dimensional_cells ).\ + ( 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." << endl; throw("Error in constructor Bitmap_cubical_complex_base( std::vector sizes_in_following_directions,\ - std::vector top_dimensional_cells )\ + 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."); } @@ -411,7 +412,8 @@ Bitmap_cubical_complex_base::Bitmap_cubical_complex_base( const char* perseus if (dbg){cerr << "dimensionOfData : " << dimensionOfData << endl;} - std::vector sizes; + std::vector sizes; + sizes.reserve( dimensionOfData ); for ( size_t i = 0 ; i != dimensionOfData ; ++i ) { unsigned size_in_this_dimension; @@ -449,17 +451,21 @@ Bitmap_cubical_complex_base::Bitmap_cubical_complex_base( const char* perseus template std::vector< size_t > Bitmap_cubical_complex_base::get_boundary_of_a_cell( size_t cell )const { - std::vector< size_t > boundary_elements; + std::vector< size_t > boundary_elements; + + //Speed traded of for memory. Check if it is better in practice. + boundary_elements.reserve( this->dimension()*2 ); + size_t cell1 = cell; for ( size_t i = this->multipliers.size() ; i != 0 ; --i ) { - unsigned position = cell1/multipliers[i-1]; + unsigned position = cell1/this->multipliers[i-1]; if ( position%2 == 1 ) { - boundary_elements.push_back( cell - multipliers[ i-1 ] ); - boundary_elements.push_back( cell + multipliers[ i-1 ] ); + boundary_elements.push_back( cell - this->multipliers[ i-1 ] ); + boundary_elements.push_back( cell + this->multipliers[ i-1 ] ); } - cell1 = cell1%multipliers[i-1]; + cell1 = cell1%this->multipliers[i-1]; } return boundary_elements; } @@ -470,84 +476,48 @@ std::vector< size_t > Bitmap_cubical_complex_base::get_boundary_of_a_cell( si template std::vector< size_t > Bitmap_cubical_complex_base::get_coboundary_of_a_cell( size_t cell )const { - bool bdg = false; //first of all, we need to take the list of coordinates in which the cell has nonzero length. //We do it by using modified version to compute dimension of a cell: - std::vector< unsigned > dimensions_in_which_cell_has_zero_length; + std::vector< unsigned > dimensions_in_which_cell_has_zero_length; + + //Speed traded of for memory. Check if it is better in practice. + dimensions_in_which_cell_has_zero_length.reserve( this->dimension()*2 ); + unsigned dimension = 0; size_t cell1 = cell; for ( size_t i = this->multipliers.size() ; i != 0 ; --i ) { - unsigned position = cell1/multipliers[i-1]; + unsigned position = cell1/this->multipliers[i-1]; if ( position%2 == 0 ) { dimensions_in_which_cell_has_zero_length.push_back(i-1); dimension++; } - cell1 = cell1%multipliers[i-1]; + cell1 = cell1%this->multipliers[i-1]; } std::vector counter = this->compute_counter_for_given_cell( cell ); - //reverse(counter.begin() , counter.end()); + std::vector< size_t > coboundary_elements; + + //Speed traded of for memory. Check if it is better in practice. + coboundary_elements.reserve ( dimensions_in_which_cell_has_zero_length.size()*2 ); - if (bdg) - { - cerr << "dimensions_in_which_cell_has_zero_length : \n"; - for ( size_t i = 0 ; i != dimensions_in_which_cell_has_zero_length.size() ; ++i ) - { - cerr << dimensions_in_which_cell_has_zero_length[i] << endl; - } - cerr << "\n counter : " << endl; - for ( size_t i = 0 ; i != counter.size() ; ++i ) - { - cerr << counter[i] << endl; - } - getchar(); - } - - std::vector< size_t > coboundary_elements; if ( dimensions_in_which_cell_has_zero_length.size() == 0 )return coboundary_elements; for ( size_t i = 0 ; i != dimensions_in_which_cell_has_zero_length.size() ; ++i ) { - if ( bdg ) - { - cerr << "Dimension : " << i << endl; - if (counter[dimensions_in_which_cell_has_zero_length[i]] == 0) - { - cerr << "In dimension : " << i - << " we cannot substract, since we will jump out of a Bitmap_cubical_complex_base \n"; - } - if ( counter[dimensions_in_which_cell_has_zero_length[i]] - == - 2*this->sizes[dimensions_in_which_cell_has_zero_length[i]] ) - { - cerr << "In dimension : " << i - << " we cannot substract, since we will jump out of a Bitmap_cubical_complex_base \n"; - } - } - - - if ( (cell > multipliers[dimensions_in_which_cell_has_zero_length[i]]) + if ( (cell > this->multipliers[dimensions_in_which_cell_has_zero_length[i]]) && (counter[dimensions_in_which_cell_has_zero_length[i]] != 0) ) - //if ( counter[dimensions_in_which_cell_has_zero_length[i]] != 0 ) { - if ( bdg ) - { - cerr << "Subtracting : " << cell - multipliers[dimensions_in_which_cell_has_zero_length[i]] << endl; - } - coboundary_elements.push_back( cell - multipliers[dimensions_in_which_cell_has_zero_length[i]] ); + coboundary_elements.push_back( cell - this->multipliers[dimensions_in_which_cell_has_zero_length[i]] ); } if ( - (cell + multipliers[dimensions_in_which_cell_has_zero_length[i]] < this->data.size()) && + (cell + this->multipliers[dimensions_in_which_cell_has_zero_length[i]] < this->data.size()) && (counter[dimensions_in_which_cell_has_zero_length[i]] != 2*this->sizes[dimensions_in_which_cell_has_zero_length[i]]) ) - //if ( counter[dimensions_in_which_cell_has_zero_length[i]] != - //2*this->sizes[dimensions_in_which_cell_has_zero_length[i]] ) { - coboundary_elements.push_back( cell + multipliers[dimensions_in_which_cell_has_zero_length[i]] ); - if ( bdg )cerr << "Adding : " << cell + multipliers[dimensions_in_which_cell_has_zero_length[i]] << endl; + coboundary_elements.push_back( cell + this->multipliers[dimensions_in_which_cell_has_zero_length[i]] ); } } return coboundary_elements; @@ -566,12 +536,12 @@ unsigned Bitmap_cubical_complex_base::get_dimension_of_a_cell( size_t cell )c unsigned dimension = 0; for ( size_t i = this->multipliers.size() ; i != 0 ; --i ) { - unsigned position = cell/multipliers[i-1]; + unsigned position = cell/this->multipliers[i-1]; if (dbg)cerr << "i-1 :" << i-1 << endl; if (dbg)cerr << "cell : " << cell << endl; if (dbg)cerr << "position : " << position << endl; - if (dbg)cerr << "multipliers["<multipliers[i-1]; } return dimension; } @@ -599,8 +569,15 @@ void Bitmap_cubical_complex_base::impose_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 ); - - std::vector indices_to_consider; + + size_t size_to_reserve = 1; + for ( size_t i = 0 ; i != this->multipliers.size() ; ++i ) + { + size_to_reserve *= (size_t)((this->multipliers[i]-1)/2); + } + + 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. typename Bitmap_cubical_complex_base::Top_dimensional_cells_iterator it(*this); @@ -672,12 +649,17 @@ generate_vector_of_shifts_for_bitmaps_with_periodic_boundary_conditions if ( this->sizes.size() != directions_for_periodic_b_cond.size() ) throw "directions_for_periodic_b_cond vector size is different from the size of the bitmap. Program terminate \n"; - std::vector sizes( this->sizes.size() ); - for ( size_t i = 0 ; i != this->sizes.size() ; ++i )sizes[i] = 2*this->sizes[i]; + std::vector sizes; + sizes.reserve( this->sizes.size() ); + for ( size_t i = 0 ; i != this->sizes.size() ; ++i ) + { + sizes.push_back(2*this->sizes[i]); + } counter c( sizes ); - std::vector< size_t > result; + std::vector< size_t > result; + result.reserve( this->data.size() ); for ( size_t i = 0 ; i != this->data.size() ; ++i ) { @@ -685,7 +667,6 @@ generate_vector_of_shifts_for_bitmaps_with_periodic_boundary_conditions if ( !c.isFinal() ) { position = i; - //result.push_back( i ); } else { -- cgit v1.2.3