Skip to content

Commit

Permalink
Merge pull request GUDHI#846 from mglisse/cubical-misc
Browse files Browse the repository at this point in the history
More cubical clean-ups
  • Loading branch information
VincentRouvreau authored Apr 17, 2023
2 parents b9425a5 + 7ad0fef commit c04374f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <vector>
#include <numeric> // for iota
#include <cstddef>
#include <stdexcept>

namespace Gudhi {

Expand Down Expand Up @@ -112,7 +113,7 @@ class Bitmap_cubical_complex : public T {
/**
* Returns number of all cubes in the complex.
**/
std::size_t num_simplices() const { return this->total_number_of_cells; }
std::size_t num_simplices() const { return this->data.size(); }

/**
* Returns a Simplex_handle to a cube that do not exist in this complex.
Expand All @@ -136,12 +137,12 @@ class Bitmap_cubical_complex : public T {
#ifdef DEBUG_TRACES
std::clog << "unsigned dimension(const Simplex_handle& sh)\n";
#endif
if (sh != null_simplex()) return this->get_dimension_of_a_cell(sh);
return -1;
GUDHI_CHECK(sh != null_simplex(), std::logic_error("Only real cells have a dimension"));
return this->get_dimension_of_a_cell(sh);
}

/**
* Return the filtration of a cell pointed by the Simplex_handle.
* Return the filtration of a cell pointed by the Simplex_handle, or +inf for `null_simplex()`.
**/
Filtration_value filtration(Simplex_handle sh) {
#ifdef DEBUG_TRACES
Expand Down Expand Up @@ -271,9 +272,6 @@ class Bitmap_cubical_complex : public T {
return std::make_pair(bdry[0], bdry[1]);
}

/**
* Class needed for compatibility with Gudhi. Not useful for other purposes.
**/
class Skeleton_simplex_range;

class Skeleton_simplex_iterator {
Expand Down Expand Up @@ -348,7 +346,7 @@ class Bitmap_cubical_complex : public T {
};

/**
* @brief Class needed for compatibility with Gudhi. Not useful for other purposes.
* @brief A range containing all the cells of dimension at most k.
**/
class Skeleton_simplex_range {
// Range over the simplices of the complex in the order of the filtration.
Expand Down Expand Up @@ -381,7 +379,7 @@ class Bitmap_cubical_complex : public T {
};

/**
* Function needed for compatibility with Gudhi. Not useful for other purposes.
* Returns a range containing all the cells of dimension at most `dimension`.
**/
Skeleton_simplex_range skeleton_simplex_range(unsigned dimension) {
#ifdef DEBUG_TRACES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Bitmap_cubical_complex_base {
/**
*Default constructor
**/
Bitmap_cubical_complex_base() : total_number_of_cells(0) {}
Bitmap_cubical_complex_base() {}
/**
* There are a few constructors of a Bitmap_cubical_complex_base class.
* First one, that takes vector<unsigned>, creates an empty bitmap of a dimension equal
Expand Down Expand Up @@ -541,7 +541,7 @@ class Bitmap_cubical_complex_base {
//****************************************************************************************************************//
//****************************************************************************************************************//

inline std::size_t number_cells() const { return this->total_number_of_cells; }
inline std::size_t number_cells() const { return this->data.size(); }

//****************************************************************************************************************//
//****************************************************************************************************************//
Expand All @@ -557,7 +557,6 @@ class Bitmap_cubical_complex_base {
std::vector<unsigned> sizes;
std::vector<unsigned> multipliers;
std::vector<T> data;
std::size_t total_number_of_cells;

template <class F> void for_each_vertex_rec(F&&f, std::size_t base, int dim);
void propagate_from_vertices_rec(int special_dim, int current_dim, std::size_t base);
Expand All @@ -574,7 +573,6 @@ class Bitmap_cubical_complex_base {
this->data = std::vector<T>(multiplier, std::numeric_limits<T>::infinity());
else
this->data = std::vector<T>(multiplier, -std::numeric_limits<T>::infinity());
this->total_number_of_cells = multiplier;
}

std::size_t compute_position_in_bitmap(const std::vector<unsigned>& counter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ class Bitmap_cubical_complex_periodic_boundary_conditions_base : public Bitmap_c
this->data = std::vector<T>(multiplier, std::numeric_limits<T>::infinity());
else
this->data = std::vector<T>(multiplier, -std::numeric_limits<T>::infinity());
this->total_number_of_cells = multiplier;
}
Bitmap_cubical_complex_periodic_boundary_conditions_base(const std::vector<unsigned>& sizes);
Bitmap_cubical_complex_periodic_boundary_conditions_base(const std::vector<unsigned>& dimensions,
Expand Down
14 changes: 7 additions & 7 deletions src/python/gudhi/cubical_complex.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ __license__ = "MIT"
np.import_array()

cdef extern from "Cubical_complex_interface.h" namespace "Gudhi":
cdef cppclass Bitmap_cubical_complex_base_interface "Gudhi::Cubical_complex::Cubical_complex_interface":
Bitmap_cubical_complex_base_interface(vector[unsigned] dimensions, vector[double] cells, bool input_top_cells) nogil except +
Bitmap_cubical_complex_base_interface(const char* perseus_file) nogil except +
cdef cppclass Bitmap_cubical_complex_interface "Gudhi::Cubical_complex::Cubical_complex_interface":
Bitmap_cubical_complex_interface(vector[unsigned] dimensions, vector[double] cells, bool input_top_cells) nogil except +
Bitmap_cubical_complex_interface(const char* perseus_file) nogil except +
int num_simplices() nogil
int dimension() nogil
vector[unsigned] shape() nogil
vector[double] data

cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi":
cdef cppclass Cubical_complex_persistence_interface "Gudhi::Persistent_cohomology_interface<Gudhi::Cubical_complex::Cubical_complex_interface>":
Cubical_complex_persistence_interface(Bitmap_cubical_complex_base_interface * st, bool persistence_dim_max) nogil
Cubical_complex_persistence_interface(Bitmap_cubical_complex_interface * st, bool persistence_dim_max) nogil
void compute_persistence(int homology_coeff_field, double min_persistence) nogil except +
vector[pair[int, pair[double, double]]] get_persistence() nogil
vector[vector[int]] cofaces_of_cubical_persistence_pairs() nogil
Expand All @@ -54,7 +54,7 @@ cdef class CubicalComplex:
computational mathematics (specially rigorous numerics) and image
analysis.
"""
cdef Bitmap_cubical_complex_base_interface * thisptr
cdef Bitmap_cubical_complex_interface * thisptr
cdef Cubical_complex_persistence_interface * pcohptr
cdef bool _built_from_vertices

Expand Down Expand Up @@ -127,11 +127,11 @@ cdef class CubicalComplex:

def _construct_from_cells(self, vector[unsigned] dimensions, vector[double] cells, bool input_top_cells):
with nogil:
self.thisptr = new Bitmap_cubical_complex_base_interface(dimensions, cells, input_top_cells)
self.thisptr = new Bitmap_cubical_complex_interface(dimensions, cells, input_top_cells)

def _construct_from_file(self, const char* filename):
with nogil:
self.thisptr = new Bitmap_cubical_complex_base_interface(filename)
self.thisptr = new Bitmap_cubical_complex_interface(filename)

def __dealloc__(self):
if self.thisptr != NULL:
Expand Down
14 changes: 7 additions & 7 deletions src/python/gudhi/periodic_cubical_complex.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ __license__ = "MIT"
np.import_array()

cdef extern from "Cubical_complex_interface.h" namespace "Gudhi":
cdef cppclass Periodic_cubical_complex_base_interface "Gudhi::Cubical_complex::Periodic_cubical_complex_interface":
Periodic_cubical_complex_base_interface(vector[unsigned] dimensions, vector[double] cells, vector[bool] periodic_dimensions, bool input_top_cells) nogil except +
Periodic_cubical_complex_base_interface(const char* perseus_file) nogil except +
cdef cppclass Periodic_cubical_complex_interface "Gudhi::Cubical_complex::Periodic_cubical_complex_interface":
Periodic_cubical_complex_interface(vector[unsigned] dimensions, vector[double] cells, vector[bool] periodic_dimensions, bool input_top_cells) nogil except +
Periodic_cubical_complex_interface(const char* perseus_file) nogil except +
int num_simplices() nogil
int dimension() nogil
vector[unsigned] shape() nogil
Expand All @@ -38,7 +38,7 @@ cdef extern from "Cubical_complex_interface.h" namespace "Gudhi":

cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi":
cdef cppclass Periodic_cubical_complex_persistence_interface "Gudhi::Persistent_cohomology_interface<Gudhi::Cubical_complex::Periodic_cubical_complex_interface>":
Periodic_cubical_complex_persistence_interface(Periodic_cubical_complex_base_interface * st, bool persistence_dim_max) nogil
Periodic_cubical_complex_persistence_interface(Periodic_cubical_complex_interface * st, bool persistence_dim_max) nogil
void compute_persistence(int homology_coeff_field, double min_persistence) nogil except +
vector[pair[int, pair[double, double]]] get_persistence() nogil
vector[vector[int]] cofaces_of_cubical_persistence_pairs() nogil
Expand All @@ -53,7 +53,7 @@ cdef class PeriodicCubicalComplex:
in computational mathematics (specially rigorous numerics) and image
analysis.
"""
cdef Periodic_cubical_complex_base_interface * thisptr
cdef Periodic_cubical_complex_interface * thisptr
cdef Periodic_cubical_complex_persistence_interface * pcohptr
cdef bool _built_from_vertices

Expand Down Expand Up @@ -137,11 +137,11 @@ cdef class PeriodicCubicalComplex:

def _construct_from_cells(self, vector[unsigned] dimensions, vector[double] cells, vector[bool] periodic_dimensions, bool input_top_cells):
with nogil:
self.thisptr = new Periodic_cubical_complex_base_interface(dimensions, cells, periodic_dimensions, input_top_cells)
self.thisptr = new Periodic_cubical_complex_interface(dimensions, cells, periodic_dimensions, input_top_cells)

def _construct_from_file(self, const char* filename):
with nogil:
self.thisptr = new Periodic_cubical_complex_base_interface(filename)
self.thisptr = new Periodic_cubical_complex_interface(filename)

def __dealloc__(self):
if self.thisptr != NULL:
Expand Down

0 comments on commit c04374f

Please sign in to comment.