From f843ef3f8e4ab4ce94a28ded6d8cafd37f2b2311 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 23 Nov 2016 11:49:15 +0000 Subject: Add tangential complex git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@1773 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b47285aafaa430c883c8fe5432ac667d6cedaf37 --- src/cython/include/Tangential_complex_interface.h | 220 ++++++++++++++++++++++ 1 file changed, 220 insertions(+) create mode 100644 src/cython/include/Tangential_complex_interface.h (limited to 'src/cython/include/Tangential_complex_interface.h') diff --git a/src/cython/include/Tangential_complex_interface.h b/src/cython/include/Tangential_complex_interface.h new file mode 100644 index 00000000..645aad72 --- /dev/null +++ b/src/cython/include/Tangential_complex_interface.h @@ -0,0 +1,220 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Vincent Rouvreau + * + * Copyright (C) 2016 INRIA + * + * 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. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef TANGENTIAL_COMPLEX_INTERFACE_H +#define TANGENTIAL_COMPLEX_INTERFACE_H + +#include +#include +#include +#include + +#include "Persistent_cohomology_interface.h" + +#include +#include // std::pair +#include + +namespace Gudhi { + +namespace tangential_complex { + +class Tangential_complex_interface { + using Dynamic_kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >; + using Point_d = Dynamic_kernel::Point_d; + typedef typename Simplex_tree<>::Simplex_handle Simplex_handle; + typedef typename std::pair Insertion_result; + using Simplex = std::vector; + using Filtered_complex = std::pair; + using Complex_tree = std::vector; + using TC = Tangential_complex; + + public: + Tangential_complex_interface(std::vector>&points, double max_alpha_square) + : pcoh_(nullptr) { + Dynamic_kernel k; + unsigned intrisic_dim = 0; + if (points.size() > 0) + intrisic_dim = points[0].size(); + + tangential_complex_ = new TC(points, intrisic_dim, k); + tangential_complex_->create_complex(simplex_tree_, max_alpha_square); + simplex_tree_.initialize_filtration(); + } + + Tangential_complex_interface(std::string off_file_name, double max_alpha_square, bool from_file = true) + : pcoh_(nullptr) { + Gudhi::Points_off_reader off_reader(off_file_name); + Dynamic_kernel k; + unsigned intrisic_dim = 0; + std::vector points = off_reader.get_point_cloud(); + if (points.size() > 0) + intrisic_dim = points[0].size(); + + tangential_complex_ = new TC(points, intrisic_dim, k); + tangential_complex_->create_complex(simplex_tree_, max_alpha_square); + simplex_tree_.initialize_filtration(); + } + + bool find_simplex(const Simplex& vh) { + return (simplex_tree_.find(vh) != simplex_tree_.null_simplex()); + } + + bool insert_simplex_and_subfaces(const Simplex& complex, Filtration_value filtration = 0) { + Insertion_result result = simplex_tree_.insert_simplex_and_subfaces(complex, filtration); + return (result.second); + } + + Filtration_value simplex_filtration(const Simplex& complex) { + return simplex_tree_.filtration(simplex_tree_.find(complex)); + } + + void remove_maximal_simplex(const Simplex& complex) { + return simplex_tree_.remove_maximal_simplex(simplex_tree_.find(complex)); + } + + Complex_tree get_filtered_tree() { + Complex_tree filtered_tree; + for (auto f_simplex : simplex_tree_.filtration_simplex_range()) { + Simplex simplex; + for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) { + simplex.insert(simplex.begin(), vertex); + } + filtered_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex))); + } + return filtered_tree; + + } + + Complex_tree get_skeleton_tree(int dimension) { + Complex_tree skeleton_tree; + for (auto f_simplex : simplex_tree_.skeleton_simplex_range(dimension)) { + Simplex simplex; + for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) { + simplex.insert(simplex.begin(), vertex); + } + skeleton_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex))); + } + return skeleton_tree; + } + + Complex_tree get_star_tree(const Simplex& complex) { + Complex_tree star_tree; + for (auto f_simplex : simplex_tree_.star_simplex_range(simplex_tree_.find(complex))) { + Simplex simplex; + for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) { + simplex.insert(simplex.begin(), vertex); + } + star_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex))); + } + return star_tree; + } + + Complex_tree get_coface_tree(const Simplex& complex, int dimension) { + Complex_tree coface_tree; + for (auto f_simplex : simplex_tree_.cofaces_simplex_range(simplex_tree_.find(complex), dimension)) { + Simplex simplex; + for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) { + simplex.insert(simplex.begin(), vertex); + } + coface_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex))); + } + return coface_tree; + } + + // Specific to Witness complex because no inheritance + Filtration_value filtration() const { + return simplex_tree_.filtration(); + } + + void set_filtration(Filtration_value fil) { + simplex_tree_.set_filtration(fil); + } + + void initialize_filtration() { + simplex_tree_.initialize_filtration(); + } + + size_t num_vertices() const { + return simplex_tree_.num_vertices(); + } + + size_t num_simplices() { + return simplex_tree_.num_simplices(); + } + + int dimension() const { + return simplex_tree_.dimension(); + } + + void set_dimension(int dimension) { + simplex_tree_.set_dimension(dimension); + } + + std::vector get_point(int vh) { + std::vector vd; + try { + Point_d ph = tangential_complex_->get_point(vh); + for (auto coord = ph.cartesian_begin(); coord < ph.cartesian_end(); coord++) + vd.push_back(*coord); + } catch (std::out_of_range outofrange) { + // std::out_of_range is thrown in case not found. Other exceptions must be re-thrown + } + return vd; + } + + std::vector>> get_persistence(int homology_coeff_field, double min_persistence) { + if (pcoh_ != nullptr) { + delete pcoh_; + } + pcoh_ = new Persistent_cohomology_interface>(&simplex_tree_); + return pcoh_->get_persistence(homology_coeff_field, min_persistence); + } + + std::vector get_betti_numbers() const { + if (pcoh_ != nullptr) { + return pcoh_->betti_numbers(); + } + std::vector betti_numbers; + return betti_numbers; + } + + std::vector get_persistent_betti_numbers(Filtration_value from, Filtration_value to) const { + if (pcoh_ != nullptr) { + return pcoh_->persistent_betti_numbers(from, to); + } + std::vector persistent_betti_numbers; + return persistent_betti_numbers; + } + + private: + Simplex_tree<> simplex_tree_; + Persistent_cohomology_interface>* pcoh_; + TC* tangential_complex_; +}; + +} // namespace tangential_complex + +} // namespace Gudhi + +#endif // TANGENTIAL_COMPLEX_INTERFACE_H + -- cgit v1.2.3 From 844f8b075d9143466040c4d46a181e4a0fcbbda4 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 28 Nov 2016 16:55:08 +0000 Subject: Fix issues git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@1795 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: c4763818a5845eb884b245eca8c78ed60c1a28ca --- src/cython/cython/alpha_complex.pyx | 26 +---- src/cython/doc/index.rst | 5 + src/cython/doc/tangential_complex_sum.rst | 2 +- src/cython/include/Alpha_complex_interface.h | 128 +--------------------- src/cython/include/Simplex_tree_interface.h | 8 +- src/cython/include/Tangential_complex_interface.h | 1 + 6 files changed, 18 insertions(+), 152 deletions(-) (limited to 'src/cython/include/Tangential_complex_interface.h') diff --git a/src/cython/cython/alpha_complex.pyx b/src/cython/cython/alpha_complex.pyx index 9bf7b257..ed518c38 100644 --- a/src/cython/cython/alpha_complex.pyx +++ b/src/cython/cython/alpha_complex.pyx @@ -37,27 +37,7 @@ cdef extern from "Alpha_complex_interface.h" namespace "Gudhi": Alpha_complex_interface(vector[vector[double]] points) # bool from_file is a workaround for cython to find the correct signature Alpha_complex_interface(string off_file, bool from_file) - double filtration() - double simplex_filtration(vector[int] simplex) - void set_filtration(double filtration) - void initialize_filtration() - int num_vertices() - int num_simplices() - void set_dimension(int dimension) - int dimension() - bint find_simplex(vector[int] simplex) - bint insert_simplex_and_subfaces(vector[int] simplex, - double filtration) - vector[pair[vector[int], double]] get_filtered_tree() - vector[pair[vector[int], double]] get_skeleton_tree(int dimension) - vector[pair[vector[int], double]] get_star_tree(vector[int] simplex) - vector[pair[vector[int], double]] get_coface_tree(vector[int] simplex, - int dimension) - void remove_maximal_simplex(vector[int] simplex) vector[double] get_point(int vertex) - vector[pair[int, pair[double, double]]] get_persistence(int homology_coeff_field, double min_persistence) - vector[int] get_betti_numbers() - vector[int] get_persistent_betti_numbers(double from_value, double to_value) void create_simplex_tree(Simplex_tree_interface_full_featured simplex_tree, double max_alpha_square) # AlphaComplex python interface @@ -119,7 +99,7 @@ cdef class AlphaComplex: """This function returns the point corresponding to a given vertex. :param vertex: The vertex. - :type vertex: int. + :type vertex: int :returns: list of float -- the point. """ cdef vector[double] point = self.thisptr.get_point(vertex) @@ -130,9 +110,9 @@ cdef class AlphaComplex: Triangulation. :param simplex_tree: The simplex tree to create (must be empty) - :type simplex tree: gudhi.SimplexTree. + :type simplex_tree: SimplexTree :param max_alpha_square: The maximum alpha square threshold the simplices shall not exceed. Default is set to infinity. - :type max_alpha_square: float. + :type max_alpha_square: float """ self.thisptr.create_simplex_tree(deref(simplex_tree.thisptr), max_alpha_square) \ No newline at end of file diff --git a/src/cython/doc/index.rst b/src/cython/doc/index.rst index 89e09d70..91e31ff6 100644 --- a/src/cython/doc/index.rst +++ b/src/cython/doc/index.rst @@ -48,6 +48,11 @@ Simplex tree .. include:: simplex_tree_sum.rst +Tangential complex +================== + +.. include:: tangential_complex_sum.rst + Witness complex =============== diff --git a/src/cython/doc/tangential_complex_sum.rst b/src/cython/doc/tangential_complex_sum.rst index a2c0be0e..4e358a7b 100644 --- a/src/cython/doc/tangential_complex_sum.rst +++ b/src/cython/doc/tangential_complex_sum.rst @@ -12,5 +12,5 @@ | | extrinsic dimension :math:`d` and exponentially on the intrinsic | | | dimension :math:`k`. | +-------------------------------------------+----------------------------------------------------------------------+ -| :doc:`tangential_complex_user` | :doc:`tangential_complex_ref` | +| :doc:`tangential_complex_user` | :doc:`tangential_complex_ref` | +-------------------------------------------+----------------------------------------------------------------------+ diff --git a/src/cython/include/Alpha_complex_interface.h b/src/cython/include/Alpha_complex_interface.h index 07f5b5b4..15384206 100644 --- a/src/cython/include/Alpha_complex_interface.h +++ b/src/cython/include/Alpha_complex_interface.h @@ -27,7 +27,6 @@ #include #include -#include "Persistent_cohomology_interface.h" #include "Simplex_tree_interface.h" #include @@ -50,111 +49,14 @@ class Alpha_complex_interface { typedef typename Simplex_tree<>::Simplex_key Simplex_key; public: - Alpha_complex_interface(std::vector>&points) - : pcoh_(nullptr) { + Alpha_complex_interface(std::vector>&points) { alpha_complex_ = new Alpha_complex(points); } - Alpha_complex_interface(std::string off_file_name, bool from_file = true) - : pcoh_(nullptr) { + Alpha_complex_interface(std::string off_file_name, bool from_file = true) { alpha_complex_ = new Alpha_complex(off_file_name); } - bool find_simplex(const Simplex& vh) { - return (simplex_tree_.find(vh) != simplex_tree_.null_simplex()); - } - - bool insert_simplex_and_subfaces(const Simplex& complex, Filtration_value filtration = 0) { - Insertion_result result = simplex_tree_.insert_simplex_and_subfaces(complex, filtration); - return (result.second); - } - - Filtration_value simplex_filtration(const Simplex& complex) { - return simplex_tree_.filtration(simplex_tree_.find(complex)); - } - - void remove_maximal_simplex(const Simplex& complex) { - return simplex_tree_.remove_maximal_simplex(simplex_tree_.find(complex)); - } - - Complex_tree get_filtered_tree() { - Complex_tree filtered_tree; - for (auto f_simplex : simplex_tree_.filtration_simplex_range()) { - Simplex simplex; - for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) { - simplex.insert(simplex.begin(), vertex); - } - filtered_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex))); - } - return filtered_tree; - - } - - Complex_tree get_skeleton_tree(int dimension) { - Complex_tree skeleton_tree; - for (auto f_simplex : simplex_tree_.skeleton_simplex_range(dimension)) { - Simplex simplex; - for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) { - simplex.insert(simplex.begin(), vertex); - } - skeleton_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex))); - } - return skeleton_tree; - } - - Complex_tree get_star_tree(const Simplex& complex) { - Complex_tree star_tree; - for (auto f_simplex : simplex_tree_.star_simplex_range(simplex_tree_.find(complex))) { - Simplex simplex; - for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) { - simplex.insert(simplex.begin(), vertex); - } - star_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex))); - } - return star_tree; - } - - Complex_tree get_coface_tree(const Simplex& complex, int dimension) { - Complex_tree coface_tree; - for (auto f_simplex : simplex_tree_.cofaces_simplex_range(simplex_tree_.find(complex), dimension)) { - Simplex simplex; - for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) { - simplex.insert(simplex.begin(), vertex); - } - coface_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex))); - } - return coface_tree; - } - - // Specific to Witness complex because no inheritance - Filtration_value filtration() const { - return simplex_tree_.filtration(); - } - - void set_filtration(Filtration_value fil) { - simplex_tree_.set_filtration(fil); - } - - void initialize_filtration() { - simplex_tree_.initialize_filtration(); - } - - size_t num_vertices() const { - return simplex_tree_.num_vertices(); - } - - size_t num_simplices() { - return simplex_tree_.num_simplices(); - } - - int dimension() const { - return simplex_tree_.dimension(); - } - - void set_dimension(int dimension) { - simplex_tree_.set_dimension(dimension); - } - std::vector get_point(int vh) { std::vector vd; try { @@ -167,38 +69,12 @@ class Alpha_complex_interface { return vd; } - std::vector>> get_persistence(int homology_coeff_field, double min_persistence) { - if (pcoh_ != nullptr) { - delete pcoh_; - } - pcoh_ = new Persistent_cohomology_interface>(&simplex_tree_); - return pcoh_->get_persistence(homology_coeff_field, min_persistence); - } - - std::vector get_betti_numbers() const { - if (pcoh_ != nullptr) { - return pcoh_->betti_numbers(); - } - std::vector betti_numbers; - return betti_numbers; - } - - std::vector get_persistent_betti_numbers(Filtration_value from, Filtration_value to) const { - if (pcoh_ != nullptr) { - return pcoh_->persistent_betti_numbers(from, to); - } - std::vector persistent_betti_numbers; - return persistent_betti_numbers; - } - void create_simplex_tree(Simplex_tree_interface<>& simplex_tree, double max_alpha_square) { alpha_complex_->create_complex(simplex_tree, max_alpha_square); simplex_tree.initialize_filtration(); } private: - Simplex_tree<> simplex_tree_; - Persistent_cohomology_interface>* pcoh_; Alpha_complex* alpha_complex_; }; diff --git a/src/cython/include/Simplex_tree_interface.h b/src/cython/include/Simplex_tree_interface.h index 06ec6d40..8e9dd966 100644 --- a/src/cython/include/Simplex_tree_interface.h +++ b/src/cython/include/Simplex_tree_interface.h @@ -28,6 +28,8 @@ #include #include +#include "Persistent_cohomology_interface.h" + #include #include // std::pair #include @@ -69,10 +71,8 @@ class Simplex_tree_interface : public Simplex_tree { for (auto f_simplex : Simplex_tree::filtration_simplex_range()) { Simplex simplex; for (auto vertex : Simplex_tree::simplex_vertex_range(f_simplex)) { - std::cout << " " << vertex; simplex.insert(simplex.begin(), vertex); } - std::cout << std::endl; filtered_tree.push_back(std::make_pair(simplex, Simplex_tree::filtration(f_simplex))); } return filtered_tree; @@ -137,6 +137,10 @@ class Simplex_tree_interface : public Simplex_tree { } } + void create_persistence(Gudhi::Persistent_cohomology_interface>* pcoh) { + pcoh = new Gudhi::Persistent_cohomology_interface>(*this); + } + }; struct Simplex_tree_options_mini : Simplex_tree_options_full_featured { diff --git a/src/cython/include/Tangential_complex_interface.h b/src/cython/include/Tangential_complex_interface.h index 645aad72..e9750e85 100644 --- a/src/cython/include/Tangential_complex_interface.h +++ b/src/cython/include/Tangential_complex_interface.h @@ -29,6 +29,7 @@ #include #include "Persistent_cohomology_interface.h" +#include "Simplex_tree_interface.h" #include #include // std::pair -- cgit v1.2.3 From 2976ab407d564b46173aeedf5c1e876b5cfc5a97 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 28 Nov 2016 21:47:57 +0000 Subject: Cythonize Tangential git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@1796 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4f9968db1b5b63f0970abcb74d4cb7a5a105b2fa --- src/cython/cython/tangential_complex.pyx | 292 +++------------------- src/cython/include/Tangential_complex_interface.h | 150 ++--------- 2 files changed, 62 insertions(+), 380 deletions(-) (limited to 'src/cython/include/Tangential_complex_interface.h') diff --git a/src/cython/cython/tangential_complex.pyx b/src/cython/cython/tangential_complex.pyx index 01782004..35f1e384 100644 --- a/src/cython/cython/tangential_complex.pyx +++ b/src/cython/cython/tangential_complex.pyx @@ -3,6 +3,7 @@ from libcpp.vector cimport vector from libcpp.utility cimport pair from libcpp.string cimport string from libcpp cimport bool +from cython.operator cimport dereference as deref import os """This file is part of the Gudhi Library. The Gudhi library @@ -33,30 +34,15 @@ __license__ = "GPL v3" cdef extern from "Tangential_complex_interface.h" namespace "Gudhi": cdef cppclass Tangential_complex_interface "Gudhi::tangential_complex::Tangential_complex_interface": - Tangential_complex_interface(vector[vector[double]] points, double max_alpha_square) + Tangential_complex_interface(vector[vector[double]] points) # bool from_file is a workaround for cython to find the correct signature - Tangential_complex_interface(string off_file, double max_alpha_square, bool from_file) - double filtration() - double simplex_filtration(vector[int] simplex) - void set_filtration(double filtration) - void initialize_filtration() - int num_vertices() - int num_simplices() - void set_dimension(int dimension) - int dimension() - bint find_simplex(vector[int] simplex) - bint insert_simplex_and_subfaces(vector[int] simplex, - double filtration) - vector[pair[vector[int], double]] get_filtered_tree() - vector[pair[vector[int], double]] get_skeleton_tree(int dimension) - vector[pair[vector[int], double]] get_star_tree(vector[int] simplex) - vector[pair[vector[int], double]] get_coface_tree(vector[int] simplex, - int dimension) - void remove_maximal_simplex(vector[int] simplex) + Tangential_complex_interface(string off_file, bool from_file) vector[double] get_point(int vertex) - vector[pair[int, pair[double, double]]] get_persistence(int homology_coeff_field, double min_persistence) - vector[int] get_betti_numbers() - vector[int] get_persistent_betti_numbers(double from_value, double to_value) + unsigned number_of_vertices() + unsigned number_of_simplices() + unsigned number_of_inconsistent_simplices() + unsigned number_of_inconsistent_stars() + void create_simplex_tree(Simplex_tree_interface_full_featured simplex_tree) # TangentialComplex python interface cdef class TangentialComplex: @@ -81,7 +67,7 @@ cdef class TangentialComplex: cdef Tangential_complex_interface * thisptr # Fake constructor that does nothing but documenting the constructor - def __init__(self, points=None, off_file='', max_alpha_square=float('inf')): + def __init__(self, points=None, off_file=''): """TangentialComplex constructor. :param points: A list of points in d-Dimension. @@ -91,22 +77,17 @@ cdef class TangentialComplex: :param off_file: An OFF file style name. :type off_file: string - - :param max_alpha_square: Maximum Tangential square value. Default is :math:`\infty` - :type max_alpha_square: double """ # The real cython constructor - def __cinit__(self, points=[], off_file='', max_alpha_square=float('inf')): + def __cinit__(self, points=[], off_file=''): if off_file is not '': if os.path.isfile(off_file): - self.thisptr = new Tangential_complex_interface(off_file, - max_alpha_square, True) + self.thisptr = new Tangential_complex_interface(off_file, True) else: print("file " + off_file + " not found.") else: - self.thisptr = new Tangential_complex_interface(points, - max_alpha_square) + self.thisptr = new Tangential_complex_interface(points) def __dealloc__(self): @@ -118,195 +99,6 @@ cdef class TangentialComplex: """ return self.thisptr != NULL - def get_filtration(self): - """This function returns the main simplicial complex filtration value. - - :returns: float -- the simplicial complex filtration value. - """ - return self.thisptr.filtration() - - def filtration(self, simplex): - """This function returns the simplicial complex filtration value for a - given N-simplex. - - :param simplex: The N-simplex, represented by a list of vertex. - :type simplex: list of int - :returns: float -- the simplicial complex filtration value. - """ - return self.thisptr.simplex_filtration(simplex) - - def set_filtration(self, filtration): - """This function sets the main simplicial complex filtration value. - - :param filtration: The filtration value. - :type filtration: float. - """ - self.thisptr.set_filtration( filtration) - - def initialize_filtration(self): - """This function initializes and sorts the simplicial complex - filtration vector. - - .. note:: - - This function must be launched before persistence, betti_numbers, - persistent_betti_numbers or get_filtered_tree after inserting or - removing simplices. - """ - self.thisptr.initialize_filtration() - - def num_vertices(self): - """This function returns the number of vertices of the simplicial - complex. - - :returns: int -- the simplicial complex number of vertices. - """ - return self.thisptr.num_vertices() - - def num_simplices(self): - """This function returns the number of simplices of the simplicial - complex. - - :returns: int -- the simplicial complex number of simplices. - """ - return self.thisptr.num_simplices() - - def dimension(self): - """This function returns the dimension of the simplicial complex. - - :returns: int -- the simplicial complex dimension. - """ - return self.thisptr.dimension() - - def set_dimension(self, dimension): - """This function sets the dimension of the simplicial complex. - - :param dimension: The new dimension value. - :type dimension: int. - """ - self.thisptr.set_dimension(dimension) - - def find(self, simplex): - """This function returns if the N-simplex was found in the simplicial - complex or not. - - :param simplex: The N-simplex to find, represented by a list of vertex. - :type simplex: list of int. - :returns: bool -- true if the simplex was found, false otherwise. - """ - cdef vector[int] complex - for i in simplex: - complex.push_back(i) - return self.thisptr.find_simplex(complex) - - def insert(self, simplex, filtration=0.0): - """This function inserts the given N-simplex with the given filtration - value (default value is '0.0'). - - :param simplex: The N-simplex to insert, represented by a list of - vertex. - :type simplex: list of int. - :param filtration: The filtration value of the simplex. - :type filtration: float. - :returns: bool -- true if the simplex was found, false otherwise. - """ - cdef vector[int] complex - for i in simplex: - complex.push_back(i) - return self.thisptr.insert_simplex_and_subfaces(complex, - filtration) - - def get_filtered_tree(self): - """This function returns the tree sorted by increasing filtration - values. - - :returns: list of tuples(simplex, filtration) -- the tree sorted by - increasing filtration values. - """ - cdef vector[pair[vector[int], double]] coface_tree \ - = self.thisptr.get_filtered_tree() - ct = [] - for filtered_complex in coface_tree: - v = [] - for vertex in filtered_complex.first: - v.append(vertex) - ct.append((v, filtered_complex.second)) - return ct - - def get_skeleton_tree(self, dimension): - """This function returns the tree skeleton of a maximum given - dimension. - - :param dimension: The skeleton dimension value. - :type dimension: int. - :returns: list of tuples(simplex, filtration) -- the skeleton tree - of a maximum dimension. - """ - cdef vector[pair[vector[int], double]] coface_tree \ - = self.thisptr.get_skeleton_tree(dimension) - ct = [] - for filtered_complex in coface_tree: - v = [] - for vertex in filtered_complex.first: - v.append(vertex) - ct.append((v, filtered_complex.second)) - return ct - - def get_star_tree(self, simplex): - """This function returns the star tree of a given N-simplex. - - :param simplex: The N-simplex, represented by a list of vertex. - :type simplex: list of int. - :returns: list of tuples(simplex, filtration) -- the star tree of a - simplex. - """ - cdef vector[int] complex - for i in simplex: - complex.push_back(i) - cdef vector[pair[vector[int], double]] coface_tree \ - = self.thisptr.get_star_tree(complex) - ct = [] - for filtered_complex in coface_tree: - v = [] - for vertex in filtered_complex.first: - v.append(vertex) - ct.append((v, filtered_complex.second)) - return ct - - def get_coface_tree(self, simplex, codimension): - """This function returns the coface tree of a given N-simplex with a - given codimension. - - :param simplex: The N-simplex, represented by a list of vertex. - :type simplex: list of int. - :param codimension: The codimension. If codimension = 0, all cofaces - are returned (equivalent of get_star_tree function) - :type codimension: int. - :returns: list of tuples(simplex, filtration) -- the coface tree of a - simplex. - """ - cdef vector[int] complex - for i in simplex: - complex.push_back(i) - cdef vector[pair[vector[int], double]] coface_tree \ - = self.thisptr.get_coface_tree(complex, codimension) - ct = [] - for filtered_complex in coface_tree: - v = [] - for vertex in filtered_complex.first: - v.append(vertex) - ct.append((v, filtered_complex.second)) - return ct - - def remove_maximal_simplex(self, simplex): - """This function removes a given maximal N-simplex from the simplicial - complex. - - :param simplex: The N-simplex, represented by a list of vertex. - :type simplex: list of int. - """ - self.thisptr.remove_maximal_simplex(simplex) - def get_point(self, vertex): """This function returns the point corresponding to a given vertex. @@ -317,47 +109,39 @@ cdef class TangentialComplex: cdef vector[double] point = self.thisptr.get_point(vertex) return point - def persistence(self, homology_coeff_field=11, min_persistence=0.0): - """This function returns the persistence of the simplicial complex. - - :param homology_coeff_field: The homology coefficient field. Must be a - prime number - :type homology_coeff_field: int. - :param min_persistence: The minimum persistence value to take into - account (strictly greater than min_persistence). Default value is - 0.0. - Sets min_persistence to -1.0 to see all values. - :type min_persistence: float. - :note: list of pairs(dimension, pair(birth, death)) -- the - persistence of the simplicial complex. + def num_vertices(self): + """This function returns the number of vertices. + + :returns: unsigned -- the number of vertices. """ - return self.thisptr.get_persistence(homology_coeff_field, min_persistence) + return self.thisptr.number_of_vertices() - def betti_numbers(self): - """This function returns the Betti numbers of the simplicial complex. + def num_simplices(self): + """This function returns the number of simplices. - :returns: list of int -- The Betti numbers ([B0, B1, ..., Bn]). + :returns: unsigned -- the number of simplices. + """ + return self.thisptr.number_of_simplices() - :note: betti_numbers function requires persistence function to be - launched first. + def num_inconsistent_simplices(self): + """This function returns the number of inconsistent simplices. + + :returns: unsigned -- the number of inconsistent simplices. """ - return self.thisptr.get_betti_numbers() + return self.thisptr.number_of_inconsistent_simplices() - def persistent_betti_numbers(self, from_value, to_value): - """This function returns the persistent Betti numbers of the - simplicial complex. + def num_inconsistent_stars(self): + """This function returns the number of inconsistent stars. - :param from_value: The persistence birth limit to be added in the - numbers (persistent birth <= from_value). - :type from_value: float. - :param to_value: The persistence death limit to be added in the - numbers (persistent death > to_value). - :type to_value: float. + :returns: unsigned -- the number of inconsistent stars. + """ + return self.thisptr.number_of_inconsistent_stars() - :returns: list of int -- The persistent Betti numbers ([B0, B1, ..., - Bn]). + def create_simplex_tree(self, SimplexTree simplex_tree): + """This function creates the given simplex tree from the Delaunay + Triangulation. - :note: persistent_betti_numbers function requires persistence - function to be launched first. + :param simplex_tree: The simplex tree to create (must be empty) + :type simplex_tree: SimplexTree """ - return self.thisptr.get_persistent_betti_numbers(from_value, to_value) + self.thisptr.create_simplex_tree(deref(simplex_tree.thisptr)) \ No newline at end of file diff --git a/src/cython/include/Tangential_complex_interface.h b/src/cython/include/Tangential_complex_interface.h index e9750e85..49d66476 100644 --- a/src/cython/include/Tangential_complex_interface.h +++ b/src/cython/include/Tangential_complex_interface.h @@ -28,7 +28,6 @@ #include #include -#include "Persistent_cohomology_interface.h" #include "Simplex_tree_interface.h" #include @@ -50,20 +49,18 @@ class Tangential_complex_interface { using TC = Tangential_complex; public: - Tangential_complex_interface(std::vector>&points, double max_alpha_square) - : pcoh_(nullptr) { + Tangential_complex_interface(std::vector>&points) { Dynamic_kernel k; unsigned intrisic_dim = 0; if (points.size() > 0) intrisic_dim = points[0].size(); tangential_complex_ = new TC(points, intrisic_dim, k); - tangential_complex_->create_complex(simplex_tree_, max_alpha_square); - simplex_tree_.initialize_filtration(); + tangential_complex_->compute_tangential_complex(); + num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices(); } - Tangential_complex_interface(std::string off_file_name, double max_alpha_square, bool from_file = true) - : pcoh_(nullptr) { + Tangential_complex_interface(std::string off_file_name, bool from_file = true) { Gudhi::Points_off_reader off_reader(off_file_name); Dynamic_kernel k; unsigned intrisic_dim = 0; @@ -72,103 +69,8 @@ class Tangential_complex_interface { intrisic_dim = points[0].size(); tangential_complex_ = new TC(points, intrisic_dim, k); - tangential_complex_->create_complex(simplex_tree_, max_alpha_square); - simplex_tree_.initialize_filtration(); - } - - bool find_simplex(const Simplex& vh) { - return (simplex_tree_.find(vh) != simplex_tree_.null_simplex()); - } - - bool insert_simplex_and_subfaces(const Simplex& complex, Filtration_value filtration = 0) { - Insertion_result result = simplex_tree_.insert_simplex_and_subfaces(complex, filtration); - return (result.second); - } - - Filtration_value simplex_filtration(const Simplex& complex) { - return simplex_tree_.filtration(simplex_tree_.find(complex)); - } - - void remove_maximal_simplex(const Simplex& complex) { - return simplex_tree_.remove_maximal_simplex(simplex_tree_.find(complex)); - } - - Complex_tree get_filtered_tree() { - Complex_tree filtered_tree; - for (auto f_simplex : simplex_tree_.filtration_simplex_range()) { - Simplex simplex; - for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) { - simplex.insert(simplex.begin(), vertex); - } - filtered_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex))); - } - return filtered_tree; - - } - - Complex_tree get_skeleton_tree(int dimension) { - Complex_tree skeleton_tree; - for (auto f_simplex : simplex_tree_.skeleton_simplex_range(dimension)) { - Simplex simplex; - for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) { - simplex.insert(simplex.begin(), vertex); - } - skeleton_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex))); - } - return skeleton_tree; - } - - Complex_tree get_star_tree(const Simplex& complex) { - Complex_tree star_tree; - for (auto f_simplex : simplex_tree_.star_simplex_range(simplex_tree_.find(complex))) { - Simplex simplex; - for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) { - simplex.insert(simplex.begin(), vertex); - } - star_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex))); - } - return star_tree; - } - - Complex_tree get_coface_tree(const Simplex& complex, int dimension) { - Complex_tree coface_tree; - for (auto f_simplex : simplex_tree_.cofaces_simplex_range(simplex_tree_.find(complex), dimension)) { - Simplex simplex; - for (auto vertex : simplex_tree_.simplex_vertex_range(f_simplex)) { - simplex.insert(simplex.begin(), vertex); - } - coface_tree.push_back(std::make_pair(simplex, simplex_tree_.filtration(f_simplex))); - } - return coface_tree; - } - - // Specific to Witness complex because no inheritance - Filtration_value filtration() const { - return simplex_tree_.filtration(); - } - - void set_filtration(Filtration_value fil) { - simplex_tree_.set_filtration(fil); - } - - void initialize_filtration() { - simplex_tree_.initialize_filtration(); - } - - size_t num_vertices() const { - return simplex_tree_.num_vertices(); - } - - size_t num_simplices() { - return simplex_tree_.num_simplices(); - } - - int dimension() const { - return simplex_tree_.dimension(); - } - - void set_dimension(int dimension) { - simplex_tree_.set_dimension(dimension); + tangential_complex_->compute_tangential_complex(); + num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices(); } std::vector get_point(int vh) { @@ -183,34 +85,30 @@ class Tangential_complex_interface { return vd; } - std::vector>> get_persistence(int homology_coeff_field, double min_persistence) { - if (pcoh_ != nullptr) { - delete pcoh_; - } - pcoh_ = new Persistent_cohomology_interface>(&simplex_tree_); - return pcoh_->get_persistence(homology_coeff_field, min_persistence); + unsigned number_of_vertices() { + return tangential_complex_->number_of_vertices(); } - - std::vector get_betti_numbers() const { - if (pcoh_ != nullptr) { - return pcoh_->betti_numbers(); - } - std::vector betti_numbers; - return betti_numbers; + + unsigned number_of_simplices() { + return num_inconsistencies_.num_simplices; } - std::vector get_persistent_betti_numbers(Filtration_value from, Filtration_value to) const { - if (pcoh_ != nullptr) { - return pcoh_->persistent_betti_numbers(from, to); - } - std::vector persistent_betti_numbers; - return persistent_betti_numbers; + unsigned number_of_inconsistent_simplices() { + return num_inconsistencies_.num_inconsistent_simplices; } - + + unsigned number_of_inconsistent_stars() { + return num_inconsistencies_.num_inconsistent_stars; + } + + void create_simplex_tree(Simplex_tree<>& simplex_tree) { + tangential_complex_->create_complex>(simplex_tree); + simplex_tree.initialize_filtration(); + } + private: - Simplex_tree<> simplex_tree_; - Persistent_cohomology_interface>* pcoh_; TC* tangential_complex_; + TC::Num_inconsistencies num_inconsistencies_; }; } // namespace tangential_complex -- cgit v1.2.3 From 97d80185d6ec4d5e8f81b4cd4936d29a6d63b05b Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 29 Nov 2016 16:50:55 +0000 Subject: Fix interface for Alpha complex and Tangential complex git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@1801 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 995b53c7f65057ec155988b90f17299665eab4ae --- .../include/gudhi/Tangential_complex/config.h | 3 +- src/cython/CMakeLists.txt | 4 ++ src/cython/cython/alpha_complex.pyx | 19 ++++---- src/cython/cython/simplex_tree.pyx | 48 ++++++++++++-------- src/cython/cython/tangential_complex.pyx | 12 +++-- src/cython/doc/alpha_complex_user.rst | 14 +++--- .../doc/persistence_graphical_tools_user.rst | 3 +- src/cython/doc/tangential_complex_user.rst | 53 ++++++++++++++++++---- ...ex_diagram_persistence_from_off_file_example.py | 3 +- .../example/alpha_complex_from_points_example.py | 3 +- src/cython/include/Alpha_complex_interface.h | 6 +-- src/cython/include/Tangential_complex_interface.h | 14 +++--- src/cython/test/test_alpha_complex.py | 6 +-- 13 files changed, 116 insertions(+), 72 deletions(-) (limited to 'src/cython/include/Tangential_complex_interface.h') diff --git a/src/Tangential_complex/include/gudhi/Tangential_complex/config.h b/src/Tangential_complex/include/gudhi/Tangential_complex/config.h index 98a1b14f..ffefcd6b 100644 --- a/src/Tangential_complex/include/gudhi/Tangential_complex/config.h +++ b/src/Tangential_complex/include/gudhi/Tangential_complex/config.h @@ -26,8 +26,7 @@ #include // ========================= Debugging & profiling ============================= -#define GUDHI_TC_PROFILING -#define DEBUG_TRACES +// #define GUDHI_TC_PROFILING // #define GUDHI_TC_VERY_VERBOSE // #define GUDHI_TC_PERFORM_EXTRA_CHECKS // #define GUDHI_TC_SHOW_DETAILED_STATS_FOR_INCONSISTENCIES diff --git a/src/cython/CMakeLists.txt b/src/cython/CMakeLists.txt index 09ebb678..2746cab9 100644 --- a/src/cython/CMakeLists.txt +++ b/src/cython/CMakeLists.txt @@ -29,6 +29,10 @@ if(PYTHON_PATH AND CYTHON_PATH) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") set(GUDHI_CYTHON_EXTRA_COMPILE_ARGS "${GUDHI_CYTHON_EXTRA_COMPILE_ARGS}'-fp-model strict', ") endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") + if (DEBUG_TRACES) + # For programs to be more verbose + set(GUDHI_CYTHON_EXTRA_COMPILE_ARGS "${GUDHI_CYTHON_EXTRA_COMPILE_ARGS}'-DDEBUG_TRACES', ") + endif() find_package(Eigen3 3.1.0) diff --git a/src/cython/cython/alpha_complex.pyx b/src/cython/cython/alpha_complex.pyx index ed518c38..93f9b87e 100644 --- a/src/cython/cython/alpha_complex.pyx +++ b/src/cython/cython/alpha_complex.pyx @@ -38,7 +38,7 @@ cdef extern from "Alpha_complex_interface.h" namespace "Gudhi": # bool from_file is a workaround for cython to find the correct signature Alpha_complex_interface(string off_file, bool from_file) vector[double] get_point(int vertex) - void create_simplex_tree(Simplex_tree_interface_full_featured simplex_tree, double max_alpha_square) + void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, double max_alpha_square) # AlphaComplex python interface cdef class AlphaComplex: @@ -100,19 +100,20 @@ cdef class AlphaComplex: :param vertex: The vertex. :type vertex: int - :returns: list of float -- the point. + :rtype: list of float + :returns: the point. """ cdef vector[double] point = self.thisptr.get_point(vertex) return point - def create_simplex_tree(self, SimplexTree simplex_tree, max_alpha_square=float('inf')): - """This function creates the given simplex tree from the Delaunay - Triangulation. - - :param simplex_tree: The simplex tree to create (must be empty) - :type simplex_tree: SimplexTree + def create_simplex_tree(self, max_alpha_square=float('inf')): + """ :param max_alpha_square: The maximum alpha square threshold the simplices shall not exceed. Default is set to infinity. :type max_alpha_square: float + :returns: A simplex tree created from the Delaunay Triangulation. + :rtype: SimplexTree """ - self.thisptr.create_simplex_tree(deref(simplex_tree.thisptr), max_alpha_square) \ No newline at end of file + simplex_tree = SimplexTree() + self.thisptr.create_simplex_tree(simplex_tree.thisptr, max_alpha_square) + return simplex_tree diff --git a/src/cython/cython/simplex_tree.pyx b/src/cython/cython/simplex_tree.pyx index cf7cbe26..06e2eb90 100644 --- a/src/cython/cython/simplex_tree.pyx +++ b/src/cython/cython/simplex_tree.pyx @@ -102,7 +102,8 @@ cdef class SimplexTree: def get_filtration(self): """This function returns the main simplicial complex filtration value. - :returns: float -- the simplicial complex filtration value. + :returns: The simplicial complex filtration value. + :rtype: float """ return self.thisptr.filtration() @@ -112,7 +113,8 @@ cdef class SimplexTree: :param simplex: The N-simplex, represented by a list of vertex. :type simplex: list of int. - :returns: float -- the simplicial complex filtration value. + :returns: The simplicial complex filtration value. + :rtype: float """ return self.thisptr.simplex_filtration(simplex) @@ -140,7 +142,8 @@ cdef class SimplexTree: """This function returns the number of vertices of the simplicial complex. - :returns: int -- the simplicial complex number of vertices. + :returns: The simplicial complex number of vertices. + :rtype: int """ return self.thisptr.num_vertices() @@ -148,14 +151,16 @@ cdef class SimplexTree: """This function returns the number of simplices of the simplicial complex. - :returns: int -- the simplicial complex number of simplices. + :returns: the simplicial complex number of simplices. + :rtype: int """ return self.thisptr.num_simplices() def dimension(self): """This function returns the dimension of the simplicial complex. - :returns: int -- the simplicial complex dimension. + :returns: the simplicial complex dimension. + :rtype: int """ return self.thisptr.dimension() @@ -173,7 +178,8 @@ cdef class SimplexTree: :param simplex: The N-simplex to find, represented by a list of vertex. :type simplex: list of int. - :returns: bool -- true if the simplex was found, false otherwise. + :returns: true if the simplex was found, false otherwise. + :rtype: bool """ cdef vector[int] complex for i in simplex: @@ -189,7 +195,8 @@ cdef class SimplexTree: :type simplex: list of int. :param filtration: The filtration value of the simplex. :type filtration: float. - :returns: bool -- true if the simplex was found, false otherwise. + :returns: true if the simplex was found, false otherwise. + :rtype: bool """ cdef vector[int] complex for i in simplex: @@ -201,8 +208,8 @@ cdef class SimplexTree: """This function returns the tree sorted by increasing filtration values. - :returns: list of tuples(simplex, filtration) -- the tree sorted by - increasing filtration values. + :returns: The tree sorted by increasing filtration values. + :rtype: list of tuples(simplex, filtration) """ cdef vector[pair[vector[int], double]] coface_tree \ = self.thisptr.get_filtered_tree() @@ -220,8 +227,8 @@ cdef class SimplexTree: :param dimension: The skeleton dimension value. :type dimension: int. - :returns: list of tuples(simplex, filtration) -- the skeleton tree - of a maximum dimension. + :returns: The skeleton tree of a maximum dimension. + :rtype: list of tuples(simplex, filtration) """ cdef vector[pair[vector[int], double]] coface_tree \ = self.thisptr.get_skeleton_tree(dimension) @@ -238,8 +245,8 @@ cdef class SimplexTree: :param simplex: The N-simplex, represented by a list of vertex. :type simplex: list of int. - :returns: list of tuples(simplex, filtration) -- the star tree of a - simplex. + :returns: The star tree of a simplex. + :rtype: list of tuples(simplex, filtration) """ cdef vector[int] complex for i in simplex: @@ -263,8 +270,8 @@ cdef class SimplexTree: :param codimension: The codimension. If codimension = 0, all cofaces are returned (equivalent of get_star_tree function) :type codimension: int. - :returns: list of tuples(simplex, filtration) -- the coface tree of a - simplex. + :returns: The coface tree of a simplex. + :rtype: list of tuples(simplex, filtration) """ cdef vector[int] complex for i in simplex: @@ -299,8 +306,8 @@ cdef class SimplexTree: 0.0. Sets min_persistence to -1.0 to see all values. :type min_persistence: float. - :note: list of pairs(dimension, pair(birth, death)) -- the - persistence of the simplicial complex. + :returns: The persistence of the simplicial complex. + :rtype: list of pairs(dimension, pair(birth, death)) """ if self.pcohptr != NULL: del self.pcohptr @@ -313,7 +320,8 @@ cdef class SimplexTree: def betti_numbers(self): """This function returns the Betti numbers of the simplicial complex. - :returns: list of int -- The Betti numbers ([B0, B1, ..., Bn]). + :returns: The Betti numbers ([B0, B1, ..., Bn]). + :rtype: list of int :note: betti_numbers function requires persistence function to be launched first. @@ -337,8 +345,8 @@ cdef class SimplexTree: numbers (persistent death > to_value). :type to_value: float. - :returns: list of int -- The persistent Betti numbers ([B0, B1, ..., - Bn]). + :returns: The persistent Betti numbers ([B0, B1, ..., Bn]). + :rtype: list of int :note: persistent_betti_numbers function requires persistence function to be launched first. diff --git a/src/cython/cython/tangential_complex.pyx b/src/cython/cython/tangential_complex.pyx index 35f1e384..f0e4eb02 100644 --- a/src/cython/cython/tangential_complex.pyx +++ b/src/cython/cython/tangential_complex.pyx @@ -37,12 +37,12 @@ cdef extern from "Tangential_complex_interface.h" namespace "Gudhi": Tangential_complex_interface(vector[vector[double]] points) # bool from_file is a workaround for cython to find the correct signature Tangential_complex_interface(string off_file, bool from_file) - vector[double] get_point(int vertex) + vector[double] get_point(unsigned vertex) unsigned number_of_vertices() unsigned number_of_simplices() unsigned number_of_inconsistent_simplices() unsigned number_of_inconsistent_stars() - void create_simplex_tree(Simplex_tree_interface_full_featured simplex_tree) + void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree) # TangentialComplex python interface cdef class TangentialComplex: @@ -137,11 +137,15 @@ cdef class TangentialComplex: """ return self.thisptr.number_of_inconsistent_stars() - def create_simplex_tree(self, SimplexTree simplex_tree): + def create_simplex_tree(self): """This function creates the given simplex tree from the Delaunay Triangulation. :param simplex_tree: The simplex tree to create (must be empty) :type simplex_tree: SimplexTree + :returns: A simplex tree created from the Delaunay Triangulation. + :rtype: SimplexTree """ - self.thisptr.create_simplex_tree(deref(simplex_tree.thisptr)) \ No newline at end of file + simplex_tree = SimplexTree() + self.thisptr.create_simplex_tree(simplex_tree.thisptr) + return simplex_tree diff --git a/src/cython/doc/alpha_complex_user.rst b/src/cython/doc/alpha_complex_user.rst index 5ad3a9e7..ed2a470c 100644 --- a/src/cython/doc/alpha_complex_user.rst +++ b/src/cython/doc/alpha_complex_user.rst @@ -25,14 +25,13 @@ This example builds the Delaunay triangulation from the given points, and initia import gudhi alpha_complex = gudhi.AlphaComplex(points=[[1, 1], [7, 0], [4, 6], [9, 6], [0, 14], [2, 19], [9, 17]]) - simplex_tree = gudhi.SimplexTree() - alpha_complex.create_simplex_tree(simplex_tree, max_alpha_square=60.0) + simplex_tree = alpha_complex.create_simplex_tree(max_alpha_square=60.0) result_str = 'Alpha complex is of dimension ' + repr(simplex_tree.dimension()) + ' - ' + \ repr(simplex_tree.num_simplices()) + ' simplices - ' + \ repr(simplex_tree.num_vertices()) + ' vertices.' print(result_str) - for fitered_value in simplex_tree.get_filtered_tree(): - print(fitered_value) + for filtered_value in simplex_tree.get_filtered_tree(): + print(filtered_value) The output is: @@ -156,14 +155,13 @@ Then, it is asked to display information about the alpha complex: import gudhi alpha_complex = gudhi.AlphaComplex(off_file='alphacomplexdoc.off') - simplex_tree = gudhi.SimplexTree() - alpha_complex.create_simplex_tree(simplex_tree, max_alpha_square=59.0) + simplex_tree = alpha_complex.create_simplex_tree(max_alpha_square=59.0) result_str = 'Alpha complex is of dimension ' + repr(simplex_tree.dimension()) + ' - ' + \ repr(simplex_tree.num_simplices()) + ' simplices - ' + \ repr(simplex_tree.num_vertices()) + ' vertices.' print(result_str) - for fitered_value in simplex_tree.get_filtered_tree(): - print(fitered_value) + for filtered_value in simplex_tree.get_filtered_tree(): + print(filtered_value) the program output is: diff --git a/src/cython/doc/persistence_graphical_tools_user.rst b/src/cython/doc/persistence_graphical_tools_user.rst index b23ad5e6..43c695bf 100644 --- a/src/cython/doc/persistence_graphical_tools_user.rst +++ b/src/cython/doc/persistence_graphical_tools_user.rst @@ -41,7 +41,6 @@ This function can display the persistence result as a diagram: import gudhi alpha_complex = gudhi.AlphaComplex(off_file='tore3D_300.off') - simplex_tree = gudhi.SimplexTree() - alpha_complex.create_simplex_tree(simplex_tree) + simplex_tree = alpha_complex.create_simplex_tree() diag = simplex_tree.persistence() gudhi.diagram_persistence(diag) diff --git a/src/cython/doc/tangential_complex_user.rst b/src/cython/doc/tangential_complex_user.rst index 588de08c..33c03e34 100644 --- a/src/cython/doc/tangential_complex_user.rst +++ b/src/cython/doc/tangential_complex_user.rst @@ -111,20 +111,55 @@ itself and/or after the perturbation process. Simple example -------------- -This example builds the Tangential complex of point set. Note that the -dimension of the kernel here is dynamic, which is slower, but more flexible: -the intrinsic and ambient dimensions does not have to be known at compile-time. +This example builds the Tangential complex of point set. -testcode:: +.. testcode:: - import gudhi - tc = gudhi.TangentialComplex(points=[[1, 1], [7, 0], [4, 6], [9, 6], [0, 14], [2, 19], [9, 17]]) + import gudhi + tc = gudhi.TangentialComplex(points=[[1, 1], [7, 0], [4, 6], [9, 6], [0, 14], [2, 19], [9, 17]]) + result_str = 'Tangential contains ' + repr(tc.num_simplices()) + \ + ' simplices - ' + repr(tc.num_vertices()) + ' vertices.' + print(result_str) -The output is: + st = tc.create_simplex_tree() + result_str = 'Simplex tree is of dimension ' + repr(st.dimension()) + \ + ' - ' + repr(st.num_simplices()) + ' simplices - ' + \ + repr(st.num_vertices()) + ' vertices.' + print(result_str) + for filtered_value in st.get_filtered_tree(): + print(filtered_value) -testoutput:: +The output is: - Tangential complex is of dimension 2 - 25 simplices - 7 vertices. +.. testoutput:: + + Tangential contains 18 simplices - 7 vertices. + Simplex tree is of dimension 2 - 25 simplices - 7 vertices. + ([0], 0.0) + ([1], 0.0) + ([0, 1], 0.0) + ([2], 0.0) + ([0, 2], 0.0) + ([1, 2], 0.0) + ([0, 1, 2], 0.0) + ([3], 0.0) + ([1, 3], 0.0) + ([2, 3], 0.0) + ([1, 2, 3], 0.0) + ([4], 0.0) + ([0, 4], 0.0) + ([2, 4], 0.0) + ([0, 2, 4], 0.0) + ([5], 0.0) + ([4, 5], 0.0) + ([6], 0.0) + ([2, 6], 0.0) + ([3, 6], 0.0) + ([2, 3, 6], 0.0) + ([4, 6], 0.0) + ([2, 4, 6], 0.0) + ([5, 6], 0.0) + ([4, 5, 6], 0.0) Example with perturbation diff --git a/src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py b/src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py index 40d06f93..6cdd5506 100755 --- a/src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py +++ b/src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py @@ -53,8 +53,7 @@ with open(args.file, 'r') as f: print(message) alpha_complex = gudhi.AlphaComplex(off_file=args.file) - simplex_tree = gudhi.SimplexTree() - alpha_complex.create_simplex_tree(simplex_tree, max_alpha_square=args.max_alpha_square) + simplex_tree = alpha_complex.create_simplex_tree(max_alpha_square=args.max_alpha_square) message = "Number of simplices=" + repr(simplex_tree.num_simplices()) print(message) diff --git a/src/cython/example/alpha_complex_from_points_example.py b/src/cython/example/alpha_complex_from_points_example.py index 45319f7f..ae21c711 100755 --- a/src/cython/example/alpha_complex_from_points_example.py +++ b/src/cython/example/alpha_complex_from_points_example.py @@ -31,8 +31,7 @@ __license__ = "GPL v3" print("#####################################################################") print("AlphaComplex creation from points") alpha_complex = AlphaComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]]) -simplex_tree = SimplexTree() -alpha_complex.create_simplex_tree(simplex_tree, max_alpha_square=60.0) +simplex_tree = alpha_complex.create_simplex_tree(max_alpha_square=60.0) if simplex_tree.find([0, 1]): print("[0, 1] Found !!") diff --git a/src/cython/include/Alpha_complex_interface.h b/src/cython/include/Alpha_complex_interface.h index 15384206..81761c77 100644 --- a/src/cython/include/Alpha_complex_interface.h +++ b/src/cython/include/Alpha_complex_interface.h @@ -69,9 +69,9 @@ class Alpha_complex_interface { return vd; } - void create_simplex_tree(Simplex_tree_interface<>& simplex_tree, double max_alpha_square) { - alpha_complex_->create_complex(simplex_tree, max_alpha_square); - simplex_tree.initialize_filtration(); + void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square) { + alpha_complex_->create_complex(*simplex_tree, max_alpha_square); + simplex_tree->initialize_filtration(); } private: diff --git a/src/cython/include/Tangential_complex_interface.h b/src/cython/include/Tangential_complex_interface.h index 49d66476..c7fce557 100644 --- a/src/cython/include/Tangential_complex_interface.h +++ b/src/cython/include/Tangential_complex_interface.h @@ -73,14 +73,12 @@ class Tangential_complex_interface { num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices(); } - std::vector get_point(int vh) { + std::vector get_point(unsigned vh) { std::vector vd; - try { + if (vh < tangential_complex_->number_of_vertices()) { Point_d ph = tangential_complex_->get_point(vh); for (auto coord = ph.cartesian_begin(); coord < ph.cartesian_end(); coord++) vd.push_back(*coord); - } catch (std::out_of_range outofrange) { - // std::out_of_range is thrown in case not found. Other exceptions must be re-thrown } return vd; } @@ -101,9 +99,11 @@ class Tangential_complex_interface { return num_inconsistencies_.num_inconsistent_stars; } - void create_simplex_tree(Simplex_tree<>& simplex_tree) { - tangential_complex_->create_complex>(simplex_tree); - simplex_tree.initialize_filtration(); + void create_simplex_tree(Simplex_tree<>* simplex_tree) { + int max_dim = tangential_complex_->create_complex>(*simplex_tree); + // FIXME + simplex_tree->set_dimension(max_dim); + simplex_tree->initialize_filtration(); } private: diff --git a/src/cython/test/test_alpha_complex.py b/src/cython/test/test_alpha_complex.py index 3731ccda..b08ac0d7 100755 --- a/src/cython/test/test_alpha_complex.py +++ b/src/cython/test/test_alpha_complex.py @@ -36,8 +36,7 @@ def test_infinite_alpha(): alpha_complex = AlphaComplex(points=point_list) assert alpha_complex.__is_defined() == True - simplex_tree = SimplexTree() - alpha_complex.create_simplex_tree(simplex_tree) + simplex_tree = alpha_complex.create_simplex_tree() assert simplex_tree.__is_persistence_defined() == False assert simplex_tree.num_simplices() == 11 @@ -65,8 +64,7 @@ def test_filtered_alpha(): point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] filtered_alpha = AlphaComplex(points=point_list) - simplex_tree = SimplexTree() - filtered_alpha.create_simplex_tree(simplex_tree, max_alpha_square=0.25) + simplex_tree = filtered_alpha.create_simplex_tree(max_alpha_square=0.25) assert simplex_tree.num_simplices() == 8 assert simplex_tree.num_vertices() == 4 -- cgit v1.2.3 From d7d59f1e4245af3595c8eafd0abc0abdc4b5805d Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 30 Nov 2016 10:33:56 +0000 Subject: Doc, examples and tests updates for tangential git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@1805 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 56d080f79a7a0c3b6eb3ed38b376e899cb17c8f9 --- src/cython/cython/simplex_tree.pyx | 7 ++- src/cython/cython/tangential_complex.pyx | 12 ++++ src/cython/doc/tangential_complex_user.rst | 23 ++++++-- ...ex_diagram_persistence_from_off_file_example.py | 3 +- ...complex_plain_homology_from_off_file_example.py | 66 ++++++++++++++++++++++ src/cython/include/Tangential_complex_interface.h | 9 ++- src/cython/test/test_tangential_complex.py | 56 ++++++++++++++++++ 7 files changed, 164 insertions(+), 12 deletions(-) create mode 100755 src/cython/example/tangential_complex_plain_homology_from_off_file_example.py create mode 100755 src/cython/test/test_tangential_complex.py (limited to 'src/cython/include/Tangential_complex_interface.h') diff --git a/src/cython/cython/simplex_tree.pyx b/src/cython/cython/simplex_tree.pyx index 06e2eb90..8f909398 100644 --- a/src/cython/cython/simplex_tree.pyx +++ b/src/cython/cython/simplex_tree.pyx @@ -1,6 +1,7 @@ from cython cimport numeric from libcpp.vector cimport vector from libcpp.utility cimport pair +from libcpp cimport bool """This file is part of the Gudhi Library. The Gudhi library (Geometric Understanding in Higher Dimensions) is a generic C++ @@ -54,7 +55,7 @@ cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi": cdef cppclass Simplex_tree_persistence_interface "Gudhi::Persistent_cohomology_interface>": - Simplex_tree_persistence_interface(Simplex_tree_interface_full_featured * st) + Simplex_tree_persistence_interface(Simplex_tree_interface_full_featured * st, bool persistence_dim_max) vector[pair[int, pair[double, double]]] get_persistence(int homology_coeff_field, double min_persistence) vector[int] betti_numbers() vector[int] persistent_betti_numbers(double from_value, double to_value) @@ -295,7 +296,7 @@ cdef class SimplexTree: """ self.thisptr.remove_maximal_simplex(simplex) - def persistence(self, homology_coeff_field=11, min_persistence=0): + def persistence(self, homology_coeff_field=11, min_persistence=0, persistence_dim_max = False): """This function returns the persistence of the simplicial complex. :param homology_coeff_field: The homology coefficient field. Must be a @@ -311,7 +312,7 @@ cdef class SimplexTree: """ if self.pcohptr != NULL: del self.pcohptr - self.pcohptr = new Simplex_tree_persistence_interface(self.thisptr) + self.pcohptr = new Simplex_tree_persistence_interface(self.thisptr, persistence_dim_max) cdef vector[pair[int, pair[double, double]]] persistence_result if self.pcohptr != NULL: persistence_result = self.pcohptr.get_persistence(homology_coeff_field, min_persistence) diff --git a/src/cython/cython/tangential_complex.pyx b/src/cython/cython/tangential_complex.pyx index f0e4eb02..5a7ebd1a 100644 --- a/src/cython/cython/tangential_complex.pyx +++ b/src/cython/cython/tangential_complex.pyx @@ -43,6 +43,7 @@ cdef extern from "Tangential_complex_interface.h" namespace "Gudhi": unsigned number_of_inconsistent_simplices() unsigned number_of_inconsistent_stars() void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree) + void fix_inconsistencies_using_perturbation(double max_perturb, double time_limit) # TangentialComplex python interface cdef class TangentialComplex: @@ -149,3 +150,14 @@ cdef class TangentialComplex: simplex_tree = SimplexTree() self.thisptr.create_simplex_tree(simplex_tree.thisptr) return simplex_tree + + def fix_inconsistencies_using_perturbation(self, max_perturb, time_limit=-1.0): + """Attempts to fix inconsistencies by perturbing the point positions. + :param max_perturb: Maximum length of the translations used by the + perturbation. + :type max_perturb: double + :param time_limit: Time limit in seconds. If -1, no time limit is set. + :type time_limit: double + """ + self.thisptr.fix_inconsistencies_using_perturbation(max_perturb, + time_limit) diff --git a/src/cython/doc/tangential_complex_user.rst b/src/cython/doc/tangential_complex_user.rst index 33c03e34..30c97b8f 100644 --- a/src/cython/doc/tangential_complex_user.rst +++ b/src/cython/doc/tangential_complex_user.rst @@ -111,12 +111,12 @@ itself and/or after the perturbation process. Simple example -------------- -This example builds the Tangential complex of point set. +This example builds the Tangential complex of point set read in an OFF file. .. testcode:: import gudhi - tc = gudhi.TangentialComplex(points=[[1, 1], [7, 0], [4, 6], [9, 6], [0, 14], [2, 19], [9, 17]]) + tc = gudhi.TangentialComplex(off_file='alphacomplexdoc.off') result_str = 'Tangential contains ' + repr(tc.num_simplices()) + \ ' simplices - ' + repr(tc.num_vertices()) + ' vertices.' print(result_str) @@ -169,11 +169,24 @@ This example builds the Tangential complex of a point set, then tries to solve inconsistencies by perturbing the positions of points involved in inconsistent simplices. -testcode:: +.. testcode:: import gudhi - tc = gudhi.TangentialComplex(points=[[1, 1], [7, 0], [4, 6], [9, 6], [0, 14], [2, 19], [9, 17]]) + tc = gudhi.TangentialComplex(points=[[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0]]) + result_str = 'Tangential contains ' + repr(tc.num_vertices()) + ' vertices.' + print(result_str) + + if tc.num_inconsistent_simplices() > 0: + print('Tangential contains inconsistencies.') + + tc.fix_inconsistencies_using_perturbation(10, 60) + if tc.num_inconsistent_simplices() == 0: + print('Inconsistencies has been fixed.') The output is: -testoutput:: +.. testoutput:: + + Tangential contains 4 vertices. + Tangential contains inconsistencies. + Inconsistencies has been fixed. diff --git a/src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py b/src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py index 6cdd5506..ae03aa67 100755 --- a/src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py +++ b/src/cython/example/alpha_complex_diagram_persistence_from_off_file_example.py @@ -35,8 +35,7 @@ parser = argparse.ArgumentParser(description='AlphaComplex creation from ' 'example/alpha_complex_diagram_persistence_from_off_file_example.py ' '-f ../data/points/tore3D_300.off -a 0.6' '- Constructs a alpha complex with the ' - 'points from the given file. File format ' - 'is X1, X2, ..., Xn') + 'points from the given OFF file.') parser.add_argument("-f", "--file", type=str, required=True) parser.add_argument("-a", "--max_alpha_square", type=float, default=0.5) parser.add_argument('--no-diagram', default=False, action='store_true' , help='Flag for not to display the diagrams') diff --git a/src/cython/example/tangential_complex_plain_homology_from_off_file_example.py b/src/cython/example/tangential_complex_plain_homology_from_off_file_example.py new file mode 100755 index 00000000..be4c40be --- /dev/null +++ b/src/cython/example/tangential_complex_plain_homology_from_off_file_example.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python + +import gudhi +import argparse + +"""This file is part of the Gudhi Library. The Gudhi library + (Geometric Understanding in Higher Dimensions) is a generic C++ + library for computational topology. + + Author(s): Vincent Rouvreau + + Copyright (C) 2016 INRIA + + 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. + + 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. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA" +__license__ = "GPL v3" + +parser = argparse.ArgumentParser(description='TangentialComplex creation from ' + 'points read in a OFF file.', + epilog='Example: ' + 'example/tangential_complex_plain_homology_from_off_file_example.py ' + '-f ../data/points/tore3D_300.off' + '- Constructs a tangential complex with the ' + 'points from the given OFF file') +parser.add_argument("-f", "--file", type=str, required=True) +parser.add_argument('--no-diagram', default=False, action='store_true' , help='Flag for not to display the diagrams') + +args = parser.parse_args() + +with open(args.file, 'r') as f: + first_line = f.readline() + if (first_line == 'OFF\n') or (first_line == 'nOFF\n'): + print("#####################################################################") + print("TangentialComplex creation from points read in a OFF file") + + tc = gudhi.TangentialComplex(off_file=args.file) + st = tc.create_simplex_tree() + + message = "Number of simplices=" + repr(st.num_simplices()) + print(message) + + diag = st.persistence(persistence_dim_max = True) + + print("betti_numbers()=") + print(st.betti_numbers()) + + if args.no_diagram == False: + gudhi.diagram_persistence(diag) + else: + print(args.file, "is not a valid OFF file") + + f.close() diff --git a/src/cython/include/Tangential_complex_interface.h b/src/cython/include/Tangential_complex_interface.h index c7fce557..9da32757 100644 --- a/src/cython/include/Tangential_complex_interface.h +++ b/src/cython/include/Tangential_complex_interface.h @@ -53,7 +53,7 @@ class Tangential_complex_interface { Dynamic_kernel k; unsigned intrisic_dim = 0; if (points.size() > 0) - intrisic_dim = points[0].size(); + intrisic_dim = points[0].size() - 1; tangential_complex_ = new TC(points, intrisic_dim, k); tangential_complex_->compute_tangential_complex(); @@ -66,7 +66,7 @@ class Tangential_complex_interface { unsigned intrisic_dim = 0; std::vector points = off_reader.get_point_cloud(); if (points.size() > 0) - intrisic_dim = points[0].size(); + intrisic_dim = points[0].size() - 1; tangential_complex_ = new TC(points, intrisic_dim, k); tangential_complex_->compute_tangential_complex(); @@ -99,6 +99,11 @@ class Tangential_complex_interface { return num_inconsistencies_.num_inconsistent_stars; } + void fix_inconsistencies_using_perturbation(double max_perturb, double time_limit) { + tangential_complex_->fix_inconsistencies_using_perturbation(max_perturb, time_limit); + num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices(); + } + void create_simplex_tree(Simplex_tree<>* simplex_tree) { int max_dim = tangential_complex_->create_complex>(*simplex_tree); // FIXME diff --git a/src/cython/test/test_tangential_complex.py b/src/cython/test/test_tangential_complex.py new file mode 100755 index 00000000..8e1b5c51 --- /dev/null +++ b/src/cython/test/test_tangential_complex.py @@ -0,0 +1,56 @@ +from gudhi import TangentialComplex, SimplexTree + +"""This file is part of the Gudhi Library. The Gudhi library + (Geometric Understanding in Higher Dimensions) is a generic C++ + library for computational topology. + + Author(s): Vincent Rouvreau + + Copyright (C) 2016 INRIA + + 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. + + 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. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA" +__license__ = "GPL v3" + + +def test_tangential(): + point_list = [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0]] + tc = TangentialComplex(points=point_list) + assert tc.__is_defined() == True + assert tc.num_vertices() == 4 + + st = tc.create_simplex_tree() + assert st.__is_defined() == True + assert st.__is_persistence_defined() == False + + assert st.num_simplices() == 13 + assert st.num_vertices() == 4 + + assert st.get_filtered_tree() == \ + [([0], 0.0), ([1], 0.0), ([0, 1], 0.0), ([2], 0.0), ([0, 2], 0.0), + ([1, 2], 0.0), ([3], 0.0), ([0, 3], 0.0), ([1, 3], 0.0), + ([0, 1, 3], 0.0), ([2, 3], 0.0), ([0, 2, 3], 0.0), + ([1, 2, 3], 0.0)] + assert st.get_coface_tree([0], 1) == \ + [([0, 1], 0.0), ([0, 2], 0.0), ([0, 3], 0.0)] + + assert point_list[0] == tc.get_point(0) + assert point_list[1] == tc.get_point(1) + assert point_list[2] == tc.get_point(2) + assert point_list[3] == tc.get_point(3) + assert tc.get_point(4) == [] + assert tc.get_point(125) == [] -- cgit v1.2.3 From ad9c182c0ffa8b517cd20d174de823db05250514 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 25 Jan 2017 08:59:20 +0000 Subject: Fix rips complex with the new interface Remove mini simplex tree Fix persistent cohomology doc - only simplex tree used Remove useless type definition in Cython C++ interfaces git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@2003 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: fff43192b00df1c70d59109a6c14932013992ff1 --- src/cython/cython/mini_simplex_tree.pyx | 352 -------------------- src/cython/cython/rips_complex.pyx | 354 +++------------------ src/cython/doc/persistent_cohomology_sum.rst | 3 - src/cython/doc/persistent_cohomology_user.rst | 3 - src/cython/example/mini_simplex_tree_example.py | 73 ----- ...am_persistence_with_pandas_interface_example.py | 11 +- .../example/rips_complex_from_points_example.py | 10 +- src/cython/example/rips_persistence_diagram.py | 7 +- src/cython/gudhi.pyx.in | 1 - src/cython/include/Alpha_complex_interface.h | 9 +- src/cython/include/Cubical_complex_interface.h | 4 +- src/cython/include/Rips_complex_interface.h | 70 ++++ src/cython/include/Simplex_tree_interface.h | 34 +- src/cython/include/Subsampling_interface.h | 3 +- src/cython/include/Tangential_complex_interface.h | 5 - src/cython/include/Witness_complex_interface.h | 4 +- src/cython/test/test_mini_simplex_tree.py | 50 --- src/cython/test/test_rips_complex.py | 35 +- 18 files changed, 158 insertions(+), 870 deletions(-) delete mode 100644 src/cython/cython/mini_simplex_tree.pyx delete mode 100755 src/cython/example/mini_simplex_tree_example.py create mode 100644 src/cython/include/Rips_complex_interface.h delete mode 100755 src/cython/test/test_mini_simplex_tree.py (limited to 'src/cython/include/Tangential_complex_interface.h') diff --git a/src/cython/cython/mini_simplex_tree.pyx b/src/cython/cython/mini_simplex_tree.pyx deleted file mode 100644 index 3ba7e853..00000000 --- a/src/cython/cython/mini_simplex_tree.pyx +++ /dev/null @@ -1,352 +0,0 @@ -from cython cimport numeric -from libcpp.vector cimport vector -from libcpp.utility cimport pair - -"""This file is part of the Gudhi Library. The Gudhi library - (Geometric Understanding in Higher Dimensions) is a generic C++ - library for computational topology. - - Author(s): Vincent Rouvreau - - Copyright (C) 2016 INRIA - - 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. - - 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. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -""" - -__author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA" -__license__ = "GPL v3" - -cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": - cdef cppclass Simplex_tree_options_mini: - pass - - cdef cppclass Simplex_tree_interface_mini "Gudhi::Simplex_tree_interface": - Simplex_tree() - double filtration() - double simplex_filtration(vector[int] simplex) - void set_filtration(double filtration) - void initialize_filtration() - int num_vertices() - int num_simplices() - void set_dimension(int dimension) - int dimension() - bint find_simplex(vector[int] simplex) - bint insert_simplex_and_subfaces(vector[int] simplex, - double filtration) - vector[pair[vector[int], double]] get_filtered_tree() - vector[pair[vector[int], double]] get_skeleton_tree(int dimension) - vector[pair[vector[int], double]] get_star_tree(vector[int] simplex) - vector[pair[vector[int], double]] get_coface_tree(vector[int] simplex, - int dimension) - void remove_maximal_simplex(vector[int] simplex) - -cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi": - cdef cppclass Mini_simplex_tree_persistence_interface "Gudhi::Persistent_cohomology_interface>": - Mini_simplex_tree_persistence_interface(Simplex_tree_interface_mini * st) - vector[pair[int, pair[double, double]]] get_persistence(int homology_coeff_field, double min_persistence) - vector[int] betti_numbers() - vector[int] persistent_betti_numbers(double from_value, double to_value) - -# MiniSimplexTree python interface -cdef class MiniSimplexTree: - """The simplex tree is an efficient and flexible data structure for - representing general (filtered) simplicial complexes. The data structure - is described in Jean-Daniel Boissonnat and Clément Maria. The Simplex - Tree: An Efficient Data Structure for General Simplicial Complexes. - Algorithmica, pages 1–22, 2014. - - This class is a non-filtered, with keys, and non contiguous vertices - version of the simplex tree. - """ - cdef Simplex_tree_interface_mini * thisptr - - cdef Mini_simplex_tree_persistence_interface * pcohptr - - # Fake constructor that does nothing but documenting the constructor - def __init__(self, points=[], max_alpha_square=float('inf')): - """MiniSimplexTree constructor. - """ - - # The real cython constructor - def __cinit__(self): - self.thisptr = new Simplex_tree_interface_mini() - - def __dealloc__(self): - if self.thisptr != NULL: - del self.thisptr - if self.pcohptr != NULL: - del self.pcohptr - - def __is_defined(self): - """Returns true if MiniSimplexTree pointer is not NULL. - """ - return self.thisptr != NULL - - def __is_persistence_defined(self): - """Returns true if Persistence pointer is not NULL. - """ - return self.pcohptr != NULL - - def get_filtration(self): - """This function returns the main simplicial complex filtration value. - - :returns: float -- the simplicial complex filtration value. - """ - return self.thisptr.filtration() - - def filtration(self, simplex): - """This function returns the simplicial complex filtration value for a - given N-simplex. - - :param simplex: The N-simplex, represented by a list of vertex. - :type simplex: list of int. - :returns: float -- the simplicial complex filtration value. - """ - return self.thisptr.simplex_filtration(simplex) - - def set_filtration(self, filtration): - """This function sets the main simplicial complex filtration value. - - :param filtration: The filtration value. - :type filtration: float. - """ - self.thisptr.set_filtration( filtration) - - def initialize_filtration(self): - """This function initializes and sorts the simplicial complex - filtration vector. - - .. note:: - - This function must be launched before persistence, betti_numbers, - persistent_betti_numbers or get_filtered_tree after inserting or - removing simplices. - """ - self.thisptr.initialize_filtration() - - def num_vertices(self): - """This function returns the number of vertices of the simplicial - complex. - - :returns: int -- the simplicial complex number of vertices. - """ - return self.thisptr.num_vertices() - - def num_simplices(self): - """This function returns the number of simplices of the simplicial - complex. - - :returns: int -- the simplicial complex number of simplices. - """ - return self.thisptr.num_simplices() - - def dimension(self): - """This function returns the dimension of the simplicial complex. - - :returns: int -- the simplicial complex dimension. - """ - return self.thisptr.dimension() - - def set_dimension(self, dimension): - """This function sets the dimension of the simplicial complex. - - :param dimension: The new dimension value. - :type dimension: int. - """ - self.thisptr.set_dimension(dimension) - - def find(self, simplex): - """This function returns if the N-simplex was found in the simplicial - complex or not. - - :param simplex: The N-simplex to find, represented by a list of vertex. - :type simplex: list of int. - :returns: bool -- true if the simplex was found, false otherwise. - """ - cdef vector[int] complex - for i in simplex: - complex.push_back(i) - return self.thisptr.find_simplex(complex) - - def insert(self, simplex, filtration=0.0): - """This function inserts the given N-simplex with the given filtration - value (default value is '0.0'). - - :param simplex: The N-simplex to insert, represented by a list of - vertex. - :type simplex: list of int. - :param filtration: The filtration value of the simplex. - :type filtration: float. - :returns: bool -- true if the simplex was found, false otherwise. - """ - cdef vector[int] complex - for i in simplex: - complex.push_back(i) - return self.thisptr.insert_simplex_and_subfaces(complex, - filtration) - - def get_filtered_tree(self): - """This function returns the tree sorted by increasing filtration - values. - - :returns: list of tuples(simplex, filtration) -- the tree sorted by - increasing filtration values. - """ - cdef vector[pair[vector[int], double]] coface_tree \ - = self.thisptr.get_filtered_tree() - ct = [] - for filtered_complex in coface_tree: - v = [] - for vertex in filtered_complex.first: - v.append(vertex) - ct.append((v, filtered_complex.second)) - return ct - - def get_skeleton_tree(self, dimension): - """This function returns the tree skeleton of a maximum given - dimension. - - :param dimension: The skeleton dimension value. - :type dimension: int. - :returns: list of tuples(simplex, filtration) -- the skeleton tree - of a maximum dimension. - """ - cdef vector[pair[vector[int], double]] coface_tree \ - = self.thisptr.get_skeleton_tree(dimension) - ct = [] - for filtered_complex in coface_tree: - v = [] - for vertex in filtered_complex.first: - v.append(vertex) - ct.append((v, filtered_complex.second)) - return ct - - def get_star_tree(self, simplex): - """This function returns the star tree of a given N-simplex. - - :param simplex: The N-simplex, represented by a list of vertex. - :type simplex: list of int. - :returns: list of tuples(simplex, filtration) -- the star tree of a - simplex. - """ - cdef vector[int] complex - for i in simplex: - complex.push_back(i) - cdef vector[pair[vector[int], double]] coface_tree \ - = self.thisptr.get_star_tree(complex) - ct = [] - for filtered_complex in coface_tree: - v = [] - for vertex in filtered_complex.first: - v.append(vertex) - ct.append((v, filtered_complex.second)) - return ct - - def get_coface_tree(self, simplex, codimension): - """This function returns the coface tree of a given N-simplex with a - given codimension. - - :param simplex: The N-simplex, represented by a list of vertex. - :type simplex: list of int. - :param codimension: The codimension. If codimension = 0, all cofaces - are returned (equivalent of get_star_tree function) - :type codimension: int. - :returns: list of tuples(simplex, filtration) -- the coface tree of a - simplex. - """ - cdef vector[int] complex - for i in simplex: - complex.push_back(i) - cdef vector[pair[vector[int], double]] coface_tree \ - = self.thisptr.get_coface_tree(complex, codimension) - ct = [] - for filtered_complex in coface_tree: - v = [] - for vertex in filtered_complex.first: - v.append(vertex) - ct.append((v, filtered_complex.second)) - return ct - - def remove_maximal_simplex(self, simplex): - """This function removes a given maximal N-simplex from the simplicial - complex. - - :param simplex: The N-simplex, represented by a list of vertex. - :type simplex: list of int. - """ - self.thisptr.remove_maximal_simplex(simplex) - - def persistence(self, homology_coeff_field=11): - """This function returns the persistence of the simplicial complex. - - :param homology_coeff_field: The homology coefficient field. Must be a - prime number - :type homology_coeff_field: int. - :param min_persistence: The minimum persistence value to take into - account (strictly greater than min_persistence). Default value is - 0.0. - Sets min_persistence to -1.0 to see all values. - :type min_persistence: float. - :returns: list of pairs(dimension, pair(birth, death)) -- the - persistence of the simplicial complex. - """ - if self.pcohptr != NULL: - del self.pcohptr - self.pcohptr = new Mini_simplex_tree_persistence_interface(self.thisptr) - cdef vector[pair[int, pair[double, double]]] persistence_result - if self.pcohptr != NULL: - persistence_result = self.pcohptr.get_persistence(homology_coeff_field, 0) - return persistence_result - - def betti_numbers(self): - """This function returns the Betti numbers of the simplicial complex. - - :returns: list of int -- The Betti numbers ([B0, B1, ..., Bn]). - - :note: betti_numbers function requires persistence function to be - launched first. - """ - cdef vector[int] bn_result - if self.pcohptr != NULL: - bn_result = self.pcohptr.betti_numbers() - else: - print("betti_numbers function requires persistence function" - " to be launched first.") - return bn_result - - def persistent_betti_numbers(self, from_value, to_value): - """This function returns the persistent Betti numbers of the - simplicial complex. - - :param from_value: The persistence birth limit to be added in the - numbers (persistent birth <= from_value). - :type from_value: float. - :param to_value: The persistence death limit to be added in the - numbers (persistent death > to_value). - :type to_value: float. - - :returns: list of int -- The persistent Betti numbers ([B0, B1, ..., - Bn]). - - :note: persistent_betti_numbers function requires persistence - function to be launched first. - """ - cdef vector[int] pbn_result - if self.pcohptr != NULL: - pbn_result = self.pcohptr.persistent_betti_numbers(from_value, to_value) - else: - print("persistent_betti_numbers function requires persistence function" - " to be launched first.") - return pbn_result diff --git a/src/cython/cython/rips_complex.pyx b/src/cython/cython/rips_complex.pyx index 08bd2388..2e739ac3 100644 --- a/src/cython/cython/rips_complex.pyx +++ b/src/cython/cython/rips_complex.pyx @@ -3,6 +3,7 @@ from libcpp.vector cimport vector from libcpp.utility cimport pair from libcpp.string cimport string from libcpp cimport bool +import os """This file is part of the Gudhi Library. The Gudhi library (Geometric Understanding in Higher Dimensions) is a generic C++ @@ -30,61 +31,37 @@ __author__ = "Vincent Rouvreau" __copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" -cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": - cdef cppclass Simplex_tree_options_full_featured: - pass - - cdef cppclass Rips_complex_interface "Gudhi::Simplex_tree_interface": - Simplex_tree() - double filtration() - double simplex_filtration(vector[int] simplex) - void set_filtration(double filtration) - void initialize_filtration() - int num_vertices() - int num_simplices() - void set_dimension(int dimension) - int dimension() - bint find_simplex(vector[int] simplex) - bint insert_simplex_and_subfaces(vector[int] simplex, - double filtration) - vector[pair[vector[int], double]] get_filtered_tree() - vector[pair[vector[int], double]] get_skeleton_tree(int dimension) - vector[pair[vector[int], double]] get_star_tree(vector[int] simplex) - vector[pair[vector[int], double]] get_coface_tree(vector[int] simplex, - int dimension) - void remove_maximal_simplex(vector[int] simplex) - void graph_expansion(vector[vector[double]] points, int max_dimension, - double max_edge_length) - void graph_expansion(string off_file, int max_dimension, - double max_edge_length, bool from_file) - -cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi": - cdef cppclass Rips_complex_persistence_interface "Gudhi::Persistent_cohomology_interface>": - Rips_complex_persistence_interface(Rips_complex_interface * st) - vector[pair[int, pair[double, double]]] get_persistence(int homology_coeff_field, double min_persistence) - vector[int] betti_numbers() - vector[int] persistent_betti_numbers(double from_value, double to_value) +cdef extern from "Rips_complex_interface.h" namespace "Gudhi": + cdef cppclass Rips_complex_interface "Gudhi::rips_complex::Rips_complex_interface": + Rips_complex_interface(vector[vector[double]] points, double threshold) + # bool from_file is a workaround for cython to find the correct signature + Rips_complex_interface(string off_file, double threshold, bool from_file) + void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, int dim_max) # RipsComplex python interface cdef class RipsComplex: - """RipsComplex is a simplicial complex constructed from a list of points. + """RipsComplex is a simplicial complex constructed from the finite cells + of a Delaunay Triangulation. + + The filtration value of each simplex is computed as the square of the + circumradius of the simplex if the circumsphere is empty (the simplex is + then said to be Gabriel), and as the minimum of the filtration values of + the codimension 1 cofaces that make it not Gabriel otherwise. + + All simplices that have a filtration value strictly greater than a given + alpha squared value are not inserted into the complex. + + .. note:: - Each point Pn is inserted as a vertex in the simplicial complex with a - null filtration value. + When Rips_complex is constructed with an infinite value of alpha, the + complex is a Delaunay complex. - A N-simplex represented by the list of vertices Vi, ..., Vj is inserted in - the simplicial complex if all the points Pi, ..., Pj corresponding to the - vertices are within a distance less or equal to a given maximum edge length - value, and if N (dimension of the N-simplex) is less or equal to a given - maximum dimension. """ - cdef Rips_complex_interface * thisptr - cdef Rips_complex_persistence_interface * pcohptr + cdef Rips_complex_interface * thisptr # Fake constructor that does nothing but documenting the constructor - def __init__(self, points=[], off_file='', max_dimension=3, - max_edge_length=float('inf')): + def __init__(self, points=[], off_file='', max_edge_length=float('inf')): """RipsComplex constructor. :param points: A list of points in d-Dimension. @@ -95,291 +72,40 @@ cdef class RipsComplex: :param off_file: An OFF file style name. :type off_file: string - :param max_dimension: Maximum dimension of the complex to be expanded. - :type max_dimension: int - :param max_edge_length: Maximum edge length value (rips radius). - :type max_edge_length: double + :param max_edge_length: Rips value. + :type max_edge_length: int """ # The real cython constructor - def __cinit__(self, points=[], off_file='', max_dimension=3, - max_edge_length=float('inf')): - self.thisptr = new Rips_complex_interface() - # Constructor from graph expansion + def __cinit__(self, points=[], off_file='', max_edge_length=float('inf')): if off_file is not '': if os.path.isfile(off_file): - self.thisptr.graph_expansion(off_file, max_dimension, - max_edge_length, True) + self.thisptr = new Rips_complex_interface(off_file, + max_edge_length, + True) else: print("file " + off_file + " not found.") else: - self.thisptr.graph_expansion(points, max_dimension, - max_edge_length) + self.thisptr = new Rips_complex_interface(points, max_edge_length) + def __dealloc__(self): if self.thisptr != NULL: del self.thisptr - if self.pcohptr != NULL: - del self.pcohptr def __is_defined(self): """Returns true if RipsComplex pointer is not NULL. """ return self.thisptr != NULL - def __is_persistence_defined(self): - """Returns true if Persistence pointer is not NULL. - """ - return self.pcohptr != NULL - - def get_filtration(self): - """This function returns the main simplicial complex filtration value. - - :returns: float -- the simplicial complex filtration value. - """ - return self.thisptr.filtration() - - def filtration(self, simplex): - """This function returns the simplicial complex filtration value for a - given N-simplex. - - :param simplex: The N-simplex, represented by a list of vertex. - :type simplex: list of int. - :returns: float -- the simplicial complex filtration value. - """ - return self.thisptr.simplex_filtration(simplex) - - def set_filtration(self, filtration): - """This function sets the main simplicial complex filtration value. - - :param filtration: The filtration value. - :type filtration: float. + def create_simplex_tree(self, max_dimension=1): """ - self.thisptr.set_filtration( filtration) - - def initialize_filtration(self): - """This function initializes and sorts the simplicial complex - filtration vector. - - .. note:: - - This function must be launched before persistence, betti_numbers, - persistent_betti_numbers or get_filtered_tree after inserting or - removing simplices. - """ - self.thisptr.initialize_filtration() - - def num_vertices(self): - """This function returns the number of vertices of the simplicial - complex. - - :returns: int -- the simplicial complex number of vertices. - """ - return self.thisptr.num_vertices() - - def num_simplices(self): - """This function returns the number of simplices of the simplicial - complex. - - :returns: int -- the simplicial complex number of simplices. - """ - return self.thisptr.num_simplices() - - def dimension(self): - """This function returns the dimension of the simplicial complex. - - :returns: int -- the simplicial complex dimension. - """ - return self.thisptr.dimension() - - def set_dimension(self, dimension): - """This function sets the dimension of the simplicial complex. - - :param dimension: The new dimension value. - :type dimension: int. - """ - self.thisptr.set_dimension(dimension) - - def find(self, simplex): - """This function returns if the N-simplex was found in the simplicial - complex or not. - - :param simplex: The N-simplex to find, represented by a list of vertex. - :type simplex: list of int. - :returns: bool -- true if the simplex was found, false otherwise. - """ - cdef vector[int] complex - for i in simplex: - complex.push_back(i) - return self.thisptr.find_simplex(complex) - - def insert(self, simplex, filtration=0.0): - """This function inserts the given N-simplex with the given filtration - value (default value is '0.0'). - - :param simplex: The N-simplex to insert, represented by a list of - vertex. - :type simplex: list of int. - :param filtration: The filtration value of the simplex. - :type filtration: float. - :returns: bool -- true if the simplex was found, false otherwise. - """ - cdef vector[int] complex - for i in simplex: - complex.push_back(i) - return self.thisptr.insert_simplex_and_subfaces(complex, - filtration) - - def get_filtered_tree(self): - """This function returns the tree sorted by increasing filtration - values. - - :returns: list of tuples(simplex, filtration) -- the tree sorted by - increasing filtration values. - """ - cdef vector[pair[vector[int], double]] coface_tree \ - = self.thisptr.get_filtered_tree() - ct = [] - for filtered_complex in coface_tree: - v = [] - for vertex in filtered_complex.first: - v.append(vertex) - ct.append((v, filtered_complex.second)) - return ct - - def get_skeleton_tree(self, dimension): - """This function returns the tree skeleton of a maximum given - dimension. - - :param dimension: The skeleton dimension value. - :type dimension: int. - :returns: list of tuples(simplex, filtration) -- the skeleton tree - of a maximum dimension. - """ - cdef vector[pair[vector[int], double]] coface_tree \ - = self.thisptr.get_skeleton_tree(dimension) - ct = [] - for filtered_complex in coface_tree: - v = [] - for vertex in filtered_complex.first: - v.append(vertex) - ct.append((v, filtered_complex.second)) - return ct - - def get_star_tree(self, simplex): - """This function returns the star tree of a given N-simplex. - - :param simplex: The N-simplex, represented by a list of vertex. - :type simplex: list of int. - :returns: list of tuples(simplex, filtration) -- the star tree of a - simplex. - """ - cdef vector[int] complex - for i in simplex: - complex.push_back(i) - cdef vector[pair[vector[int], double]] coface_tree \ - = self.thisptr.get_star_tree(complex) - ct = [] - for filtered_complex in coface_tree: - v = [] - for vertex in filtered_complex.first: - v.append(vertex) - ct.append((v, filtered_complex.second)) - return ct - - def get_coface_tree(self, simplex, codimension): - """This function returns the coface tree of a given N-simplex with a - given codimension. - - :param simplex: The N-simplex, represented by a list of vertex. - :type simplex: list of int. - :param codimension: The codimension. If codimension = 0, all cofaces - are returned (equivalent of get_star_tree function) - :type codimension: int. - :returns: list of tuples(simplex, filtration) -- the coface tree of a - simplex. - """ - cdef vector[int] complex - for i in simplex: - complex.push_back(i) - cdef vector[pair[vector[int], double]] coface_tree \ - = self.thisptr.get_coface_tree(complex, codimension) - ct = [] - for filtered_complex in coface_tree: - v = [] - for vertex in filtered_complex.first: - v.append(vertex) - ct.append((v, filtered_complex.second)) - return ct - - def remove_maximal_simplex(self, simplex): - """This function removes a given maximal N-simplex from the simplicial - complex. - - :param simplex: The N-simplex, represented by a list of vertex. - :type simplex: list of int. - """ - self.thisptr.remove_maximal_simplex(simplex) - - def persistence(self, homology_coeff_field=11, min_persistence=0): - """This function returns the persistence of the simplicial complex. - - :param homology_coeff_field: The homology coefficient field. Must be a - prime number - :type homology_coeff_field: int. - :param min_persistence: The minimum persistence value to take into - account (strictly greater than min_persistence). Default value is - 0.0. - Sets min_persistence to -1.0 to see all values. - :type min_persistence: float. - :note: list of pairs(dimension, pair(birth, death)) -- the - persistence of the simplicial complex. - """ - if self.pcohptr != NULL: - del self.pcohptr - self.pcohptr = new Rips_complex_persistence_interface(self.thisptr) - cdef vector[pair[int, pair[double, double]]] persistence_result - if self.pcohptr != NULL: - persistence_result = self.pcohptr.get_persistence(homology_coeff_field, min_persistence) - return persistence_result - - def betti_numbers(self): - """This function returns the Betti numbers of the simplicial complex. - - :returns: list of int -- The Betti numbers ([B0, B1, ..., Bn]). - - :note: betti_numbers function requires persistence function to be - launched first. - """ - cdef vector[int] bn_result - if self.pcohptr != NULL: - bn_result = self.pcohptr.betti_numbers() - else: - print("betti_numbers function requires persistence function" - " to be launched first.") - return bn_result - - def persistent_betti_numbers(self, from_value, to_value): - """This function returns the persistent Betti numbers of the - simplicial complex. - - :param from_value: The persistence birth limit to be added in the - numbers (persistent birth <= from_value). - :type from_value: float. - :param to_value: The persistence death limit to be added in the - numbers (persistent death > to_value). - :type to_value: float. - - :returns: list of int -- The persistent Betti numbers ([B0, B1, ..., - Bn]). - - :note: persistent_betti_numbers function requires persistence - function to be launched first. + :param max_dimension: graph expansion for rips until this given maximal + dimension. + :type max_dimension: int + :returns: A simplex tree created from the Delaunay Triangulation. + :rtype: SimplexTree """ - cdef vector[int] pbn_result - if self.pcohptr != NULL: - pbn_result = self.pcohptr.persistent_betti_numbers(from_value, to_value) - else: - print("persistent_betti_numbers function requires persistence function" - " to be launched first.") - return pbn_result + simplex_tree = SimplexTree() + self.thisptr.create_simplex_tree(simplex_tree.thisptr, max_dimension) + return simplex_tree diff --git a/src/cython/doc/persistent_cohomology_sum.rst b/src/cython/doc/persistent_cohomology_sum.rst index b306b3d4..cf3029fc 100644 --- a/src/cython/doc/persistent_cohomology_sum.rst +++ b/src/cython/doc/persistent_cohomology_sum.rst @@ -21,8 +21,5 @@ | :doc:`persistent_cohomology_user` | Please refer to each data structure that contains persistence | | | feature for reference: | | | | -| | * :doc:`alpha_complex_ref` | -| | * :doc:`cubical_complex_ref` | | | * :doc:`simplex_tree_ref` | -| | * :doc:`witness_complex_ref` | +---------------------------------------------+----------------------------------------------------------------------+ diff --git a/src/cython/doc/persistent_cohomology_user.rst b/src/cython/doc/persistent_cohomology_user.rst index 33b19ce2..ca936754 100644 --- a/src/cython/doc/persistent_cohomology_user.rst +++ b/src/cython/doc/persistent_cohomology_user.rst @@ -11,10 +11,7 @@ Definition | :doc:`persistent_cohomology_user` | Please refer to each data structure that contains persistence | | | feature for reference: | | | | -| | * :doc:`alpha_complex_ref` | -| | * :doc:`cubical_complex_ref` | | | * :doc:`simplex_tree_ref` | -| | * :doc:`witness_complex_ref` | +---------------------------------------------+----------------------------------------------------------------------+ diff --git a/src/cython/example/mini_simplex_tree_example.py b/src/cython/example/mini_simplex_tree_example.py deleted file mode 100755 index 7b65a9d6..00000000 --- a/src/cython/example/mini_simplex_tree_example.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python - -import gudhi - -"""This file is part of the Gudhi Library. The Gudhi library - (Geometric Understanding in Higher Dimensions) is a generic C++ - library for computational topology. - - Author(s): Vincent Rouvreau - - Copyright (C) 2016 INRIA - - 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. - - 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. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -""" - -__author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA" -__license__ = "GPL v3" - -print("#####################################################################") -print("MiniSimplexTree creation from insertion") - -""" Complex to build. - 1 3 - o---o - /X\ / - o---o o - 2 0 4 -""" - -triangle012 = [0, 1, 2] -edge03 = [0, 3] -edge13 = [1, 3] -vertex4 = [4] -mini_st = gudhi.MiniSimplexTree() -mini_st.insert(triangle012) -mini_st.insert(edge03) -mini_st.insert(edge13) -mini_st.insert(vertex4) - -# FIXME: Remove this line -mini_st.set_dimension(2) - -# initialize_filtration required before plain_homology -mini_st.initialize_filtration() - -print("persistence(homology_coeff_field=2)=") -print(mini_st.persistence(homology_coeff_field=2)) - -edge02 = [0, 2] -if mini_st.find(edge02): - # Only coface is 012 - print("coface(edge02,1)=", mini_st.get_coface_tree(edge02, 1)) - -if mini_st.get_coface_tree(triangle012, 1) == []: - # Precondition: Check the simplex has no coface before removing it. - mini_st.remove_maximal_simplex(triangle012) - -# initialize_filtration required after removing -mini_st.initialize_filtration() - -print("filtered_tree after triangle012 removal =", mini_st.get_filtered_tree()) diff --git a/src/cython/example/rips_complex_diagram_persistence_with_pandas_interface_example.py b/src/cython/example/rips_complex_diagram_persistence_with_pandas_interface_example.py index bcf2fbcb..8af1b767 100755 --- a/src/cython/example/rips_complex_diagram_persistence_with_pandas_interface_example.py +++ b/src/cython/example/rips_complex_diagram_persistence_with_pandas_interface_example.py @@ -53,16 +53,17 @@ message = "RipsComplex with max_edge_length=" + repr(args.max_edge_length) print(message) rips_complex = gudhi.RipsComplex(points=points.values, - max_dimension=len(points.values[0]), max_edge_length=args.max_edge_length) + max_edge_length=args.max_edge_length) -message = "Number of simplices=" + repr(rips_complex.num_simplices()) +simplex_tree = rips_complex.create_simplex_tree(max_dimension=len(points.values[0])) + +message = "Number of simplices=" + repr(simplex_tree.num_simplices()) print(message) -rips_complex.initialize_filtration() -diag = rips_complex.persistence() +diag = simplex_tree.persistence() print("betti_numbers()=") -print(rips_complex.betti_numbers()) +print(simplex_tree.betti_numbers()) if args.no_diagram == False: gudhi.diagram_persistence(diag) diff --git a/src/cython/example/rips_complex_from_points_example.py b/src/cython/example/rips_complex_from_points_example.py index 1a22d8e3..df6252cd 100755 --- a/src/cython/example/rips_complex_from_points_example.py +++ b/src/cython/example/rips_complex_from_points_example.py @@ -31,8 +31,10 @@ __license__ = "GPL v3" print("#####################################################################") print("RipsComplex creation from points") rips = gudhi.RipsComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]], - max_dimension=1, max_edge_length=42) + max_edge_length=42) -print("filtered_tree=", rips.get_filtered_tree()) -print("star([0])=", rips.get_star_tree([0])) -print("coface([0], 1)=", rips.get_coface_tree([0], 1)) +simplex_tree = rips.create_simplex_tree(max_dimension=1) + +print("filtered_tree=", simplex_tree.get_filtered_tree()) +print("star([0])=", simplex_tree.get_star_tree([0])) +print("coface([0], 1)=", simplex_tree.get_coface_tree([0], 1)) diff --git a/src/cython/example/rips_persistence_diagram.py b/src/cython/example/rips_persistence_diagram.py index fddea298..e485b2f5 100755 --- a/src/cython/example/rips_persistence_diagram.py +++ b/src/cython/example/rips_persistence_diagram.py @@ -31,9 +31,12 @@ __license__ = "GPL v3" print("#####################################################################") print("RipsComplex creation from points") rips = gudhi.RipsComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]], - max_dimension=1, max_edge_length=42) + max_edge_length=42) -diag = rips.persistence(homology_coeff_field=2, min_persistence=0) +simplex_tree = rips.create_simplex_tree(max_dimension=1) + + +diag = simplex_tree.persistence(homology_coeff_field=2, min_persistence=0) print("diag=", diag) gudhi.diagram_persistence(diag) diff --git a/src/cython/gudhi.pyx.in b/src/cython/gudhi.pyx.in index 60f4c30b..5dcb9d48 100644 --- a/src/cython/gudhi.pyx.in +++ b/src/cython/gudhi.pyx.in @@ -25,7 +25,6 @@ __copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" include "cython/simplex_tree.pyx" -include "cython/mini_simplex_tree.pyx" include "cython/rips_complex.pyx" include "cython/cubical_complex.pyx" include "cython/periodic_cubical_complex.pyx" diff --git a/src/cython/include/Alpha_complex_interface.h b/src/cython/include/Alpha_complex_interface.h index 81761c77..9f308ae9 100644 --- a/src/cython/include/Alpha_complex_interface.h +++ b/src/cython/include/Alpha_complex_interface.h @@ -29,9 +29,9 @@ #include "Simplex_tree_interface.h" -#include -#include // std::pair #include +#include +#include namespace Gudhi { @@ -40,11 +40,6 @@ namespace alpha_complex { class Alpha_complex_interface { using Dynamic_kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >; using Point_d = Dynamic_kernel::Point_d; - typedef typename Simplex_tree<>::Simplex_handle Simplex_handle; - typedef typename std::pair Insertion_result; - using Simplex = std::vector; - using Filtered_complex = std::pair; - using Complex_tree = std::vector; typedef typename Simplex_tree<>::Simplex_key Simplex_key; diff --git a/src/cython/include/Cubical_complex_interface.h b/src/cython/include/Cubical_complex_interface.h index 5d17ff6b..4c53523b 100644 --- a/src/cython/include/Cubical_complex_interface.h +++ b/src/cython/include/Cubical_complex_interface.h @@ -27,9 +27,9 @@ #include #include -#include -#include // std::pair #include +#include +#include namespace Gudhi { diff --git a/src/cython/include/Rips_complex_interface.h b/src/cython/include/Rips_complex_interface.h new file mode 100644 index 00000000..7e897b1d --- /dev/null +++ b/src/cython/include/Rips_complex_interface.h @@ -0,0 +1,70 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Vincent Rouvreau + * + * Copyright (C) 2016 INRIA + * + * 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. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef RIPS_COMPLEX_INTERFACE_H +#define RIPS_COMPLEX_INTERFACE_H + +#include +#include +#include +#include + +#include "Simplex_tree_interface.h" + +#include +#include +#include // std::pair +#include + +namespace Gudhi { + +namespace rips_complex { + +class Rips_complex_interface { + using Point_d = std::vector; + + public: + Rips_complex_interface(std::vector>&points, double threshold) { + rips_complex_ = new Rips_complex::Filtration_value>(points, threshold, + Euclidean_distance()); + } + + Rips_complex_interface(std::string off_file_name, double threshold, bool from_file = true) { + Gudhi::Points_off_reader off_reader(off_file_name); + rips_complex_ = new Rips_complex::Filtration_value>(off_reader.get_point_cloud(), + threshold, Euclidean_distance()); + } + + void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, int dim_max) { + rips_complex_->create_complex(*simplex_tree, dim_max); + simplex_tree->initialize_filtration(); + } + + private: + Rips_complex::Filtration_value>* rips_complex_; +}; + +} // namespace rips_complex + +} // namespace Gudhi + +#endif // RIPS_COMPLEX_INTERFACE_H diff --git a/src/cython/include/Simplex_tree_interface.h b/src/cython/include/Simplex_tree_interface.h index 8e9dd966..19e02ca4 100644 --- a/src/cython/include/Simplex_tree_interface.h +++ b/src/cython/include/Simplex_tree_interface.h @@ -30,15 +30,17 @@ #include "Persistent_cohomology_interface.h" +#include #include #include // std::pair -#include namespace Gudhi { template class Simplex_tree_interface : public Simplex_tree { public: + typedef typename Simplex_tree::Filtration_value Filtration_value; + typedef typename Simplex_tree::Vertex_handle Vertex_handle; typedef typename Simplex_tree::Simplex_handle Simplex_handle; typedef typename std::pair Insertion_result; using Simplex = std::vector; @@ -115,42 +117,12 @@ class Simplex_tree_interface : public Simplex_tree { return coface_tree; } - void graph_expansion(std::vector>&points, int max_dimension, double max_edge_length) { - Graph_t prox_graph = compute_proximity_graph(points, max_edge_length, euclidean_distance>); - Simplex_tree::insert_graph(prox_graph); - Simplex_tree::expansion(max_dimension); - Simplex_tree::initialize_filtration(); - } - - void graph_expansion(std::string& off_file_name, int max_dimension, double max_edge_length, bool from_file=true) { - Gudhi::Points_off_reader> off_reader(off_file_name); - // Check the read operation was correct - if (!off_reader.is_valid()) { - std::cerr << "Unable to read file " << off_file_name << std::endl; - } else { - std::vector> points = off_reader.get_point_cloud(); - Graph_t prox_graph = compute_proximity_graph(points, max_edge_length, - euclidean_distance>); - Simplex_tree::insert_graph(prox_graph); - Simplex_tree::expansion(max_dimension); - Simplex_tree::initialize_filtration(); - } - } - void create_persistence(Gudhi::Persistent_cohomology_interface>* pcoh) { pcoh = new Gudhi::Persistent_cohomology_interface>(*this); } }; -struct Simplex_tree_options_mini : Simplex_tree_options_full_featured { - // Not doing persistence, so we don't need those - static const bool store_key = true; - static const bool store_filtration = false; - // I have few vertices - typedef short Vertex_handle; -}; - } // namespace Gudhi #endif // SIMPLEX_TREE_INTERFACE_H diff --git a/src/cython/include/Subsampling_interface.h b/src/cython/include/Subsampling_interface.h index 9340cd86..fb047441 100644 --- a/src/cython/include/Subsampling_interface.h +++ b/src/cython/include/Subsampling_interface.h @@ -29,8 +29,9 @@ #include #include -#include #include +#include +#include namespace Gudhi { diff --git a/src/cython/include/Tangential_complex_interface.h b/src/cython/include/Tangential_complex_interface.h index 9da32757..7c774c73 100644 --- a/src/cython/include/Tangential_complex_interface.h +++ b/src/cython/include/Tangential_complex_interface.h @@ -41,11 +41,6 @@ namespace tangential_complex { class Tangential_complex_interface { using Dynamic_kernel = CGAL::Epick_d< CGAL::Dynamic_dimension_tag >; using Point_d = Dynamic_kernel::Point_d; - typedef typename Simplex_tree<>::Simplex_handle Simplex_handle; - typedef typename std::pair Insertion_result; - using Simplex = std::vector; - using Filtered_complex = std::pair; - using Complex_tree = std::vector; using TC = Tangential_complex; public: diff --git a/src/cython/include/Witness_complex_interface.h b/src/cython/include/Witness_complex_interface.h index ab99adf5..a753bc1d 100644 --- a/src/cython/include/Witness_complex_interface.h +++ b/src/cython/include/Witness_complex_interface.h @@ -40,6 +40,8 @@ namespace witness_complex { class Witness_complex_interface { typedef typename Simplex_tree<>::Simplex_handle Simplex_handle; + typedef typename Simplex_tree<>::Filtration_value Filtration_value; + typedef typename Simplex_tree<>::Vertex_handle Vertex_handle; typedef typename std::pair Insertion_result; using Simplex = std::vector; using Filtered_complex = std::pair; @@ -51,7 +53,7 @@ class Witness_complex_interface { std::vector > knn; std::vector> landmarks; Gudhi::subsampling::pick_n_random_points(points, number_of_landmarks, std::back_inserter(landmarks)); - Gudhi::witness_complex::construct_closest_landmark_table(points, landmarks, knn); + Gudhi::witness_complex::construct_closest_landmark_table(points, landmarks, knn); Gudhi::witness_complex::witness_complex(knn, number_of_landmarks, points[0].size(), simplex_tree_); } diff --git a/src/cython/test/test_mini_simplex_tree.py b/src/cython/test/test_mini_simplex_tree.py deleted file mode 100755 index e44bfdbc..00000000 --- a/src/cython/test/test_mini_simplex_tree.py +++ /dev/null @@ -1,50 +0,0 @@ -from gudhi import MiniSimplexTree - -"""This file is part of the Gudhi Library. The Gudhi library - (Geometric Understanding in Higher Dimensions) is a generic C++ - library for computational topology. - - Author(s): Vincent Rouvreau - - Copyright (C) 2016 INRIA - - 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. - - 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. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -""" - -__author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA" -__license__ = "GPL v3" - - -def test_mini(): - triangle012 = [0, 1, 2] - edge03 = [0, 3] - mini_st = MiniSimplexTree() - assert mini_st.__is_defined() == True - assert mini_st.__is_persistence_defined() == False - assert mini_st.insert(triangle012) == True - assert mini_st.insert(edge03) == True - # FIXME: Remove this line - mini_st.set_dimension(2) - - edge02 = [0, 2] - assert mini_st.find(edge02) == True - assert mini_st.get_coface_tree(edge02, 1) == \ - [([0, 1, 2], 0.0)] - - # remove_maximal_simplex test - assert mini_st.get_coface_tree(triangle012, 1) == [] - mini_st.remove_maximal_simplex(triangle012) - assert mini_st.find(edge02) == True - assert mini_st.find(triangle012) == False diff --git a/src/cython/test/test_rips_complex.py b/src/cython/test/test_rips_complex.py index 877289cf..687e8529 100755 --- a/src/cython/test/test_rips_complex.py +++ b/src/cython/test/test_rips_complex.py @@ -30,36 +30,39 @@ __license__ = "GPL v3" def test_empty_rips(): rips_complex = RipsComplex() assert rips_complex.__is_defined() == True - assert rips_complex.__is_persistence_defined() == False def test_rips(): point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] - rips_complex = RipsComplex(points=point_list, max_dimension=1, - max_edge_length=42) - assert rips_complex.__is_defined() == True - assert rips_complex.__is_persistence_defined() == False + rips_complex = RipsComplex(points=point_list, max_edge_length=42) + + simplex_tree = rips_complex.create_simplex_tree(max_dimension=1) + + assert simplex_tree.__is_defined() == True + assert simplex_tree.__is_persistence_defined() == False - assert rips_complex.num_simplices() == 10 - assert rips_complex.num_vertices() == 4 + assert simplex_tree.num_simplices() == 10 + assert simplex_tree.num_vertices() == 4 - assert rips_complex.get_filtered_tree() == \ + assert simplex_tree.get_filtered_tree() == \ [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0), ([0, 1], 1.0), ([0, 2], 1.0), ([1, 3], 1.0), ([2, 3], 1.0), ([1, 2], 1.4142135623730951), ([0, 3], 1.4142135623730951)] - assert rips_complex.get_star_tree([0]) == \ + assert simplex_tree.get_star_tree([0]) == \ [([0], 0.0), ([0, 1], 1.0), ([0, 2], 1.0), ([0, 3], 1.4142135623730951)] - assert rips_complex.get_coface_tree([0], 1) == \ + assert simplex_tree.get_coface_tree([0], 1) == \ [([0, 1], 1.0), ([0, 2], 1.0), ([0, 3], 1.4142135623730951)] def test_filtered_rips(): point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] - filtered_rips = RipsComplex(points=point_list, max_dimension=1, - max_edge_length=1.0) - assert filtered_rips.__is_defined() == True - assert filtered_rips.__is_persistence_defined() == False + filtered_rips = RipsComplex(points=point_list, max_edge_length=1.0) + + simplex_tree = filtered_rips.create_simplex_tree(max_dimension=1) + + assert simplex_tree.__is_defined() == True + assert simplex_tree.__is_persistence_defined() == False - assert filtered_rips.num_simplices() == 8 - assert filtered_rips.num_vertices() == 4 + assert simplex_tree.num_simplices() == 8 + assert simplex_tree.num_vertices() == 4 -- cgit v1.2.3 From 10411aae9845d28d36a9d4394bd668ed84d540f1 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 20 Mar 2017 13:44:20 +0000 Subject: constify interfaces git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@2203 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 55cf020d2a7989dc4e7125bcf6f91443aad4dda1 --- src/cython/include/Alpha_complex_interface.h | 4 ++-- src/cython/include/Bottleneck_distance_interface.h | 8 ++++---- .../Euclidean_strong_witness_complex_interface.h | 6 ++++-- .../include/Euclidean_witness_complex_interface.h | 3 ++- src/cython/include/Off_reader_interface.h | 2 +- src/cython/include/Rips_complex_interface.h | 4 ++-- .../include/Strong_witness_complex_interface.h | 2 +- src/cython/include/Subsampling_interface.h | 24 ++++++++++++++-------- src/cython/include/Tangential_complex_interface.h | 4 ++-- src/cython/include/Witness_complex_interface.h | 2 +- 10 files changed, 35 insertions(+), 24 deletions(-) (limited to 'src/cython/include/Tangential_complex_interface.h') diff --git a/src/cython/include/Alpha_complex_interface.h b/src/cython/include/Alpha_complex_interface.h index bcd2849b..f11a464b 100644 --- a/src/cython/include/Alpha_complex_interface.h +++ b/src/cython/include/Alpha_complex_interface.h @@ -42,11 +42,11 @@ class Alpha_complex_interface { using Point_d = Dynamic_kernel::Point_d; public: - Alpha_complex_interface(std::vector>&points) { + Alpha_complex_interface(const std::vector>& points) { alpha_complex_ = new Alpha_complex(points); } - Alpha_complex_interface(std::string off_file_name, bool from_file = true) { + Alpha_complex_interface(const std::string& off_file_name, bool from_file = true) { alpha_complex_ = new Alpha_complex(off_file_name); } diff --git a/src/cython/include/Bottleneck_distance_interface.h b/src/cython/include/Bottleneck_distance_interface.h index b814661e..6819734b 100644 --- a/src/cython/include/Bottleneck_distance_interface.h +++ b/src/cython/include/Bottleneck_distance_interface.h @@ -34,14 +34,14 @@ namespace Gudhi { namespace persistence_diagram { // bottleneck_distance function renamed for the python function can be called bottleneck_dstance - double bottleneck(const std::vector> &diag1, - const std::vector> &diag2, + double bottleneck(const std::vector>& diag1, + const std::vector>& diag2, double e) { return bottleneck_distance(diag1, diag2, e); } - double bottleneck(const std::vector> &diag1, - const std::vector> &diag2) { + double bottleneck(const std::vector>& diag1, + const std::vector>& diag2) { return bottleneck_distance(diag1, diag2); } diff --git a/src/cython/include/Euclidean_strong_witness_complex_interface.h b/src/cython/include/Euclidean_strong_witness_complex_interface.h index 739014b9..fc88a82d 100644 --- a/src/cython/include/Euclidean_strong_witness_complex_interface.h +++ b/src/cython/include/Euclidean_strong_witness_complex_interface.h @@ -47,13 +47,15 @@ class Euclidean_strong_witness_complex_interface { typedef typename Simplex_tree<>::Simplex_key Simplex_key; public: - Euclidean_strong_witness_complex_interface(std::vector>&landmarks, std::vector>&witnesses) + Euclidean_strong_witness_complex_interface(const std::vector>& landmarks, + const std::vector>& witnesses) : landmarks_(landmarks.begin(), landmarks.end()), witnesses_(witnesses.begin(), witnesses.end()), witness_complex_(landmarks_, witnesses_) { } - void create_simplex_tree(Gudhi::Simplex_tree<>* simplex_tree, double max_alpha_square, std::size_t limit_dimension) { + void create_simplex_tree(Gudhi::Simplex_tree<>* simplex_tree, double max_alpha_square, + std::size_t limit_dimension) { witness_complex_.create_complex(*simplex_tree, max_alpha_square, limit_dimension); simplex_tree->initialize_filtration(); } diff --git a/src/cython/include/Euclidean_witness_complex_interface.h b/src/cython/include/Euclidean_witness_complex_interface.h index efa8885f..a1ec68aa 100644 --- a/src/cython/include/Euclidean_witness_complex_interface.h +++ b/src/cython/include/Euclidean_witness_complex_interface.h @@ -47,7 +47,8 @@ class Euclidean_witness_complex_interface { typedef typename Simplex_tree<>::Simplex_key Simplex_key; public: - Euclidean_witness_complex_interface(std::vector>&landmarks, std::vector>&witnesses) + Euclidean_witness_complex_interface(const std::vector>& landmarks, + const std::vector>& witnesses) : landmarks_(landmarks.begin(), landmarks.end()), witnesses_(witnesses.begin(), witnesses.end()), witness_complex_(landmarks_, witnesses_) { diff --git a/src/cython/include/Off_reader_interface.h b/src/cython/include/Off_reader_interface.h index 257331f8..97d64d3e 100644 --- a/src/cython/include/Off_reader_interface.h +++ b/src/cython/include/Off_reader_interface.h @@ -31,7 +31,7 @@ namespace Gudhi { -std::vector> read_points_from_OFF_file(std::string& off_file) { +std::vector> read_points_from_OFF_file(const std::string& off_file) { Gudhi::Points_off_reader> off_reader(off_file); return off_reader.get_point_cloud(); } diff --git a/src/cython/include/Rips_complex_interface.h b/src/cython/include/Rips_complex_interface.h index 9295906c..01df5366 100644 --- a/src/cython/include/Rips_complex_interface.h +++ b/src/cython/include/Rips_complex_interface.h @@ -45,7 +45,7 @@ class Rips_complex_interface { using Distance_matrix = std::vector::Filtration_value>>; public: - Rips_complex_interface(std::vector>&values, double threshold, bool euclidean) { + Rips_complex_interface(const std::vector>& values, double threshold, bool euclidean) { if (euclidean) { // Rips construction where values is a vector of points rips_complex_ = new Rips_complex::Filtration_value>(values, threshold, @@ -57,7 +57,7 @@ class Rips_complex_interface { } } - Rips_complex_interface(std::string file_name, double threshold, bool euclidean, bool from_file = true) { + Rips_complex_interface(const std::string& file_name, double threshold, bool euclidean, bool from_file = true) { if (euclidean) { // Rips construction where file_name is an OFF file Gudhi::Points_off_reader off_reader(file_name); diff --git a/src/cython/include/Strong_witness_complex_interface.h b/src/cython/include/Strong_witness_complex_interface.h index 5081ec2d..70e78a2a 100644 --- a/src/cython/include/Strong_witness_complex_interface.h +++ b/src/cython/include/Strong_witness_complex_interface.h @@ -42,7 +42,7 @@ class Strong_witness_complex_interface { using Nearest_landmark_table = std::vector; public: - Strong_witness_complex_interface(Nearest_landmark_table& nlt) { + Strong_witness_complex_interface(const Nearest_landmark_table& nlt) { witness_complex_ = new Strong_witness_complex(nlt); } diff --git a/src/cython/include/Subsampling_interface.h b/src/cython/include/Subsampling_interface.h index fb047441..5fc16767 100644 --- a/src/cython/include/Subsampling_interface.h +++ b/src/cython/include/Subsampling_interface.h @@ -42,7 +42,8 @@ using Subsampling_point_d = Subsampling_dynamic_kernel::Point_d; using Subsampling_ft = Subsampling_dynamic_kernel::FT; // ------ choose_n_farthest_points ------ -std::vector> subsampling_n_farthest_points(std::vector>& points, unsigned nb_points) { +std::vector> subsampling_n_farthest_points(const std::vector>& points, + unsigned nb_points) { std::vector> landmarks; Subsampling_dynamic_kernel k; choose_n_farthest_points(k, points, nb_points, std::back_inserter(landmarks)); @@ -50,7 +51,8 @@ std::vector> subsampling_n_farthest_points(std::vector> subsampling_n_farthest_points(std::vector>& points, unsigned nb_points, unsigned starting_point) { +std::vector> subsampling_n_farthest_points(const std::vector>& points, + unsigned nb_points, unsigned starting_point) { std::vector> landmarks; Subsampling_dynamic_kernel k; choose_n_farthest_points(k, points, nb_points, starting_point, std::back_inserter(landmarks)); @@ -58,34 +60,39 @@ std::vector> subsampling_n_farthest_points(std::vector> subsampling_n_farthest_points_from_file(std::string& off_file, unsigned nb_points) { +std::vector> subsampling_n_farthest_points_from_file(const std::string& off_file, + unsigned nb_points) { Gudhi::Points_off_reader> off_reader(off_file); std::vector> points = off_reader.get_point_cloud(); return subsampling_n_farthest_points(points, nb_points); } -std::vector> subsampling_n_farthest_points_from_file(std::string& off_file, unsigned nb_points, unsigned starting_point) { +std::vector> subsampling_n_farthest_points_from_file(const std::string& off_file, + unsigned nb_points, unsigned starting_point) { Gudhi::Points_off_reader> off_reader(off_file); std::vector> points = off_reader.get_point_cloud(); return subsampling_n_farthest_points(points, nb_points, starting_point); } // ------ pick_n_random_points ------ -std::vector> subsampling_n_random_points(std::vector>& points, unsigned nb_points) { +std::vector> subsampling_n_random_points(const std::vector>& points, + unsigned nb_points) { std::vector> landmarks; pick_n_random_points(points, nb_points, std::back_inserter(landmarks)); return landmarks; } -std::vector> subsampling_n_random_points_from_file(std::string& off_file, unsigned nb_points) { +std::vector> subsampling_n_random_points_from_file(const std::string& off_file, + unsigned nb_points) { Gudhi::Points_off_reader> off_reader(off_file); std::vector> points = off_reader.get_point_cloud(); return subsampling_n_random_points(points, nb_points); } // ------ sparsify_point_set ------ -std::vector> subsampling_sparsify_points(std::vector>& points, double min_squared_dist) { +std::vector> subsampling_sparsify_points(const std::vector>& points, + double min_squared_dist) { std::vector input, output; for (auto point : points) input.push_back(Subsampling_point_d(point.size(), point.begin(), point.end())); @@ -98,7 +105,8 @@ std::vector> subsampling_sparsify_points(std::vector> subsampling_sparsify_points_from_file(std::string& off_file, double min_squared_dist) { +std::vector> subsampling_sparsify_points_from_file(const std::string& off_file, + double min_squared_dist) { Gudhi::Points_off_reader> off_reader(off_file); std::vector> points = off_reader.get_point_cloud(); return subsampling_sparsify_points(points, min_squared_dist); diff --git a/src/cython/include/Tangential_complex_interface.h b/src/cython/include/Tangential_complex_interface.h index 7c774c73..93d9bad7 100644 --- a/src/cython/include/Tangential_complex_interface.h +++ b/src/cython/include/Tangential_complex_interface.h @@ -44,7 +44,7 @@ class Tangential_complex_interface { using TC = Tangential_complex; public: - Tangential_complex_interface(std::vector>&points) { + Tangential_complex_interface(const std::vector>& points) { Dynamic_kernel k; unsigned intrisic_dim = 0; if (points.size() > 0) @@ -55,7 +55,7 @@ class Tangential_complex_interface { num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices(); } - Tangential_complex_interface(std::string off_file_name, bool from_file = true) { + Tangential_complex_interface(const std::string& off_file_name, bool from_file = true) { Gudhi::Points_off_reader off_reader(off_file_name); Dynamic_kernel k; unsigned intrisic_dim = 0; diff --git a/src/cython/include/Witness_complex_interface.h b/src/cython/include/Witness_complex_interface.h index 3761b43d..835b69ab 100644 --- a/src/cython/include/Witness_complex_interface.h +++ b/src/cython/include/Witness_complex_interface.h @@ -42,7 +42,7 @@ class Witness_complex_interface { using Nearest_landmark_table = std::vector; public: - Witness_complex_interface(Nearest_landmark_table& nlt) { + Witness_complex_interface(const Nearest_landmark_table& nlt) { witness_complex_ = new Witness_complex(nlt); } -- cgit v1.2.3 From 54ed7a649fd461880693f5e9985dc529ae72a39f Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 21 Mar 2017 13:45:53 +0000 Subject: Memory leaks Landmarks initialization were not correct git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@2213 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ab7e0adb6f36b2ccfd52a8c652c1ea35258a7aa1 --- src/cython/include/Alpha_complex_interface.h | 4 ++++ .../Euclidean_strong_witness_complex_interface.h | 22 +++++++++++++--------- .../include/Euclidean_witness_complex_interface.h | 22 +++++++++++++--------- .../include/Strong_witness_complex_interface.h | 4 ++++ src/cython/include/Tangential_complex_interface.h | 4 ++++ src/cython/include/Witness_complex_interface.h | 4 ++++ 6 files changed, 42 insertions(+), 18 deletions(-) (limited to 'src/cython/include/Tangential_complex_interface.h') diff --git a/src/cython/include/Alpha_complex_interface.h b/src/cython/include/Alpha_complex_interface.h index f11a464b..d74ff304 100644 --- a/src/cython/include/Alpha_complex_interface.h +++ b/src/cython/include/Alpha_complex_interface.h @@ -50,6 +50,10 @@ class Alpha_complex_interface { alpha_complex_ = new Alpha_complex(off_file_name); } + ~Alpha_complex_interface() { + delete alpha_complex_; + } + std::vector get_point(int vh) { std::vector vd; try { diff --git a/src/cython/include/Euclidean_strong_witness_complex_interface.h b/src/cython/include/Euclidean_strong_witness_complex_interface.h index fc88a82d..67d85e18 100644 --- a/src/cython/include/Euclidean_strong_witness_complex_interface.h +++ b/src/cython/include/Euclidean_strong_witness_complex_interface.h @@ -48,27 +48,32 @@ class Euclidean_strong_witness_complex_interface { public: Euclidean_strong_witness_complex_interface(const std::vector>& landmarks, - const std::vector>& witnesses) - : landmarks_(landmarks.begin(), landmarks.end()), - witnesses_(witnesses.begin(), witnesses.end()), - witness_complex_(landmarks_, witnesses_) { + const std::vector>& witnesses) { + landmarks_.reserve(landmarks.size()); + for(auto& landmark : landmarks) + landmarks_.emplace_back(landmark.begin(), landmark.end()); + witness_complex_ = new Euclidean_strong_witness_complex(landmarks_, witnesses); + } + + ~Euclidean_strong_witness_complex_interface() { + delete witness_complex_; } void create_simplex_tree(Gudhi::Simplex_tree<>* simplex_tree, double max_alpha_square, std::size_t limit_dimension) { - witness_complex_.create_complex(*simplex_tree, max_alpha_square, limit_dimension); + witness_complex_->create_complex(*simplex_tree, max_alpha_square, limit_dimension); simplex_tree->initialize_filtration(); } void create_simplex_tree(Gudhi::Simplex_tree<>* simplex_tree, double max_alpha_square) { - witness_complex_.create_complex(*simplex_tree, max_alpha_square); + witness_complex_->create_complex(*simplex_tree, max_alpha_square); simplex_tree->initialize_filtration(); } std::vector get_point(unsigned vh) { std::vector vd; if (vh < landmarks_.size()) { - Point_d ph = witness_complex_.get_point(vh); + Point_d ph = witness_complex_->get_point(vh); for (auto coord = ph.cartesian_begin(); coord < ph.cartesian_end(); coord++) vd.push_back(*coord); } @@ -77,8 +82,7 @@ class Euclidean_strong_witness_complex_interface { private: std::vector landmarks_; - std::vector witnesses_; - Euclidean_strong_witness_complex witness_complex_; + Euclidean_strong_witness_complex* witness_complex_; }; } // namespace witness_complex diff --git a/src/cython/include/Euclidean_witness_complex_interface.h b/src/cython/include/Euclidean_witness_complex_interface.h index a1ec68aa..a2db6a2d 100644 --- a/src/cython/include/Euclidean_witness_complex_interface.h +++ b/src/cython/include/Euclidean_witness_complex_interface.h @@ -48,26 +48,31 @@ class Euclidean_witness_complex_interface { public: Euclidean_witness_complex_interface(const std::vector>& landmarks, - const std::vector>& witnesses) - : landmarks_(landmarks.begin(), landmarks.end()), - witnesses_(witnesses.begin(), witnesses.end()), - witness_complex_(landmarks_, witnesses_) { + const std::vector>& witnesses) { + landmarks_.reserve(landmarks.size()); + for(auto& landmark : landmarks) + landmarks_.emplace_back(landmark.begin(), landmark.end()); + witness_complex_ = new Euclidean_witness_complex(landmarks_, witnesses); + } + + ~Euclidean_witness_complex_interface() { + delete witness_complex_; } void create_simplex_tree(Gudhi::Simplex_tree<>* simplex_tree, double max_alpha_square, std::size_t limit_dimension) { - witness_complex_.create_complex(*simplex_tree, max_alpha_square, limit_dimension); + witness_complex_->create_complex(*simplex_tree, max_alpha_square, limit_dimension); simplex_tree->initialize_filtration(); } void create_simplex_tree(Gudhi::Simplex_tree<>* simplex_tree, double max_alpha_square) { - witness_complex_.create_complex(*simplex_tree, max_alpha_square); + witness_complex_->create_complex(*simplex_tree, max_alpha_square); simplex_tree->initialize_filtration(); } std::vector get_point(unsigned vh) { std::vector vd; if (vh < landmarks_.size()) { - Point_d ph = witness_complex_.get_point(vh); + Point_d ph = witness_complex_->get_point(vh); for (auto coord = ph.cartesian_begin(); coord < ph.cartesian_end(); coord++) vd.push_back(*coord); } @@ -76,8 +81,7 @@ class Euclidean_witness_complex_interface { private: std::vector landmarks_; - std::vector witnesses_; - Euclidean_witness_complex witness_complex_; + Euclidean_witness_complex* witness_complex_; }; } // namespace witness_complex diff --git a/src/cython/include/Strong_witness_complex_interface.h b/src/cython/include/Strong_witness_complex_interface.h index 70e78a2a..83bf0f3c 100644 --- a/src/cython/include/Strong_witness_complex_interface.h +++ b/src/cython/include/Strong_witness_complex_interface.h @@ -46,6 +46,10 @@ class Strong_witness_complex_interface { witness_complex_ = new Strong_witness_complex(nlt); } + ~Strong_witness_complex_interface() { + delete witness_complex_; + } + void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, std::size_t limit_dimension) { witness_complex_->create_complex(*simplex_tree, max_alpha_square, limit_dimension); diff --git a/src/cython/include/Tangential_complex_interface.h b/src/cython/include/Tangential_complex_interface.h index 93d9bad7..2ca4c393 100644 --- a/src/cython/include/Tangential_complex_interface.h +++ b/src/cython/include/Tangential_complex_interface.h @@ -68,6 +68,10 @@ class Tangential_complex_interface { num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices(); } + ~Tangential_complex_interface() { + delete tangential_complex_; + } + std::vector get_point(unsigned vh) { std::vector vd; if (vh < tangential_complex_->number_of_vertices()) { diff --git a/src/cython/include/Witness_complex_interface.h b/src/cython/include/Witness_complex_interface.h index 835b69ab..4f2a903b 100644 --- a/src/cython/include/Witness_complex_interface.h +++ b/src/cython/include/Witness_complex_interface.h @@ -46,6 +46,10 @@ class Witness_complex_interface { witness_complex_ = new Witness_complex(nlt); } + ~Witness_complex_interface() { + delete witness_complex_; + } + void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, double max_alpha_square, std::size_t limit_dimension) { witness_complex_->create_complex(*simplex_tree, max_alpha_square, limit_dimension); -- cgit v1.2.3 From f48eae4cd7dc50dbbe0c8ec4f63bb98dda51a5d8 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 24 Mar 2017 06:20:50 +0000 Subject: Fix cpplint on cython interfaces git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@2229 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 41a958b1be51ac938b45b384cde7940a85e9dea0 --- .../doc/Intro_bottleneck_distance.h | 6 ++-- src/cython/include/Alpha_complex_interface.h | 6 ++-- src/cython/include/Bottleneck_distance_interface.h | 8 +++--- src/cython/include/Cubical_complex_interface.h | 8 ++---- .../Euclidean_strong_witness_complex_interface.h | 10 +++---- .../include/Euclidean_witness_complex_interface.h | 10 +++---- src/cython/include/Off_reader_interface.h | 6 ++-- .../include/Persistent_cohomology_interface.h | 32 +++++++++++----------- src/cython/include/Rips_complex_interface.h | 12 ++++---- src/cython/include/Simplex_tree_interface.h | 12 +++----- .../include/Strong_witness_complex_interface.h | 10 +++---- src/cython/include/Subsampling_interface.h | 8 ++---- src/cython/include/Tangential_complex_interface.h | 12 ++++---- src/cython/include/Witness_complex_interface.h | 9 +++--- 14 files changed, 68 insertions(+), 81 deletions(-) (limited to 'src/cython/include/Tangential_complex_interface.h') diff --git a/src/Bottleneck_distance/doc/Intro_bottleneck_distance.h b/src/Bottleneck_distance/doc/Intro_bottleneck_distance.h index 5223678d..3998fe8d 100644 --- a/src/Bottleneck_distance/doc/Intro_bottleneck_distance.h +++ b/src/Bottleneck_distance/doc/Intro_bottleneck_distance.h @@ -35,9 +35,9 @@ namespace persistence_diagram { * * \section bottleneckdefinition Definition * - * The bottleneck distance measures the similarity between two persistence diagrams. It is the shortest distance b for which there exists a perfect matching between - * the points of the two diagrams (completed with all the points on the diagonal in order to ignore cardinality mismatchs) such that - * any couple of matched points are at distance at most b. + * The bottleneck distance measures the similarity between two persistence diagrams. It is the shortest distance b for + * which there exists a perfect matching between the points of the two diagrams (completed with all the points on the + * diagonal in order to ignore cardinality mismatchs) such that any couple of matched points are at distance at most b. * * \image html perturb_pd.png On this picture, the red edges represent the matching. The bottleneck distance is the length of the longest edge. * diff --git a/src/cython/include/Alpha_complex_interface.h b/src/cython/include/Alpha_complex_interface.h index d74ff304..d47db71f 100644 --- a/src/cython/include/Alpha_complex_interface.h +++ b/src/cython/include/Alpha_complex_interface.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef ALPHA_COMPLEX_INTERFACE_H -#define ALPHA_COMPLEX_INTERFACE_H +#ifndef INCLUDE_ALPHA_COMPLEX_INTERFACE_H_ +#define INCLUDE_ALPHA_COMPLEX_INTERFACE_H_ #include #include @@ -79,4 +79,4 @@ class Alpha_complex_interface { } // namespace Gudhi -#endif // ALPHA_COMPLEX_INTERFACE_H +#endif // INCLUDE_ALPHA_COMPLEX_INTERFACE_H_ diff --git a/src/cython/include/Bottleneck_distance_interface.h b/src/cython/include/Bottleneck_distance_interface.h index 6819734b..d5fbf6ea 100644 --- a/src/cython/include/Bottleneck_distance_interface.h +++ b/src/cython/include/Bottleneck_distance_interface.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef BOTTLENECK_DISTANCE_INTERFACE_H -#define BOTTLENECK_DISTANCE_INTERFACE_H +#ifndef INCLUDE_BOTTLENECK_DISTANCE_INTERFACE_H_ +#define INCLUDE_BOTTLENECK_DISTANCE_INTERFACE_H_ #include @@ -45,9 +45,9 @@ namespace persistence_diagram { return bottleneck_distance(diag1, diag2); } -} // namespace alpha_complex +} // namespace persistence_diagram } // namespace Gudhi -#endif // BOTTLENECK_DISTANCE_INTERFACE_H +#endif // INCLUDE_BOTTLENECK_DISTANCE_INTERFACE_H_ diff --git a/src/cython/include/Cubical_complex_interface.h b/src/cython/include/Cubical_complex_interface.h index 4c53523b..7c0148f1 100644 --- a/src/cython/include/Cubical_complex_interface.h +++ b/src/cython/include/Cubical_complex_interface.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef CUBICAL_COMPLEX_INTERFACE_H -#define CUBICAL_COMPLEX_INTERFACE_H +#ifndef INCLUDE_CUBICAL_COMPLEX_INTERFACE_H_ +#define INCLUDE_CUBICAL_COMPLEX_INTERFACE_H_ #include #include @@ -38,7 +38,6 @@ namespace cubical_complex { template> class Cubical_complex_interface : public Bitmap_cubical_complex { public: - Cubical_complex_interface(const std::vector& dimensions, const std::vector& top_dimensional_cells) : Bitmap_cubical_complex(dimensions, top_dimensional_cells) { @@ -47,12 +46,11 @@ class Cubical_complex_interface : public Bitmap_cubical_complex(perseus_file.c_str()) { } - }; } // namespace cubical_complex } // namespace Gudhi -#endif // CUBICAL_COMPLEX_INTERFACE_H +#endif // INCLUDE_CUBICAL_COMPLEX_INTERFACE_H_ diff --git a/src/cython/include/Euclidean_strong_witness_complex_interface.h b/src/cython/include/Euclidean_strong_witness_complex_interface.h index 67d85e18..b9dd8177 100644 --- a/src/cython/include/Euclidean_strong_witness_complex_interface.h +++ b/src/cython/include/Euclidean_strong_witness_complex_interface.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef EUCLIDEAN_STRONG_WITNESS_COMPLEX_INTERFACE_H -#define EUCLIDEAN_STRONG_WITNESS_COMPLEX_INTERFACE_H +#ifndef INCLUDE_EUCLIDEAN_STRONG_WITNESS_COMPLEX_INTERFACE_H_ +#define INCLUDE_EUCLIDEAN_STRONG_WITNESS_COMPLEX_INTERFACE_H_ #include #include @@ -50,7 +50,7 @@ class Euclidean_strong_witness_complex_interface { Euclidean_strong_witness_complex_interface(const std::vector>& landmarks, const std::vector>& witnesses) { landmarks_.reserve(landmarks.size()); - for(auto& landmark : landmarks) + for (auto& landmark : landmarks) landmarks_.emplace_back(landmark.begin(), landmark.end()); witness_complex_ = new Euclidean_strong_witness_complex(landmarks_, witnesses); } @@ -87,7 +87,7 @@ class Euclidean_strong_witness_complex_interface { } // namespace witness_complex -} // namespace Gudhi +} // namespace Gudhi -#endif // EUCLIDEAN_STRONG_WITNESS_COMPLEX_INTERFACE_H +#endif // INCLUDE_EUCLIDEAN_STRONG_WITNESS_COMPLEX_INTERFACE_H_ diff --git a/src/cython/include/Euclidean_witness_complex_interface.h b/src/cython/include/Euclidean_witness_complex_interface.h index a2db6a2d..2a09b3b5 100644 --- a/src/cython/include/Euclidean_witness_complex_interface.h +++ b/src/cython/include/Euclidean_witness_complex_interface.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef EUCLIDEAN_WITNESS_COMPLEX_INTERFACE_H -#define EUCLIDEAN_WITNESS_COMPLEX_INTERFACE_H +#ifndef INCLUDE_EUCLIDEAN_WITNESS_COMPLEX_INTERFACE_H_ +#define INCLUDE_EUCLIDEAN_WITNESS_COMPLEX_INTERFACE_H_ #include #include @@ -50,7 +50,7 @@ class Euclidean_witness_complex_interface { Euclidean_witness_complex_interface(const std::vector>& landmarks, const std::vector>& witnesses) { landmarks_.reserve(landmarks.size()); - for(auto& landmark : landmarks) + for (auto& landmark : landmarks) landmarks_.emplace_back(landmark.begin(), landmark.end()); witness_complex_ = new Euclidean_witness_complex(landmarks_, witnesses); } @@ -86,7 +86,7 @@ class Euclidean_witness_complex_interface { } // namespace witness_complex -} // namespace Gudhi +} // namespace Gudhi -#endif // EUCLIDEAN_WITNESS_COMPLEX_INTERFACE_H +#endif // INCLUDE_EUCLIDEAN_WITNESS_COMPLEX_INTERFACE_H_ diff --git a/src/cython/include/Off_reader_interface.h b/src/cython/include/Off_reader_interface.h index 97d64d3e..0ca55500 100644 --- a/src/cython/include/Off_reader_interface.h +++ b/src/cython/include/Off_reader_interface.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef OFF_READER_INTERFACE_H -#define OFF_READER_INTERFACE_H +#ifndef INCLUDE_OFF_READER_INTERFACE_H_ +#define INCLUDE_OFF_READER_INTERFACE_H_ #include @@ -38,5 +38,5 @@ std::vector> read_points_from_OFF_file(const std::string& of } // namespace Gudhi -#endif // OFF_READER_INTERFACE_H +#endif // INCLUDE_OFF_READER_INTERFACE_H_ diff --git a/src/cython/include/Persistent_cohomology_interface.h b/src/cython/include/Persistent_cohomology_interface.h index 1ff0e09b..25c458d2 100644 --- a/src/cython/include/Persistent_cohomology_interface.h +++ b/src/cython/include/Persistent_cohomology_interface.h @@ -20,13 +20,14 @@ * along with this program. If not, see . */ -#ifndef PERSISTENT_COHOMOLOGY_INTERFACE_H -#define PERSISTENT_COHOMOLOGY_INTERFACE_H +#ifndef INCLUDE_PERSISTENT_COHOMOLOGY_INTERFACE_H_ +#define INCLUDE_PERSISTENT_COHOMOLOGY_INTERFACE_H_ #include #include #include // for std::pair +#include // for sort namespace Gudhi { @@ -34,12 +35,10 @@ template class Persistent_cohomology_interface : public persistent_cohomology::Persistent_cohomology { private: - /* * Compare two intervals by dimension, then by length. */ struct cmp_intervals_by_dim_then_length { - explicit cmp_intervals_by_dim_then_length(FilteredComplex * sc) : sc_(sc) { } @@ -55,23 +54,26 @@ persistent_cohomology::Persistent_cohomology(*stptr), stptr_(stptr) { } Persistent_cohomology_interface(FilteredComplex* stptr, bool persistence_dim_max) - : persistent_cohomology::Persistent_cohomology(*stptr, - persistence_dim_max), - stptr_(stptr) { } + : persistent_cohomology::Persistent_cohomology(*stptr, persistence_dim_max), + stptr_(stptr) { } - std::vector>> get_persistence(int homology_coeff_field, double min_persistence) { - persistent_cohomology::Persistent_cohomology::init_coefficients(homology_coeff_field); - persistent_cohomology::Persistent_cohomology::compute_persistent_cohomology(min_persistence); + std::vector>> get_persistence(int homology_coeff_field, + double min_persistence) { + persistent_cohomology::Persistent_cohomology::init_coefficients(homology_coeff_field); + persistent_cohomology::Persistent_cohomology::compute_persistent_cohomology(min_persistence); // Custom sort and output persistence cmp_intervals_by_dim_then_length cmp(stptr_); - auto persistent_pairs = persistent_cohomology::Persistent_cohomology::get_persistent_pairs(); + auto persistent_pairs = persistent_cohomology::Persistent_cohomology::get_persistent_pairs(); std::sort(std::begin(persistent_pairs), std::end(persistent_pairs), cmp); std::vector>> persistence; @@ -81,7 +83,6 @@ persistent_cohomology::Persistent_cohomologyfiltration(get<1>(pair))))); } return persistence; - } private: @@ -90,7 +91,6 @@ persistent_cohomology::Persistent_cohomology. */ -#ifndef RIPS_COMPLEX_INTERFACE_H -#define RIPS_COMPLEX_INTERFACE_H +#ifndef INCLUDE_RIPS_COMPLEX_INTERFACE_H_ +#define INCLUDE_RIPS_COMPLEX_INTERFACE_H_ #include #include @@ -53,7 +53,6 @@ class Rips_complex_interface { } else { // Rips construction where values is a distance matrix rips_complex_ = new Rips_complex::Filtration_value>(values, threshold); - } } @@ -65,11 +64,10 @@ class Rips_complex_interface { threshold, Euclidean_distance()); } else { // Rips construction where values is a distance matrix - Distance_matrix distances = read_lower_triangular_matrix_from_csv_file::Filtration_value>(file_name); + Distance_matrix distances = + read_lower_triangular_matrix_from_csv_file::Filtration_value>(file_name); rips_complex_ = new Rips_complex::Filtration_value>(distances, threshold); - } - } void create_simplex_tree(Simplex_tree_interface<>* simplex_tree, int dim_max) { @@ -85,4 +83,4 @@ class Rips_complex_interface { } // namespace Gudhi -#endif // RIPS_COMPLEX_INTERFACE_H +#endif // INCLUDE_RIPS_COMPLEX_INTERFACE_H_ diff --git a/src/cython/include/Simplex_tree_interface.h b/src/cython/include/Simplex_tree_interface.h index c2783e22..4266b3ef 100644 --- a/src/cython/include/Simplex_tree_interface.h +++ b/src/cython/include/Simplex_tree_interface.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SIMPLEX_TREE_INTERFACE_H -#define SIMPLEX_TREE_INTERFACE_H +#ifndef INCLUDE_SIMPLEX_TREE_INTERFACE_H_ +#define INCLUDE_SIMPLEX_TREE_INTERFACE_H_ #include #include @@ -48,7 +48,6 @@ class Simplex_tree_interface : public Simplex_tree { using Complex = std::vector>; public: - bool find_simplex(const Simplex& vh) { return (Base::find(vh) != Base::null_simplex()); } @@ -98,7 +97,6 @@ class Simplex_tree_interface : public Simplex_tree { filtered_tree.push_back(std::make_pair(simplex, Base::filtration(f_simplex))); } return filtered_tree; - } Complex get_skeleton_tree(int dimension) { @@ -144,10 +142,8 @@ class Simplex_tree_interface : public Simplex_tree { void create_persistence(Gudhi::Persistent_cohomology_interface* pcoh) { pcoh = new Gudhi::Persistent_cohomology_interface(*this); } - }; -} // namespace Gudhi - -#endif // SIMPLEX_TREE_INTERFACE_H +} // namespace Gudhi +#endif // INCLUDE_SIMPLEX_TREE_INTERFACE_H_ diff --git a/src/cython/include/Strong_witness_complex_interface.h b/src/cython/include/Strong_witness_complex_interface.h index 83bf0f3c..d05eaac5 100644 --- a/src/cython/include/Strong_witness_complex_interface.h +++ b/src/cython/include/Strong_witness_complex_interface.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef STRONG_WITNESS_COMPLEX_INTERFACE_H -#define STRONG_WITNESS_COMPLEX_INTERFACE_H +#ifndef INCLUDE_STRONG_WITNESS_COMPLEX_INTERFACE_H_ +#define INCLUDE_STRONG_WITNESS_COMPLEX_INTERFACE_H_ #include #include @@ -64,12 +64,10 @@ class Strong_witness_complex_interface { private: Strong_witness_complex* witness_complex_; - }; } // namespace witness_complex -} // namespace Gudhi - -#endif // STRONG_WITNESS_COMPLEX_INTERFACE_H +} // namespace Gudhi +#endif // INCLUDE_STRONG_WITNESS_COMPLEX_INTERFACE_H_ diff --git a/src/cython/include/Subsampling_interface.h b/src/cython/include/Subsampling_interface.h index 5fc16767..1c6032c0 100644 --- a/src/cython/include/Subsampling_interface.h +++ b/src/cython/include/Subsampling_interface.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SUBSAMPLING_INTERFACE_H -#define SUBSAMPLING_INTERFACE_H +#ifndef INCLUDE_SUBSAMPLING_INTERFACE_H_ +#define INCLUDE_SUBSAMPLING_INTERFACE_H_ #include #include @@ -112,10 +112,8 @@ std::vector> subsampling_sparsify_points_from_file(const std return subsampling_sparsify_points(points, min_squared_dist); } - } // namespace subsampling } // namespace Gudhi -#endif // SUBSAMPLING_INTERFACE_H - +#endif // INCLUDE_SUBSAMPLING_INTERFACE_H_ diff --git a/src/cython/include/Tangential_complex_interface.h b/src/cython/include/Tangential_complex_interface.h index 2ca4c393..5e9dc0e4 100644 --- a/src/cython/include/Tangential_complex_interface.h +++ b/src/cython/include/Tangential_complex_interface.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef TANGENTIAL_COMPLEX_INTERFACE_H -#define TANGENTIAL_COMPLEX_INTERFACE_H +#ifndef INCLUDE_TANGENTIAL_COMPLEX_INTERFACE_H_ +#define INCLUDE_TANGENTIAL_COMPLEX_INTERFACE_H_ #include #include @@ -33,6 +33,7 @@ #include #include // std::pair #include +#include namespace Gudhi { @@ -49,7 +50,7 @@ class Tangential_complex_interface { unsigned intrisic_dim = 0; if (points.size() > 0) intrisic_dim = points[0].size() - 1; - + tangential_complex_ = new TC(points, intrisic_dim, k); tangential_complex_->compute_tangential_complex(); num_inconsistencies_ = tangential_complex_->number_of_inconsistent_simplices(); @@ -117,7 +118,6 @@ class Tangential_complex_interface { } // namespace tangential_complex -} // namespace Gudhi - -#endif // TANGENTIAL_COMPLEX_INTERFACE_H +} // namespace Gudhi +#endif // INCLUDE_TANGENTIAL_COMPLEX_INTERFACE_H_ diff --git a/src/cython/include/Witness_complex_interface.h b/src/cython/include/Witness_complex_interface.h index 4f2a903b..6501cc35 100644 --- a/src/cython/include/Witness_complex_interface.h +++ b/src/cython/include/Witness_complex_interface.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef WITNESS_COMPLEX_INTERFACE_H -#define WITNESS_COMPLEX_INTERFACE_H +#ifndef INCLUDE_WITNESS_COMPLEX_INTERFACE_H_ +#define INCLUDE_WITNESS_COMPLEX_INTERFACE_H_ #include #include @@ -64,12 +64,11 @@ class Witness_complex_interface { private: Witness_complex* witness_complex_; - }; } // namespace witness_complex -} // namespace Gudhi +} // namespace Gudhi -#endif // WITNESS_COMPLEX_INTERFACE_H +#endif // INCLUDE_WITNESS_COMPLEX_INTERFACE_H_ -- cgit v1.2.3