From 1e283611d2999003353e57f429bc9a0513fb0508 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 31 May 2016 09:53:04 +0000 Subject: Rename files using PEP8 recommendations git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@1226 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 4fb27e76a494266c9f79f411c03633f68e2da525 --- src/cython/Makefile | 16 +-- src/cython/example/Alpha_complex_example.py | 45 ------ src/cython/example/Mini_simplex_tree_example.py | 46 ------- src/cython/example/Rips_complex_example.py | 15 -- src/cython/example/Simplex_tree_example.py | 42 ------ src/cython/example/alpha_complex_example.py | 71 ++++++++++ src/cython/example/mini_simplex_tree_example.py | 72 ++++++++++ src/cython/example/rips_complex_example.py | 41 ++++++ src/cython/example/simplex_tree_example.py | 68 +++++++++ src/cython/gudhi.pyx | 34 ++++- src/cython/setup.py | 26 ++++ src/cython/src/cython/Alpha_complex.pyx | 171 ----------------------- src/cython/src/cython/Mini_simplex_tree.pyx | 167 ----------------------- src/cython/src/cython/Rips_complex.pyx | 174 ------------------------ src/cython/src/cython/Simplex_tree.pyx | 168 ----------------------- src/cython/src/cython/alpha_complex.pyx | 171 +++++++++++++++++++++++ src/cython/src/cython/mini_simplex_tree.pyx | 167 +++++++++++++++++++++++ src/cython/src/cython/rips_complex.pyx | 174 ++++++++++++++++++++++++ src/cython/src/cython/simplex_tree.pyx | 168 +++++++++++++++++++++++ src/cython/test/Alpha_complex_UT.py | 58 -------- src/cython/test/Mini_simplex_tree_UT.py | 29 ---- src/cython/test/Rips_complex_UT.py | 35 ----- src/cython/test/Simplex_tree_UT.py | 65 --------- src/cython/test/test_alpha_complex.py | 84 ++++++++++++ src/cython/test/test_mini_simplex_tree.py | 55 ++++++++ src/cython/test/test_rips_complex.py | 61 +++++++++ src/cython/test/test_simplex_tree.py | 91 +++++++++++++ 27 files changed, 1287 insertions(+), 1027 deletions(-) delete mode 100755 src/cython/example/Alpha_complex_example.py delete mode 100755 src/cython/example/Mini_simplex_tree_example.py delete mode 100755 src/cython/example/Rips_complex_example.py delete mode 100755 src/cython/example/Simplex_tree_example.py create mode 100755 src/cython/example/alpha_complex_example.py create mode 100755 src/cython/example/mini_simplex_tree_example.py create mode 100755 src/cython/example/rips_complex_example.py create mode 100755 src/cython/example/simplex_tree_example.py delete mode 100644 src/cython/src/cython/Alpha_complex.pyx delete mode 100644 src/cython/src/cython/Mini_simplex_tree.pyx delete mode 100644 src/cython/src/cython/Rips_complex.pyx delete mode 100644 src/cython/src/cython/Simplex_tree.pyx create mode 100644 src/cython/src/cython/alpha_complex.pyx create mode 100644 src/cython/src/cython/mini_simplex_tree.pyx create mode 100644 src/cython/src/cython/rips_complex.pyx create mode 100644 src/cython/src/cython/simplex_tree.pyx delete mode 100755 src/cython/test/Alpha_complex_UT.py delete mode 100755 src/cython/test/Mini_simplex_tree_UT.py delete mode 100755 src/cython/test/Rips_complex_UT.py delete mode 100755 src/cython/test/Simplex_tree_UT.py create mode 100755 src/cython/test/test_alpha_complex.py create mode 100755 src/cython/test/test_mini_simplex_tree.py create mode 100755 src/cython/test/test_rips_complex.py create mode 100755 src/cython/test/test_simplex_tree.py (limited to 'src') diff --git a/src/cython/Makefile b/src/cython/Makefile index c90135b8..fd7e16e6 100644 --- a/src/cython/Makefile +++ b/src/cython/Makefile @@ -2,16 +2,16 @@ ext: python setup.py build_ext --inplace test: - python test/Simplex_tree_UT.py - python test/Mini_simplex_tree_UT.py - python test/Rips_complex_UT.py - python test/Alpha_complex_UT.py + python test/test_simplex_tree.py + python test/test_mini_simplex_tree.py + python test/test_rips_complex.py + python test/test_alpha_complex.py example: - python example/Simplex_tree_example.py - python example/Mini_simplex_tree_example.py - python example/Rips_complex_example.py - python example/Alpha_complex_example.py + python example/simplex_tree_example.py + python example/mini_simplex_tree_example.py + python example/rips_complex_example.py + python example/alpha_complex_example.py clean: rm -rf build/ *.o *.so *.cpp diff --git a/src/cython/example/Alpha_complex_example.py b/src/cython/example/Alpha_complex_example.py deleted file mode 100755 index a724b0c4..00000000 --- a/src/cython/example/Alpha_complex_example.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env python - -import gudhi - -print("#####################################################################") -print("AlphaComplex creation from points") -alpha_complex = gudhi.AlphaComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]], - max_alpha_square=60.0) - -if alpha_complex.find([0, 1]): - print("[0, 1] Found !!") -else: - print("[0, 1] Not found...") - -if alpha_complex.find([4]): - print("[4] Found !!") -else: - print("[4] Not found...") - -if alpha_complex.insert([0, 1, 2], filtration=4.0): - print("[0, 1, 2] Inserted !!") -else: - print("[0, 1, 2] Not inserted...") - -if alpha_complex.insert([0, 1, 4], filtration=4.0): - print("[0, 1, 4] Inserted !!") -else: - print("[0, 1, 4] Not inserted...") - -if alpha_complex.find([4]): - print("[4] Found !!") -else: - print("[4] Not found...") - -print("dimension=", alpha_complex.dimension()) -print("filtered_tree=", alpha_complex.get_filtered_tree()) -print("star([0])=", alpha_complex.get_star_tree([0])) -print("coface([0], 1)=", alpha_complex.get_coface_tree([0], 1)) - -print("point[0]=", alpha_complex.get_point(0)) -print("point[5]=", alpha_complex.get_point(5)) - -alpha_complex.initialize_filtration() -print("persistence(2)=", alpha_complex.persistence(homology_coeff_field=2, - min_persistence=0)) 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 6cd5bf29..00000000 --- a/src/cython/example/Mini_simplex_tree_example.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python - -import gudhi - -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("plain_homology(2)=", mini_st.plain_homology(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_example.py b/src/cython/example/Rips_complex_example.py deleted file mode 100755 index 6a39fc77..00000000 --- a/src/cython/example/Rips_complex_example.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python - -import gudhi - -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) - -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)) - -print("persistence(2)=", rips.persistence(homology_coeff_field=2, - min_persistence=0)) diff --git a/src/cython/example/Simplex_tree_example.py b/src/cython/example/Simplex_tree_example.py deleted file mode 100755 index e8585d83..00000000 --- a/src/cython/example/Simplex_tree_example.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python - -import gudhi - -st = gudhi.SimplexTree() - -print("#####################################################################") -print("SimplexTree creation from insertion") -if st.insert([0, 1]): - print("Inserted !!") -else: - print("Not inserted...") - -if st.find([0, 1]): - print("Found !!") -else: - print("Not found...") - -if st.insert([0, 1, 2], filtration=4.0): - print("Inserted !!") -else: - print("Not inserted...") - -# FIXME: Remove this line -st.set_dimension(3) -print("dimension=", st.dimension()) - -st.set_filtration(4.0) -st.initialize_filtration() -print("filtration=", st.get_filtration()) -print("filtration[1, 2]=", st.filtration([1, 2])) -print("filtration[4, 2]=", st.filtration([4, 2])) - -print("num_simplices=", st.num_simplices()) -print("num_vertices=", st.num_vertices()) - -print("skeleton_tree[2]=", st.get_skeleton_tree(2)) -print("skeleton_tree[1]=", st.get_skeleton_tree(1)) -print("skeleton_tree[0]=", st.get_skeleton_tree(0)) - -print("persistence(2)=", st.persistence(homology_coeff_field=2, - min_persistence=0)) diff --git a/src/cython/example/alpha_complex_example.py b/src/cython/example/alpha_complex_example.py new file mode 100755 index 00000000..6996b692 --- /dev/null +++ b/src/cython/example/alpha_complex_example.py @@ -0,0 +1,71 @@ +#!/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 . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__license__ = "GPL v3" + +print("#####################################################################") +print("AlphaComplex creation from points") +alpha_complex = gudhi.AlphaComplex(points=[[0, 0], [1, 0], [0, 1], [1, 1]], + max_alpha_square=60.0) + +if alpha_complex.find([0, 1]): + print("[0, 1] Found !!") +else: + print("[0, 1] Not found...") + +if alpha_complex.find([4]): + print("[4] Found !!") +else: + print("[4] Not found...") + +if alpha_complex.insert([0, 1, 2], filtration=4.0): + print("[0, 1, 2] Inserted !!") +else: + print("[0, 1, 2] Not inserted...") + +if alpha_complex.insert([0, 1, 4], filtration=4.0): + print("[0, 1, 4] Inserted !!") +else: + print("[0, 1, 4] Not inserted...") + +if alpha_complex.find([4]): + print("[4] Found !!") +else: + print("[4] Not found...") + +print("dimension=", alpha_complex.dimension()) +print("filtered_tree=", alpha_complex.get_filtered_tree()) +print("star([0])=", alpha_complex.get_star_tree([0])) +print("coface([0], 1)=", alpha_complex.get_coface_tree([0], 1)) + +print("point[0]=", alpha_complex.get_point(0)) +print("point[5]=", alpha_complex.get_point(5)) + +alpha_complex.initialize_filtration() +print("persistence(2)=", alpha_complex.persistence(homology_coeff_field=2, + min_persistence=0)) diff --git a/src/cython/example/mini_simplex_tree_example.py b/src/cython/example/mini_simplex_tree_example.py new file mode 100755 index 00000000..0461a1df --- /dev/null +++ b/src/cython/example/mini_simplex_tree_example.py @@ -0,0 +1,72 @@ +#!/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 . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__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("plain_homology(2)=", mini_st.plain_homology(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_example.py b/src/cython/example/rips_complex_example.py new file mode 100755 index 00000000..eba3f298 --- /dev/null +++ b/src/cython/example/rips_complex_example.py @@ -0,0 +1,41 @@ +#!/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 . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__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) + +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)) + +print("persistence(2)=", rips.persistence(homology_coeff_field=2, + min_persistence=0)) diff --git a/src/cython/example/simplex_tree_example.py b/src/cython/example/simplex_tree_example.py new file mode 100755 index 00000000..bdaabca2 --- /dev/null +++ b/src/cython/example/simplex_tree_example.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python + +import gudhi + +st = gudhi.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 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 . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__license__ = "GPL v3" + +print("#####################################################################") +print("SimplexTree creation from insertion") +if st.insert([0, 1]): + print("Inserted !!") +else: + print("Not inserted...") + +if st.find([0, 1]): + print("Found !!") +else: + print("Not found...") + +if st.insert([0, 1, 2], filtration=4.0): + print("Inserted !!") +else: + print("Not inserted...") + +# FIXME: Remove this line +st.set_dimension(3) +print("dimension=", st.dimension()) + +st.set_filtration(4.0) +st.initialize_filtration() +print("filtration=", st.get_filtration()) +print("filtration[1, 2]=", st.filtration([1, 2])) +print("filtration[4, 2]=", st.filtration([4, 2])) + +print("num_simplices=", st.num_simplices()) +print("num_vertices=", st.num_vertices()) + +print("skeleton_tree[2]=", st.get_skeleton_tree(2)) +print("skeleton_tree[1]=", st.get_skeleton_tree(1)) +print("skeleton_tree[0]=", st.get_skeleton_tree(0)) + +print("persistence(2)=", st.persistence(homology_coeff_field=2, + min_persistence=0)) diff --git a/src/cython/gudhi.pyx b/src/cython/gudhi.pyx index 8fcc081a..77b1b4bc 100644 --- a/src/cython/gudhi.pyx +++ b/src/cython/gudhi.pyx @@ -1,4 +1,30 @@ -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" +"""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 . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__license__ = "GPL v3" + +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" diff --git a/src/cython/setup.py b/src/cython/setup.py index 92ed6bbd..5b99ba5f 100644 --- a/src/cython/setup.py +++ b/src/cython/setup.py @@ -1,6 +1,32 @@ from distutils.core import setup, Extension from Cython.Build import cythonize +"""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 . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__license__ = "GPL v3" + gudhi = Extension( "gudhi", sources = ['gudhi.pyx',], diff --git a/src/cython/src/cython/Alpha_complex.pyx b/src/cython/src/cython/Alpha_complex.pyx deleted file mode 100644 index a06134c8..00000000 --- a/src/cython/src/cython/Alpha_complex.pyx +++ /dev/null @@ -1,171 +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 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 . -""" - -__author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" -__license__ = "GPL v3" - -cdef extern from "Alpha_complex_interface.h" namespace "Gudhi": - cdef cppclass Alpha_complex_interface "Gudhi::alphacomplex::Alpha_complex_interface": - Alpha_complex_interface(vector[vector[double]] points, double max_alpha_square) - 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) - -cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi": - cdef cppclass Alpha_complex_persistence_interface "Gudhi::Persistent_cohomology_interface >>": - Alpha_complex_persistence_interface(Alpha_complex_interface * st) - void get_persistence(int homology_coeff_field, double min_persistence) - -# AlphaComplex python interface -cdef class AlphaComplex: - cdef Alpha_complex_interface * thisptr - - def __cinit__(self, points=None, max_alpha_square=float('inf')): - if points is not None: - self.thisptr = new Alpha_complex_interface(points, - max_alpha_square) - - def __dealloc__(self): - if self.thisptr != NULL: - del self.thisptr - - def get_filtration(self): - return self.thisptr.filtration() - - def filtration(self, simplex): - return self.thisptr.simplex_filtration(simplex) - - def set_filtration(self, filtration): - self.thisptr.set_filtration( filtration) - - def initialize_filtration(self): - self.thisptr.initialize_filtration() - - def num_vertices(self): - return self.thisptr.num_vertices() - - def num_simplices(self): - return self.thisptr.num_simplices() - - def dimension(self): - return self.thisptr.dimension() - - def set_dimension(self, dim): - self.thisptr.set_dimension(dim) - - def find(self, simplex): - 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): - 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): - 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, dim): - cdef vector[pair[vector[int], double]] coface_tree \ - = self.thisptr.get_skeleton_tree(dim) - 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): - 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, dim): - 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, dim) - 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): - self.thisptr.remove_maximal_simplex(simplex) - - def get_point(self, vertex): - cdef vector[double] point = self.thisptr.get_point(vertex) - return point - - def persistence(self, homology_coeff_field=11, min_persistence=0): - cdef Alpha_complex_persistence_interface * pcohptr \ - = new Alpha_complex_persistence_interface(self.thisptr) - if pcohptr != NULL: - pcohptr.get_persistence(homology_coeff_field, min_persistence) - del pcohptr - return 5 diff --git a/src/cython/src/cython/Mini_simplex_tree.pyx b/src/cython/src/cython/Mini_simplex_tree.pyx deleted file mode 100644 index b836fb88..00000000 --- a/src/cython/src/cython/Mini_simplex_tree.pyx +++ /dev/null @@ -1,167 +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 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 . -""" - -__author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" -__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) - void get_persistence(int homology_coeff_field, double min_persistence) - -# MiniSimplexTree python interface -cdef class MiniSimplexTree: - cdef Simplex_tree_interface_mini * thisptr - - def __cinit__(self): - self.thisptr = new Simplex_tree_interface_mini() - - def __dealloc__(self): - if self.thisptr != NULL: - del self.thisptr - - def get_filtration(self): - return self.thisptr.filtration() - - def filtration(self, simplex): - return self.thisptr.simplex_filtration(simplex) - - def set_filtration(self, filtration): - self.thisptr.set_filtration( filtration) - - def initialize_filtration(self): - self.thisptr.initialize_filtration() - - def num_vertices(self): - return self.thisptr.num_vertices() - - def num_simplices(self): - return self.thisptr.num_simplices() - - def dimension(self): - return self.thisptr.dimension() - - def set_dimension(self, dim): - self.thisptr.set_dimension(dim) - - def find(self, simplex): - 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): - 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): - 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, dim): - cdef vector[pair[vector[int], double]] coface_tree \ - = self.thisptr.get_skeleton_tree(dim) - 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): - 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, dim): - 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, dim) - 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): - self.thisptr.remove_maximal_simplex(simplex) - - def plain_homology(self, homology_coeff_field=11): - cdef Mini_simplex_tree_persistence_interface * pcohptr \ - = new Mini_simplex_tree_persistence_interface(self.thisptr) - if pcohptr != NULL: - pcohptr.get_persistence(homology_coeff_field, 0) - del pcohptr - return 5 diff --git a/src/cython/src/cython/Rips_complex.pyx b/src/cython/src/cython/Rips_complex.pyx deleted file mode 100644 index 3ca890d9..00000000 --- a/src/cython/src/cython/Rips_complex.pyx +++ /dev/null @@ -1,174 +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 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 . -""" - -__author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" -__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) - -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) - void get_persistence(int homology_coeff_field, double min_persistence) - -# RipsComplex python interface -cdef class RipsComplex: - cdef Rips_complex_interface * thisptr - - def __cinit__(self, points=None, max_dimension=3, - max_edge_length=float('inf')): - self.thisptr = new Rips_complex_interface() - # Constructor from graph expansion - if points is not None: - self.thisptr.graph_expansion(points, max_dimension, - max_edge_length) - - def __dealloc__(self): - if self.thisptr != NULL: - del self.thisptr - - def get_filtration(self): - return self.thisptr.filtration() - - def filtration(self, simplex): - return self.thisptr.simplex_filtration(simplex) - - def set_filtration(self, filtration): - self.thisptr.set_filtration( filtration) - - def initialize_filtration(self): - self.thisptr.initialize_filtration() - - def num_vertices(self): - return self.thisptr.num_vertices() - - def num_simplices(self): - return self.thisptr.num_simplices() - - def dimension(self): - return self.thisptr.dimension() - - def set_dimension(self, dim): - self.thisptr.set_dimension(dim) - - def find(self, simplex): - 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): - 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): - 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, dim): - cdef vector[pair[vector[int], double]] coface_tree \ - = self.thisptr.get_skeleton_tree(dim) - 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): - 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, dim): - 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, dim) - 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): - self.thisptr.remove_maximal_simplex(simplex) - - def persistence(self, homology_coeff_field=11, min_persistence=0): - cdef Rips_complex_persistence_interface * pcohptr \ - = new Rips_complex_persistence_interface(self.thisptr) - if pcohptr != NULL: - pcohptr.get_persistence(homology_coeff_field, min_persistence) - del pcohptr - return 5 diff --git a/src/cython/src/cython/Simplex_tree.pyx b/src/cython/src/cython/Simplex_tree.pyx deleted file mode 100644 index e3cdc27b..00000000 --- a/src/cython/src/cython/Simplex_tree.pyx +++ /dev/null @@ -1,168 +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 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 . -""" - -__author__ = "Vincent Rouvreau" -__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" -__license__ = "GPL v3" - -cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": - cdef cppclass Simplex_tree_options_full_featured: - pass - - cdef cppclass Simplex_tree_interface_full_featured "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 Simplex_tree_persistence_interface "Gudhi::Persistent_cohomology_interface>": - Simplex_tree_persistence_interface(Simplex_tree_interface_full_featured * st) - void get_persistence(int homology_coeff_field, double min_persistence) - -# SimplexTree python interface -cdef class SimplexTree: - cdef Simplex_tree_interface_full_featured * thisptr - - def __cinit__(self): - self.thisptr = new Simplex_tree_interface_full_featured() - - def __dealloc__(self): - if self.thisptr != NULL: - del self.thisptr - - def get_filtration(self): - return self.thisptr.filtration() - - def filtration(self, simplex): - return self.thisptr.simplex_filtration(simplex) - - def set_filtration(self, filtration): - self.thisptr.set_filtration( filtration) - - def initialize_filtration(self): - self.thisptr.initialize_filtration() - - def num_vertices(self): - return self.thisptr.num_vertices() - - def num_simplices(self): - return self.thisptr.num_simplices() - - def dimension(self): - return self.thisptr.dimension() - - def set_dimension(self, dim): - self.thisptr.set_dimension(dim) - - def find(self, simplex): - 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): - 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): - 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, dim): - cdef vector[pair[vector[int], double]] coface_tree \ - = self.thisptr.get_skeleton_tree(dim) - 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): - 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, dim): - 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, dim) - 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): - self.thisptr.remove_maximal_simplex(simplex) - - def persistence(self, homology_coeff_field=11, min_persistence=0): - cdef Simplex_tree_persistence_interface * pcohptr \ - = new Simplex_tree_persistence_interface(self.thisptr) - if pcohptr != NULL: - pcohptr.get_persistence(homology_coeff_field, min_persistence) - del pcohptr - return 5 - diff --git a/src/cython/src/cython/alpha_complex.pyx b/src/cython/src/cython/alpha_complex.pyx new file mode 100644 index 00000000..a06134c8 --- /dev/null +++ b/src/cython/src/cython/alpha_complex.pyx @@ -0,0 +1,171 @@ +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 . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__license__ = "GPL v3" + +cdef extern from "Alpha_complex_interface.h" namespace "Gudhi": + cdef cppclass Alpha_complex_interface "Gudhi::alphacomplex::Alpha_complex_interface": + Alpha_complex_interface(vector[vector[double]] points, double max_alpha_square) + 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) + +cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi": + cdef cppclass Alpha_complex_persistence_interface "Gudhi::Persistent_cohomology_interface >>": + Alpha_complex_persistence_interface(Alpha_complex_interface * st) + void get_persistence(int homology_coeff_field, double min_persistence) + +# AlphaComplex python interface +cdef class AlphaComplex: + cdef Alpha_complex_interface * thisptr + + def __cinit__(self, points=None, max_alpha_square=float('inf')): + if points is not None: + self.thisptr = new Alpha_complex_interface(points, + max_alpha_square) + + def __dealloc__(self): + if self.thisptr != NULL: + del self.thisptr + + def get_filtration(self): + return self.thisptr.filtration() + + def filtration(self, simplex): + return self.thisptr.simplex_filtration(simplex) + + def set_filtration(self, filtration): + self.thisptr.set_filtration( filtration) + + def initialize_filtration(self): + self.thisptr.initialize_filtration() + + def num_vertices(self): + return self.thisptr.num_vertices() + + def num_simplices(self): + return self.thisptr.num_simplices() + + def dimension(self): + return self.thisptr.dimension() + + def set_dimension(self, dim): + self.thisptr.set_dimension(dim) + + def find(self, simplex): + 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): + 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): + 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, dim): + cdef vector[pair[vector[int], double]] coface_tree \ + = self.thisptr.get_skeleton_tree(dim) + 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): + 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, dim): + 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, dim) + 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): + self.thisptr.remove_maximal_simplex(simplex) + + def get_point(self, vertex): + cdef vector[double] point = self.thisptr.get_point(vertex) + return point + + def persistence(self, homology_coeff_field=11, min_persistence=0): + cdef Alpha_complex_persistence_interface * pcohptr \ + = new Alpha_complex_persistence_interface(self.thisptr) + if pcohptr != NULL: + pcohptr.get_persistence(homology_coeff_field, min_persistence) + del pcohptr + return 5 diff --git a/src/cython/src/cython/mini_simplex_tree.pyx b/src/cython/src/cython/mini_simplex_tree.pyx new file mode 100644 index 00000000..b836fb88 --- /dev/null +++ b/src/cython/src/cython/mini_simplex_tree.pyx @@ -0,0 +1,167 @@ +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 . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__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) + void get_persistence(int homology_coeff_field, double min_persistence) + +# MiniSimplexTree python interface +cdef class MiniSimplexTree: + cdef Simplex_tree_interface_mini * thisptr + + def __cinit__(self): + self.thisptr = new Simplex_tree_interface_mini() + + def __dealloc__(self): + if self.thisptr != NULL: + del self.thisptr + + def get_filtration(self): + return self.thisptr.filtration() + + def filtration(self, simplex): + return self.thisptr.simplex_filtration(simplex) + + def set_filtration(self, filtration): + self.thisptr.set_filtration( filtration) + + def initialize_filtration(self): + self.thisptr.initialize_filtration() + + def num_vertices(self): + return self.thisptr.num_vertices() + + def num_simplices(self): + return self.thisptr.num_simplices() + + def dimension(self): + return self.thisptr.dimension() + + def set_dimension(self, dim): + self.thisptr.set_dimension(dim) + + def find(self, simplex): + 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): + 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): + 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, dim): + cdef vector[pair[vector[int], double]] coface_tree \ + = self.thisptr.get_skeleton_tree(dim) + 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): + 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, dim): + 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, dim) + 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): + self.thisptr.remove_maximal_simplex(simplex) + + def plain_homology(self, homology_coeff_field=11): + cdef Mini_simplex_tree_persistence_interface * pcohptr \ + = new Mini_simplex_tree_persistence_interface(self.thisptr) + if pcohptr != NULL: + pcohptr.get_persistence(homology_coeff_field, 0) + del pcohptr + return 5 diff --git a/src/cython/src/cython/rips_complex.pyx b/src/cython/src/cython/rips_complex.pyx new file mode 100644 index 00000000..3ca890d9 --- /dev/null +++ b/src/cython/src/cython/rips_complex.pyx @@ -0,0 +1,174 @@ +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 . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__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) + +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) + void get_persistence(int homology_coeff_field, double min_persistence) + +# RipsComplex python interface +cdef class RipsComplex: + cdef Rips_complex_interface * thisptr + + def __cinit__(self, points=None, max_dimension=3, + max_edge_length=float('inf')): + self.thisptr = new Rips_complex_interface() + # Constructor from graph expansion + if points is not None: + self.thisptr.graph_expansion(points, max_dimension, + max_edge_length) + + def __dealloc__(self): + if self.thisptr != NULL: + del self.thisptr + + def get_filtration(self): + return self.thisptr.filtration() + + def filtration(self, simplex): + return self.thisptr.simplex_filtration(simplex) + + def set_filtration(self, filtration): + self.thisptr.set_filtration( filtration) + + def initialize_filtration(self): + self.thisptr.initialize_filtration() + + def num_vertices(self): + return self.thisptr.num_vertices() + + def num_simplices(self): + return self.thisptr.num_simplices() + + def dimension(self): + return self.thisptr.dimension() + + def set_dimension(self, dim): + self.thisptr.set_dimension(dim) + + def find(self, simplex): + 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): + 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): + 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, dim): + cdef vector[pair[vector[int], double]] coface_tree \ + = self.thisptr.get_skeleton_tree(dim) + 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): + 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, dim): + 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, dim) + 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): + self.thisptr.remove_maximal_simplex(simplex) + + def persistence(self, homology_coeff_field=11, min_persistence=0): + cdef Rips_complex_persistence_interface * pcohptr \ + = new Rips_complex_persistence_interface(self.thisptr) + if pcohptr != NULL: + pcohptr.get_persistence(homology_coeff_field, min_persistence) + del pcohptr + return 5 diff --git a/src/cython/src/cython/simplex_tree.pyx b/src/cython/src/cython/simplex_tree.pyx new file mode 100644 index 00000000..e3cdc27b --- /dev/null +++ b/src/cython/src/cython/simplex_tree.pyx @@ -0,0 +1,168 @@ +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 . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__license__ = "GPL v3" + +cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": + cdef cppclass Simplex_tree_options_full_featured: + pass + + cdef cppclass Simplex_tree_interface_full_featured "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 Simplex_tree_persistence_interface "Gudhi::Persistent_cohomology_interface>": + Simplex_tree_persistence_interface(Simplex_tree_interface_full_featured * st) + void get_persistence(int homology_coeff_field, double min_persistence) + +# SimplexTree python interface +cdef class SimplexTree: + cdef Simplex_tree_interface_full_featured * thisptr + + def __cinit__(self): + self.thisptr = new Simplex_tree_interface_full_featured() + + def __dealloc__(self): + if self.thisptr != NULL: + del self.thisptr + + def get_filtration(self): + return self.thisptr.filtration() + + def filtration(self, simplex): + return self.thisptr.simplex_filtration(simplex) + + def set_filtration(self, filtration): + self.thisptr.set_filtration( filtration) + + def initialize_filtration(self): + self.thisptr.initialize_filtration() + + def num_vertices(self): + return self.thisptr.num_vertices() + + def num_simplices(self): + return self.thisptr.num_simplices() + + def dimension(self): + return self.thisptr.dimension() + + def set_dimension(self, dim): + self.thisptr.set_dimension(dim) + + def find(self, simplex): + 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): + 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): + 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, dim): + cdef vector[pair[vector[int], double]] coface_tree \ + = self.thisptr.get_skeleton_tree(dim) + 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): + 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, dim): + 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, dim) + 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): + self.thisptr.remove_maximal_simplex(simplex) + + def persistence(self, homology_coeff_field=11, min_persistence=0): + cdef Simplex_tree_persistence_interface * pcohptr \ + = new Simplex_tree_persistence_interface(self.thisptr) + if pcohptr != NULL: + pcohptr.get_persistence(homology_coeff_field, min_persistence) + del pcohptr + return 5 + diff --git a/src/cython/test/Alpha_complex_UT.py b/src/cython/test/Alpha_complex_UT.py deleted file mode 100755 index c14c43e2..00000000 --- a/src/cython/test/Alpha_complex_UT.py +++ /dev/null @@ -1,58 +0,0 @@ -import unittest - -import gudhi - - -class TestAlphaComplex(unittest.TestCase): - - def test_infinite_alpha(self): - point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] - alpha_complex = gudhi.AlphaComplex(points=point_list) - - self.assertEqual(alpha_complex.num_simplices(), 11) - self.assertEqual(alpha_complex.num_vertices(), 4) - - self.assertEqual(alpha_complex.get_filtered_tree(), - [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0), - ([0, 1], 0.25), ([0, 2], 0.25), ([1, 3], 0.25), - ([2, 3], 0.25), ([1, 2], 0.5), ([0, 1, 2], 0.5), - ([1, 2, 3], 0.5)]) - self.assertEqual(alpha_complex.get_star_tree([0]), - [([0], 0.0), ([0, 1], 0.25), ([0, 1, 2], 0.5), - ([0, 2], 0.25)]) - self.assertEqual(alpha_complex.get_coface_tree([0], 1), - [([0, 1], 0.25), ([0, 2], 0.25)]) - - self.assertEqual(point_list[0], alpha_complex.get_point(0)) - self.assertEqual(point_list[1], alpha_complex.get_point(1)) - self.assertEqual(point_list[2], alpha_complex.get_point(2)) - self.assertEqual(point_list[3], alpha_complex.get_point(3)) - self.assertEqual([], alpha_complex.get_point(4)) - self.assertEqual([], alpha_complex.get_point(125)) - - def test_filtered_alpha(self): - point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] - filtered_alpha = gudhi.AlphaComplex(points=point_list, - max_alpha_square=0.25) - - self.assertEqual(filtered_alpha.num_simplices(), 8) - self.assertEqual(filtered_alpha.num_vertices(), 4) - - self.assertEqual(point_list[0], filtered_alpha.get_point(0)) - self.assertEqual(point_list[1], filtered_alpha.get_point(1)) - self.assertEqual(point_list[2], filtered_alpha.get_point(2)) - self.assertEqual(point_list[3], filtered_alpha.get_point(3)) - self.assertEqual([], filtered_alpha.get_point(4)) - self.assertEqual([], filtered_alpha.get_point(125)) - - self.assertEqual(filtered_alpha.get_filtered_tree(), - [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0), - ([0, 1], 0.25), ([0, 2], 0.25), ([1, 3], 0.25), - ([2, 3], 0.25)]) - self.assertEqual(filtered_alpha.get_star_tree([0]), - [([0], 0.0), ([0, 1], 0.25), ([0, 2], 0.25)]) - self.assertEqual(filtered_alpha.get_coface_tree([0], 1), - [([0, 1], 0.25), ([0, 2], 0.25)]) - -if __name__ == '__main__': - unittest.main() diff --git a/src/cython/test/Mini_simplex_tree_UT.py b/src/cython/test/Mini_simplex_tree_UT.py deleted file mode 100755 index 8f2f56df..00000000 --- a/src/cython/test/Mini_simplex_tree_UT.py +++ /dev/null @@ -1,29 +0,0 @@ -import unittest - -import gudhi - - -class TestMiniSimplexTree(unittest.TestCase): - - def test_mini(self): - triangle012 = [0, 1, 2] - edge03 = [0, 3] - mini_st = gudhi.MiniSimplexTree() - self.assertTrue(mini_st.insert(triangle012)) - self.assertTrue(mini_st.insert(edge03)) - # FIXME: Remove this line - mini_st.set_dimension(2) - - edge02 = [0, 2] - self.assertTrue(mini_st.find(edge02)) - self.assertEqual(mini_st.get_coface_tree(edge02, 1), - [([0, 1, 2], 0.0)]) - - # remove_maximal_simplex test - self.assertEqual(mini_st.get_coface_tree(triangle012, 1), []) - mini_st.remove_maximal_simplex(triangle012) - self.assertTrue(mini_st.find(edge02)) - self.assertFalse(mini_st.find(triangle012)) - -if __name__ == '__main__': - unittest.main() diff --git a/src/cython/test/Rips_complex_UT.py b/src/cython/test/Rips_complex_UT.py deleted file mode 100755 index ccff5c2d..00000000 --- a/src/cython/test/Rips_complex_UT.py +++ /dev/null @@ -1,35 +0,0 @@ -import unittest - -import gudhi - - -class TestRipsComplex(unittest.TestCase): - - def test_rips(self): - point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] - rips_complex = gudhi.RipsComplex(points=point_list, max_dimension=1, - max_edge_length=42) - - self.assertEqual(rips_complex.num_simplices(), 10) - self.assertEqual(rips_complex.num_vertices(), 4) - - self.assertEqual(rips_complex.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)]) - self.assertEqual(rips_complex.get_star_tree([0]), - [([0], 0.0), ([0, 1], 1.0), ([0, 2], 1.0), - ([0, 3], 1.4142135623730951)]) - self.assertEqual(rips_complex.get_coface_tree([0], 1), - [([0, 1], 1.0), ([0, 2], 1.0), - ([0, 3], 1.4142135623730951)]) - - filtered_rips = gudhi.RipsComplex(points=point_list, max_dimension=1, - max_edge_length=1.0) - - self.assertEqual(filtered_rips.num_simplices(), 8) - self.assertEqual(filtered_rips.num_vertices(), 4) - -if __name__ == '__main__': - unittest.main() diff --git a/src/cython/test/Simplex_tree_UT.py b/src/cython/test/Simplex_tree_UT.py deleted file mode 100755 index 392c6d71..00000000 --- a/src/cython/test/Simplex_tree_UT.py +++ /dev/null @@ -1,65 +0,0 @@ -import unittest - -import gudhi - - -class TestSimplexTree(unittest.TestCase): - - def test_insertion(self): - st = gudhi.SimplexTree() - - # insert test - self.assertTrue(st.insert([0, 1])) - self.assertTrue(st.insert([0, 1, 2], filtration=4.0)) - self.assertEqual(st.num_simplices(), 7) - self.assertEqual(st.num_vertices(), 3) - - # find test - self.assertTrue(st.find([0, 1, 2])) - self.assertTrue(st.find([0, 1])) - self.assertTrue(st.find([0, 2])) - self.assertTrue(st.find([0])) - self.assertTrue(st.find([1])) - self.assertTrue(st.find([2])) - self.assertFalse(st.find([3])) - self.assertFalse(st.find([0, 3])) - self.assertFalse(st.find([1, 3])) - self.assertFalse(st.find([2, 3])) - - # filtration test - st.set_filtration(5.0) - st.initialize_filtration() - self.assertEqual(st.get_filtration(), 5.0) - self.assertEqual(st.filtration([0, 1, 2]), 4.0) - self.assertEqual(st.filtration([0, 2]), 4.0) - self.assertEqual(st.filtration([1, 2]), 4.0) - self.assertEqual(st.filtration([2]), 4.0) - self.assertEqual(st.filtration([0, 1]), 0.0) - self.assertEqual(st.filtration([0]), 0.0) - self.assertEqual(st.filtration([1]), 0.0) - - # skeleton_tree test - self.assertEqual(st.get_skeleton_tree(2), - [([0, 1, 2], 4.0), ([0, 1], 0.0), ([0, 2], 4.0), - ([0], 0.0), ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)]) - self.assertEqual(st.get_skeleton_tree(1), - [([0, 1], 0.0), ([0, 2], 4.0), ([0], 0.0), - ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)]) - self.assertEqual(st.get_skeleton_tree(0), - [([0], 0.0), ([1], 0.0), ([2], 4.0)]) - - # remove_maximal_simplex test - self.assertEqual(st.get_coface_tree([0, 1, 2], 1), []) - st.remove_maximal_simplex([0, 1, 2]) - self.assertEqual(st.get_skeleton_tree(2), - [([0, 1], 0.0), ([0, 2], 4.0), ([0], 0.0), - ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)]) - self.assertFalse(st.find([0, 1, 2])) - self.assertTrue(st.find([0, 1])) - self.assertTrue(st.find([0, 2])) - self.assertTrue(st.find([0])) - self.assertTrue(st.find([1])) - self.assertTrue(st.find([2])) - -if __name__ == '__main__': - unittest.main() diff --git a/src/cython/test/test_alpha_complex.py b/src/cython/test/test_alpha_complex.py new file mode 100755 index 00000000..8a346bb9 --- /dev/null +++ b/src/cython/test/test_alpha_complex.py @@ -0,0 +1,84 @@ +import unittest + +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 . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__license__ = "GPL v3" + + +class TestAlphaComplex(unittest.TestCase): + + def test_infinite_alpha(self): + point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] + alpha_complex = gudhi.AlphaComplex(points=point_list) + + self.assertEqual(alpha_complex.num_simplices(), 11) + self.assertEqual(alpha_complex.num_vertices(), 4) + + self.assertEqual(alpha_complex.get_filtered_tree(), + [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0), + ([0, 1], 0.25), ([0, 2], 0.25), ([1, 3], 0.25), + ([2, 3], 0.25), ([1, 2], 0.5), ([0, 1, 2], 0.5), + ([1, 2, 3], 0.5)]) + self.assertEqual(alpha_complex.get_star_tree([0]), + [([0], 0.0), ([0, 1], 0.25), ([0, 1, 2], 0.5), + ([0, 2], 0.25)]) + self.assertEqual(alpha_complex.get_coface_tree([0], 1), + [([0, 1], 0.25), ([0, 2], 0.25)]) + + self.assertEqual(point_list[0], alpha_complex.get_point(0)) + self.assertEqual(point_list[1], alpha_complex.get_point(1)) + self.assertEqual(point_list[2], alpha_complex.get_point(2)) + self.assertEqual(point_list[3], alpha_complex.get_point(3)) + self.assertEqual([], alpha_complex.get_point(4)) + self.assertEqual([], alpha_complex.get_point(125)) + + def test_filtered_alpha(self): + point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] + filtered_alpha = gudhi.AlphaComplex(points=point_list, + max_alpha_square=0.25) + + self.assertEqual(filtered_alpha.num_simplices(), 8) + self.assertEqual(filtered_alpha.num_vertices(), 4) + + self.assertEqual(point_list[0], filtered_alpha.get_point(0)) + self.assertEqual(point_list[1], filtered_alpha.get_point(1)) + self.assertEqual(point_list[2], filtered_alpha.get_point(2)) + self.assertEqual(point_list[3], filtered_alpha.get_point(3)) + self.assertEqual([], filtered_alpha.get_point(4)) + self.assertEqual([], filtered_alpha.get_point(125)) + + self.assertEqual(filtered_alpha.get_filtered_tree(), + [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0), + ([0, 1], 0.25), ([0, 2], 0.25), ([1, 3], 0.25), + ([2, 3], 0.25)]) + self.assertEqual(filtered_alpha.get_star_tree([0]), + [([0], 0.0), ([0, 1], 0.25), ([0, 2], 0.25)]) + self.assertEqual(filtered_alpha.get_coface_tree([0], 1), + [([0, 1], 0.25), ([0, 2], 0.25)]) + +if __name__ == '__main__': + unittest.main() diff --git a/src/cython/test/test_mini_simplex_tree.py b/src/cython/test/test_mini_simplex_tree.py new file mode 100755 index 00000000..6622fa57 --- /dev/null +++ b/src/cython/test/test_mini_simplex_tree.py @@ -0,0 +1,55 @@ +import unittest + +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 . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__license__ = "GPL v3" + + +class TestMiniSimplexTree(unittest.TestCase): + + def test_mini(self): + triangle012 = [0, 1, 2] + edge03 = [0, 3] + mini_st = gudhi.MiniSimplexTree() + self.assertTrue(mini_st.insert(triangle012)) + self.assertTrue(mini_st.insert(edge03)) + # FIXME: Remove this line + mini_st.set_dimension(2) + + edge02 = [0, 2] + self.assertTrue(mini_st.find(edge02)) + self.assertEqual(mini_st.get_coface_tree(edge02, 1), + [([0, 1, 2], 0.0)]) + + # remove_maximal_simplex test + self.assertEqual(mini_st.get_coface_tree(triangle012, 1), []) + mini_st.remove_maximal_simplex(triangle012) + self.assertTrue(mini_st.find(edge02)) + self.assertFalse(mini_st.find(triangle012)) + +if __name__ == '__main__': + unittest.main() diff --git a/src/cython/test/test_rips_complex.py b/src/cython/test/test_rips_complex.py new file mode 100755 index 00000000..3ad26b53 --- /dev/null +++ b/src/cython/test/test_rips_complex.py @@ -0,0 +1,61 @@ +import unittest + +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 . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__license__ = "GPL v3" + + +class TestRipsComplex(unittest.TestCase): + + def test_rips(self): + point_list = [[0, 0], [1, 0], [0, 1], [1, 1]] + rips_complex = gudhi.RipsComplex(points=point_list, max_dimension=1, + max_edge_length=42) + + self.assertEqual(rips_complex.num_simplices(), 10) + self.assertEqual(rips_complex.num_vertices(), 4) + + self.assertEqual(rips_complex.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)]) + self.assertEqual(rips_complex.get_star_tree([0]), + [([0], 0.0), ([0, 1], 1.0), ([0, 2], 1.0), + ([0, 3], 1.4142135623730951)]) + self.assertEqual(rips_complex.get_coface_tree([0], 1), + [([0, 1], 1.0), ([0, 2], 1.0), + ([0, 3], 1.4142135623730951)]) + + filtered_rips = gudhi.RipsComplex(points=point_list, max_dimension=1, + max_edge_length=1.0) + + self.assertEqual(filtered_rips.num_simplices(), 8) + self.assertEqual(filtered_rips.num_vertices(), 4) + +if __name__ == '__main__': + unittest.main() diff --git a/src/cython/test/test_simplex_tree.py b/src/cython/test/test_simplex_tree.py new file mode 100755 index 00000000..3451ca4b --- /dev/null +++ b/src/cython/test/test_simplex_tree.py @@ -0,0 +1,91 @@ +import unittest + +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 . +""" + +__author__ = "Vincent Rouvreau" +__copyright__ = "Copyright (C) 2016 INRIA Saclay (France)" +__license__ = "GPL v3" + + +class TestSimplexTree(unittest.TestCase): + + def test_insertion(self): + st = gudhi.SimplexTree() + + # insert test + self.assertTrue(st.insert([0, 1])) + self.assertTrue(st.insert([0, 1, 2], filtration=4.0)) + self.assertEqual(st.num_simplices(), 7) + self.assertEqual(st.num_vertices(), 3) + + # find test + self.assertTrue(st.find([0, 1, 2])) + self.assertTrue(st.find([0, 1])) + self.assertTrue(st.find([0, 2])) + self.assertTrue(st.find([0])) + self.assertTrue(st.find([1])) + self.assertTrue(st.find([2])) + self.assertFalse(st.find([3])) + self.assertFalse(st.find([0, 3])) + self.assertFalse(st.find([1, 3])) + self.assertFalse(st.find([2, 3])) + + # filtration test + st.set_filtration(5.0) + st.initialize_filtration() + self.assertEqual(st.get_filtration(), 5.0) + self.assertEqual(st.filtration([0, 1, 2]), 4.0) + self.assertEqual(st.filtration([0, 2]), 4.0) + self.assertEqual(st.filtration([1, 2]), 4.0) + self.assertEqual(st.filtration([2]), 4.0) + self.assertEqual(st.filtration([0, 1]), 0.0) + self.assertEqual(st.filtration([0]), 0.0) + self.assertEqual(st.filtration([1]), 0.0) + + # skeleton_tree test + self.assertEqual(st.get_skeleton_tree(2), + [([0, 1, 2], 4.0), ([0, 1], 0.0), ([0, 2], 4.0), + ([0], 0.0), ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)]) + self.assertEqual(st.get_skeleton_tree(1), + [([0, 1], 0.0), ([0, 2], 4.0), ([0], 0.0), + ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)]) + self.assertEqual(st.get_skeleton_tree(0), + [([0], 0.0), ([1], 0.0), ([2], 4.0)]) + + # remove_maximal_simplex test + self.assertEqual(st.get_coface_tree([0, 1, 2], 1), []) + st.remove_maximal_simplex([0, 1, 2]) + self.assertEqual(st.get_skeleton_tree(2), + [([0, 1], 0.0), ([0, 2], 4.0), ([0], 0.0), + ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)]) + self.assertFalse(st.find([0, 1, 2])) + self.assertTrue(st.find([0, 1])) + self.assertTrue(st.find([0, 2])) + self.assertTrue(st.find([0])) + self.assertTrue(st.find([1])) + self.assertTrue(st.find([2])) + +if __name__ == '__main__': + unittest.main() -- cgit v1.2.3