diff options
author | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-05-31 21:30:32 +0000 |
---|---|---|
committer | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-05-31 21:30:32 +0000 |
commit | 64bb1fe71e6e9e745e473aea456aef29df9cf6d0 (patch) | |
tree | bfd11deb78db16bfaa175451ccde0dc4429b9c7a /src/cython | |
parent | 7c20f9bf5829aa4ebe26ee59fb0120852dc0a5f3 (diff) |
Add Cubical complex interfaces
Warning on compilation
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@1232 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: 56022f52ab6a8ddcc466a36b7c4fb09615df9c7a
Diffstat (limited to 'src/cython')
-rw-r--r-- | src/cython/Makefile | 1 | ||||
-rwxr-xr-x | src/cython/example/cubical_complex_example.py | 40 | ||||
-rw-r--r-- | src/cython/gudhi.pyx | 1 | ||||
-rw-r--r-- | src/cython/src/cpp/Cubical_complex_interface.h | 54 | ||||
-rw-r--r-- | src/cython/src/cython/cubical_complex.pyx | 85 |
5 files changed, 181 insertions, 0 deletions
diff --git a/src/cython/Makefile b/src/cython/Makefile index fd7e16e6..f4e524ad 100644 --- a/src/cython/Makefile +++ b/src/cython/Makefile @@ -12,6 +12,7 @@ example: python example/mini_simplex_tree_example.py python example/rips_complex_example.py python example/alpha_complex_example.py + python example/cubical_complex_example.py clean: rm -rf build/ *.o *.so *.cpp diff --git a/src/cython/example/cubical_complex_example.py b/src/cython/example/cubical_complex_example.py new file mode 100755 index 00000000..ec7d2f5f --- /dev/null +++ b/src/cython/example/cubical_complex_example.py @@ -0,0 +1,40 @@ +#!/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 Saclay (France) + + 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 <http://www.gnu.org/licenses/>. +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__license__ = "GPL v3" + +print("#####################################################################") +print("CubicalComplex creation") +cubical_complex = gudhi.CubicalComplex(dimensions=[3, 3], + top_dimensional_cells=[1, 2, 3, 4, 5, 6, 7, 8, 9]) + +print("persistence(homology_coeff_field=2, min_persistence=0)=") +print(cubical_complex.persistence(homology_coeff_field=2, min_persistence=0)) + +print("betti_numbers()=") +print(cubical_complex.betti_numbers()) diff --git a/src/cython/gudhi.pyx b/src/cython/gudhi.pyx index 77b1b4bc..d0e2df99 100644 --- a/src/cython/gudhi.pyx +++ b/src/cython/gudhi.pyx @@ -28,3 +28,4 @@ include "src/cython/simplex_tree.pyx" include "src/cython/mini_simplex_tree.pyx" include "src/cython/rips_complex.pyx" include "src/cython/alpha_complex.pyx" +include "src/cython/cubical_complex.pyx" diff --git a/src/cython/src/cpp/Cubical_complex_interface.h b/src/cython/src/cpp/Cubical_complex_interface.h new file mode 100644 index 00000000..b817198d --- /dev/null +++ b/src/cython/src/cpp/Cubical_complex_interface.h @@ -0,0 +1,54 @@ +/* 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 Saclay (France) + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef CUBICAL_COMPLEX_INTERFACE_H +#define CUBICAL_COMPLEX_INTERFACE_H + +#include <gudhi/Bitmap_cubical_complex.h> +#include <gudhi/Bitmap_cubical_complex_base.h> +#include <gudhi/Bitmap_cubical_complex_periodic_boundary_conditions_base.h> + +#include <vector> +#include <utility> // std::pair +#include <iostream> + +namespace Gudhi { + +namespace Cubical_complex { + +template<typename CubicalComplexOptions = Bitmap_cubical_complex_base<double>> +class Cubical_complex_interface : public Bitmap_cubical_complex<CubicalComplexOptions> { + public: + + Cubical_complex_interface(const std::vector<unsigned>& dimensions, + const std::vector<double>& top_dimensional_cells) + : Bitmap_cubical_complex<CubicalComplexOptions>(dimensions, top_dimensional_cells) { + } + +}; + +} // namespace Cubical_complex + +} // namespace Gudhi + +#endif // CUBICAL_COMPLEX_INTERFACE_H + diff --git a/src/cython/src/cython/cubical_complex.pyx b/src/cython/src/cython/cubical_complex.pyx new file mode 100644 index 00000000..d513191c --- /dev/null +++ b/src/cython/src/cython/cubical_complex.pyx @@ -0,0 +1,85 @@ +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 Saclay (France) + + 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 <http://www.gnu.org/licenses/>. +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__license__ = "GPL v3" + +cdef extern from "Cubical_complex_interface.h" namespace "Gudhi": + cdef cppclass Bitmap_cubical_complex_base_interface "Gudhi::Cubical_complex::Cubical_complex_interface<>": + Bitmap_cubical_complex_base_interface(vector[unsigned] dimensions, vector[double] top_dimensional_cells) + +cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi": + cdef cppclass Cubical_complex_persistence_interface "Gudhi::Persistent_cohomology_interface<Gudhi::Cubical_complex::Cubical_complex_interface<>>": + Cubical_complex_persistence_interface(Bitmap_cubical_complex_base_interface * st) + 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) + + +# CubicalComplex python interface +cdef class CubicalComplex: + cdef Bitmap_cubical_complex_base_interface * thisptr + + cdef Cubical_complex_persistence_interface * pcohptr + + def __cinit__(self, dimensions=None, top_dimensional_cells=None): + if dimensions is not None: + if top_dimensional_cells is not None: + self.thisptr = new Bitmap_cubical_complex_base_interface(dimensions, top_dimensional_cells) + + def __dealloc__(self): + if self.thisptr != NULL: + del self.thisptr + if self.pcohptr != NULL: + del self.pcohptr + + def persistence(self, homology_coeff_field=11, min_persistence=0): + if self.pcohptr != NULL: + del self.pcohptr + self.pcohptr = new Cubical_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): + 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): + cdef vector[int] pbn_result + if self.pcohptr != NULL: + pbn_result = self.pcohptr.persistent_betti_numbers(<double>from_value, <double>to_value) + else: + print("persistent_betti_numbers function requires persistence function" + " to be launched first.") + return pbn_result |