From bcc49c54943e20b117a3a83579d94f6c1b0efd04 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Sat, 4 Jan 2020 12:50:14 +0100 Subject: Link the doc for subsampling & point file readers, some reorg --- src/python/doc/diagram_readers_ref.rst | 11 ++++++++++ src/python/doc/index.rst | 40 ++++++++++++++++------------------ src/python/doc/point_cloud.rst | 22 +++++++++++++++++++ src/python/doc/point_cloud_sum.inc | 15 +++++++++++++ src/python/doc/reader_utils_ref.rst | 15 ------------- src/python/gudhi/off_reader.pyx | 2 +- src/python/gudhi/reader_utils.pyx | 6 ++--- src/python/gudhi/subsampling.pyx | 12 +++++----- 8 files changed, 77 insertions(+), 46 deletions(-) create mode 100644 src/python/doc/diagram_readers_ref.rst create mode 100644 src/python/doc/point_cloud.rst create mode 100644 src/python/doc/point_cloud_sum.inc delete mode 100644 src/python/doc/reader_utils_ref.rst (limited to 'src/python') diff --git a/src/python/doc/diagram_readers_ref.rst b/src/python/doc/diagram_readers_ref.rst new file mode 100644 index 00000000..c79daf9c --- /dev/null +++ b/src/python/doc/diagram_readers_ref.rst @@ -0,0 +1,11 @@ +:orphan: + +.. To get rid of WARNING: document isn't included in any toctree + +================================ +Diagram readers reference manual +================================ + +.. autofunction:: gudhi.read_persistence_intervals_grouped_by_dimension + +.. autofunction:: gudhi.read_persistence_intervals_in_dimension diff --git a/src/python/doc/index.rst b/src/python/doc/index.rst index c36a578f..9513deb0 100644 --- a/src/python/doc/index.rst +++ b/src/python/doc/index.rst @@ -6,8 +6,8 @@ GUDHI Python modules documentation :alt: Gudhi banner :figclass: align-center -Complexes -********* +Data structures for cell complexes +********************************** Cubical complexes ================= @@ -17,18 +17,26 @@ Cubical complexes Simplicial complexes ==================== +Simplex tree +------------ + +.. include:: simplex_tree_sum.inc + +Filtrations and reconstructions +******************************* + Alpha complex -------------- +============= .. include:: alpha_complex_sum.inc Rips complex ------------- +============ .. include:: rips_complex_sum.inc Witness complex ---------------- +=============== .. include:: witness_complex_sum.inc @@ -37,16 +45,10 @@ Cover complexes .. include:: nerve_gic_complex_sum.inc -Data structures and basic operations -************************************ - -Data structures -=============== - -Simplex tree ------------- +Tangential complex +================== -.. include:: simplex_tree_sum.inc +.. include:: tangential_complex_sum.inc Topological descriptors computation *********************************** @@ -56,14 +58,10 @@ Persistence cohomology .. include:: persistent_cohomology_sum.inc -Manifold reconstruction -*********************** - -Tangential complex -================== - -.. include:: tangential_complex_sum.inc +Point cloud utilities +********************* +.. include:: point_cloud_sum.inc Topological descriptors tools ***************************** diff --git a/src/python/doc/point_cloud.rst b/src/python/doc/point_cloud.rst new file mode 100644 index 00000000..6a74d253 --- /dev/null +++ b/src/python/doc/point_cloud.rst @@ -0,0 +1,22 @@ +:orphan: + +.. To get rid of WARNING: document isn't included in any toctree + +============================ +Point cloud utilities manual +============================ + +File Readers +------------ + +.. autofunction:: gudhi.read_off + +.. autofunction:: gudhi.read_lower_triangular_matrix_from_csv_file + +Subsampling +----------- + +.. automodule:: gudhi.subsampling + :members: + :special-members: + :show-inheritance: diff --git a/src/python/doc/point_cloud_sum.inc b/src/python/doc/point_cloud_sum.inc new file mode 100644 index 00000000..cefcf1c8 --- /dev/null +++ b/src/python/doc/point_cloud_sum.inc @@ -0,0 +1,15 @@ +.. table:: + :widths: 30 50 20 + + +----------------------------------------------------------------+------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------+ + | :math:`(x_1, x_2, \ldots, x_d)` | Utilities to process point clouds: read from file, subsample, etc. | :Author: Vincent Rouvreau | + | :math:`(y_1, y_2, \ldots, y_d)` | | | + | | | :Introduced in: GUDHI 2.0.0 | + | | | | + | | | :Copyright: MIT (`GPL v3 `_) | + | | Parts of this package require CGAL. | | + | | | :Requires: `Eigen `__ :math:`\geq` 3.1.0 and `CGAL `__ :math:`\geq` 4.11.0 | + | | | | + +----------------------------------------------------------------+------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------+ + | * :doc:`point_cloud` | + +----------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ diff --git a/src/python/doc/reader_utils_ref.rst b/src/python/doc/reader_utils_ref.rst deleted file mode 100644 index f3ecebad..00000000 --- a/src/python/doc/reader_utils_ref.rst +++ /dev/null @@ -1,15 +0,0 @@ -:orphan: - -.. To get rid of WARNING: document isn't included in any toctree - -============================= -Reader utils reference manual -============================= - -.. autofunction:: gudhi.read_off - -.. autofunction:: gudhi.read_lower_triangular_matrix_from_csv_file - -.. autofunction:: gudhi.read_persistence_intervals_grouped_by_dimension - -.. autofunction:: gudhi.read_persistence_intervals_in_dimension diff --git a/src/python/gudhi/off_reader.pyx b/src/python/gudhi/off_reader.pyx index 225e981c..e45356be 100644 --- a/src/python/gudhi/off_reader.pyx +++ b/src/python/gudhi/off_reader.pyx @@ -26,7 +26,7 @@ def read_off(off_file=''): :type off_file: string :returns: The point set. - :rtype: vector[vector[double]] + :rtype: list(list(float)) """ if off_file: if os.path.isfile(off_file): diff --git a/src/python/gudhi/reader_utils.pyx b/src/python/gudhi/reader_utils.pyx index 6994c4f9..5a756e4b 100644 --- a/src/python/gudhi/reader_utils.pyx +++ b/src/python/gudhi/reader_utils.pyx @@ -34,7 +34,7 @@ def read_lower_triangular_matrix_from_csv_file(csv_file='', separator=';'): :type separator: char :returns: The lower triangular matrix. - :rtype: vector[vector[double]] + :rtype: list(list(float)) """ if csv_file: if path.isfile(csv_file): @@ -45,7 +45,7 @@ def read_lower_triangular_matrix_from_csv_file(csv_file='', separator=';'): def read_persistence_intervals_grouped_by_dimension(persistence_file=''): """Reads a file containing persistence intervals. Each line might contain 2, 3 or 4 values: [[field] dimension] birth death - The return value is an `map[dim, vector[pair[birth, death]]]` + The return value is a `dict(dim, list(tuple(birth, death)))` where `dim` is an `int`, `birth` a `double`, and `death` a `double`. Note: the function does not check that birth <= death. @@ -53,7 +53,7 @@ def read_persistence_intervals_grouped_by_dimension(persistence_file=''): :type persistence_file: string :returns: The persistence pairs grouped by dimension. - :rtype: map[int, vector[pair[double, double]]] + :rtype: dict(int, list(tuple(float, float))) """ if persistence_file: if path.isfile(persistence_file): diff --git a/src/python/gudhi/subsampling.pyx b/src/python/gudhi/subsampling.pyx index e0cd1348..04f66219 100644 --- a/src/python/gudhi/subsampling.pyx +++ b/src/python/gudhi/subsampling.pyx @@ -33,7 +33,7 @@ def choose_n_farthest_points(points=None, off_file='', nb_points=0, starting_poi The iteration starts with the landmark `starting point`. :param points: The input point set. - :type points: vector[vector[double]]. + :type points: list(list(float)). Or @@ -47,7 +47,7 @@ def choose_n_farthest_points(points=None, off_file='', nb_points=0, starting_poi index is chosen randomly. :type starting_point: unsigned. :returns: The subsample point set. - :rtype: vector[vector[double]] + :rtype: list(list(float)). """ if off_file: if os.path.isfile(off_file): @@ -74,7 +74,7 @@ def pick_n_random_points(points=None, off_file='', nb_points=0): """Subsample a point set by picking random vertices. :param points: The input point set. - :type points: vector[vector[double]]. + :type points: list(list(float)). Or @@ -84,7 +84,7 @@ def pick_n_random_points(points=None, off_file='', nb_points=0): :param nb_points: Number of points of the subsample. :type nb_points: unsigned. :returns: The subsample point set. - :rtype: vector[vector[double]] + :rtype: list(list(float)) """ if off_file: if os.path.isfile(off_file): @@ -103,7 +103,7 @@ def sparsify_point_set(points=None, off_file='', min_squared_dist=0.0): between any two points is greater than or equal to min_squared_dist. :param points: The input point set. - :type points: vector[vector[double]]. + :type points: list(list(float)). Or @@ -114,7 +114,7 @@ def sparsify_point_set(points=None, off_file='', min_squared_dist=0.0): points. :type min_squared_dist: float. :returns: The subsample point set. - :rtype: vector[vector[double]] + :rtype: list(list(float)) """ if off_file: if os.path.isfile(off_file): -- cgit v1.2.3 From 18c98020adea4a7d0c53fe4e76c92bab23e7ad76 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Thu, 9 Jan 2020 18:03:39 +0100 Subject: Spell out types as in PEP 484 but don't actually use annotations. A quick try with sphinx-autodoc-typehints failed, I didn't investigate much, it can wait. --- src/python/gudhi/off_reader.pyx | 2 +- src/python/gudhi/reader_utils.pyx | 6 +++--- src/python/gudhi/subsampling.pyx | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/python') diff --git a/src/python/gudhi/off_reader.pyx b/src/python/gudhi/off_reader.pyx index e45356be..3a31eba6 100644 --- a/src/python/gudhi/off_reader.pyx +++ b/src/python/gudhi/off_reader.pyx @@ -26,7 +26,7 @@ def read_off(off_file=''): :type off_file: string :returns: The point set. - :rtype: list(list(float)) + :rtype: List[List[float]] """ if off_file: if os.path.isfile(off_file): diff --git a/src/python/gudhi/reader_utils.pyx b/src/python/gudhi/reader_utils.pyx index 5a756e4b..9ced6bca 100644 --- a/src/python/gudhi/reader_utils.pyx +++ b/src/python/gudhi/reader_utils.pyx @@ -34,7 +34,7 @@ def read_lower_triangular_matrix_from_csv_file(csv_file='', separator=';'): :type separator: char :returns: The lower triangular matrix. - :rtype: list(list(float)) + :rtype: List[List[float]] """ if csv_file: if path.isfile(csv_file): @@ -46,14 +46,14 @@ def read_persistence_intervals_grouped_by_dimension(persistence_file=''): """Reads a file containing persistence intervals. Each line might contain 2, 3 or 4 values: [[field] dimension] birth death The return value is a `dict(dim, list(tuple(birth, death)))` - where `dim` is an `int`, `birth` a `double`, and `death` a `double`. + where `dim` is an `int`, `birth` a `float`, and `death` a `float`. Note: the function does not check that birth <= death. :param persistence_file: A persistence file style name. :type persistence_file: string :returns: The persistence pairs grouped by dimension. - :rtype: dict(int, list(tuple(float, float))) + :rtype: Dict[int, List[Tuple[float, float]]] """ if persistence_file: if path.isfile(persistence_file): diff --git a/src/python/gudhi/subsampling.pyx b/src/python/gudhi/subsampling.pyx index 04f66219..f50f4b0c 100644 --- a/src/python/gudhi/subsampling.pyx +++ b/src/python/gudhi/subsampling.pyx @@ -33,7 +33,7 @@ def choose_n_farthest_points(points=None, off_file='', nb_points=0, starting_poi The iteration starts with the landmark `starting point`. :param points: The input point set. - :type points: list(list(float)). + :type points: Iterable[Iterable[float]]. Or @@ -47,7 +47,7 @@ def choose_n_farthest_points(points=None, off_file='', nb_points=0, starting_poi index is chosen randomly. :type starting_point: unsigned. :returns: The subsample point set. - :rtype: list(list(float)). + :rtype: List[List[float]]. """ if off_file: if os.path.isfile(off_file): @@ -74,7 +74,7 @@ def pick_n_random_points(points=None, off_file='', nb_points=0): """Subsample a point set by picking random vertices. :param points: The input point set. - :type points: list(list(float)). + :type points: Iterable[Iterable[float]]. Or @@ -84,7 +84,7 @@ def pick_n_random_points(points=None, off_file='', nb_points=0): :param nb_points: Number of points of the subsample. :type nb_points: unsigned. :returns: The subsample point set. - :rtype: list(list(float)) + :rtype: List[List[float]] """ if off_file: if os.path.isfile(off_file): @@ -103,7 +103,7 @@ def sparsify_point_set(points=None, off_file='', min_squared_dist=0.0): between any two points is greater than or equal to min_squared_dist. :param points: The input point set. - :type points: list(list(float)). + :type points: Iterable[Iterable[float]]. Or @@ -114,7 +114,7 @@ def sparsify_point_set(points=None, off_file='', min_squared_dist=0.0): points. :type min_squared_dist: float. :returns: The subsample point set. - :rtype: list(list(float)) + :rtype: List[List[float]] """ if off_file: if os.path.isfile(off_file): -- cgit v1.2.3 From 2f7f4d84df64172c1af8b8741112c6dd9c883944 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Thu, 9 Jan 2020 18:22:24 +0100 Subject: Move point utilities in the index they we between computing diagrams and using diagrams, it looked strange --- src/python/doc/index.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/python') diff --git a/src/python/doc/index.rst b/src/python/doc/index.rst index 9513deb0..3387a64f 100644 --- a/src/python/doc/index.rst +++ b/src/python/doc/index.rst @@ -58,11 +58,6 @@ Persistence cohomology .. include:: persistent_cohomology_sum.inc -Point cloud utilities -********************* - -.. include:: point_cloud_sum.inc - Topological descriptors tools ***************************** @@ -86,6 +81,11 @@ Persistence graphical tools .. include:: persistence_graphical_tools_sum.inc +Point cloud utilities +********************* + +.. include:: point_cloud_sum.inc + Bibliography ************ -- cgit v1.2.3 From 051c9760a214a11e8e4af14ae6221e34bb876350 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Thu, 9 Jan 2020 20:56:48 +0100 Subject: align text --- src/python/doc/point_cloud_sum.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/python') diff --git a/src/python/doc/point_cloud_sum.inc b/src/python/doc/point_cloud_sum.inc index cefcf1c8..85d52de7 100644 --- a/src/python/doc/point_cloud_sum.inc +++ b/src/python/doc/point_cloud_sum.inc @@ -2,8 +2,8 @@ :widths: 30 50 20 +----------------------------------------------------------------+------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------+ - | :math:`(x_1, x_2, \ldots, x_d)` | Utilities to process point clouds: read from file, subsample, etc. | :Author: Vincent Rouvreau | - | :math:`(y_1, y_2, \ldots, y_d)` | | | + | | :math:`(x_1, x_2, \ldots, x_d)` | Utilities to process point clouds: read from file, subsample, etc. | :Author: Vincent Rouvreau | + | | :math:`(y_1, y_2, \ldots, y_d)` | | | | | | :Introduced in: GUDHI 2.0.0 | | | | | | | | :Copyright: MIT (`GPL v3 `_) | -- cgit v1.2.3 From 95c34035645e788d98a3fa6b059ad48024596906 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Wed, 15 Jan 2020 10:20:22 +0100 Subject: In python2 itertools zip_longest is named izip_longest --- src/python/test/test_alpha_complex.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/python') diff --git a/src/python/test/test_alpha_complex.py b/src/python/test/test_alpha_complex.py index 712a50b6..0d9e9e45 100755 --- a/src/python/test/test_alpha_complex.py +++ b/src/python/test/test_alpha_complex.py @@ -11,8 +11,13 @@ from gudhi import AlphaComplex, SimplexTree import math import numpy as np -import itertools import pytest +try: + # python3 + from itertools import zip_longest +except ImportError: + # python2 + from itertools import izip_longest as zip_longest __author__ = "Vincent Rouvreau" __copyright__ = "Copyright (C) 2016 Inria" @@ -114,6 +119,6 @@ def test_safe_alpha_persistence_comparison(): diag1 = simplex_tree1.persistence() diag2 = simplex_tree2.persistence() - for (first_p, second_p) in itertools.zip_longest(diag1, diag2): + for (first_p, second_p) in zip_longest(diag1, diag2): assert first_p[0] == pytest.approx(second_p[0]) assert first_p[1] == pytest.approx(second_p[1]) -- cgit v1.2.3 From e1255fe356f1ff97533b33caa6179737a64c4898 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Wed, 15 Jan 2020 10:22:21 +0100 Subject: Fix #96 : set language_level. It does not work when using compiler_directives of cythonize. --- src/python/setup.py.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/python') diff --git a/src/python/setup.py.in b/src/python/setup.py.in index 24d05025..9c2124f4 100644 --- a/src/python/setup.py.in +++ b/src/python/setup.py.in @@ -11,6 +11,7 @@ from setuptools import setup, Extension from Cython.Build import cythonize from numpy import get_include as numpy_get_include +import sys __author__ = "Vincent Rouvreau" __copyright__ = "Copyright (C) 2016 Inria" @@ -38,7 +39,8 @@ for module in modules: libraries=libraries, library_dirs=library_dirs, include_dirs=include_dirs, - runtime_library_dirs=runtime_library_dirs,)) + runtime_library_dirs=runtime_library_dirs, + cython_directives = {'language_level': str(sys.version_info[0])},)) setup( name = 'gudhi', -- cgit v1.2.3 From d747facccbe835be1384e569cf3d6e4c335c0364 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Wed, 15 Jan 2020 10:23:58 +0100 Subject: In python2, does not work. is ok for Python 2 and 3 --- src/python/gudhi/alpha_complex.pyx | 2 +- src/python/gudhi/cubical_complex.pyx | 2 +- src/python/gudhi/nerve_gic.pyx | 12 ++++++------ src/python/gudhi/off_reader.pyx | 2 +- src/python/gudhi/periodic_cubical_complex.pyx | 2 +- src/python/gudhi/reader_utils.pyx | 8 ++++---- src/python/gudhi/simplex_tree.pyx | 2 +- src/python/gudhi/subsampling.pyx | 8 ++++---- src/python/gudhi/tangential_complex.pyx | 2 +- 9 files changed, 20 insertions(+), 20 deletions(-) (limited to 'src/python') diff --git a/src/python/gudhi/alpha_complex.pyx b/src/python/gudhi/alpha_complex.pyx index db11416c..f3ca3dd5 100644 --- a/src/python/gudhi/alpha_complex.pyx +++ b/src/python/gudhi/alpha_complex.pyx @@ -69,7 +69,7 @@ cdef class AlphaComplex: def __cinit__(self, points = None, off_file = ''): if off_file: if os.path.isfile(off_file): - self.thisptr = new Alpha_complex_interface(str.encode(off_file), True) + self.thisptr = new Alpha_complex_interface(off_file.encode('utf-8'), True) else: print("file " + off_file + " not found.") else: diff --git a/src/python/gudhi/cubical_complex.pyx b/src/python/gudhi/cubical_complex.pyx index 92ff6411..cbeda014 100644 --- a/src/python/gudhi/cubical_complex.pyx +++ b/src/python/gudhi/cubical_complex.pyx @@ -85,7 +85,7 @@ cdef class CubicalComplex: elif ((dimensions is None) and (top_dimensional_cells is None) and (perseus_file != '')): if os.path.isfile(perseus_file): - self.thisptr = new Bitmap_cubical_complex_base_interface(str.encode(perseus_file)) + self.thisptr = new Bitmap_cubical_complex_base_interface(perseus_file.encode('utf-8')) else: print("file " + perseus_file + " not found.") else: diff --git a/src/python/gudhi/nerve_gic.pyx b/src/python/gudhi/nerve_gic.pyx index 68c06432..382e71c5 100644 --- a/src/python/gudhi/nerve_gic.pyx +++ b/src/python/gudhi/nerve_gic.pyx @@ -180,7 +180,7 @@ cdef class CoverComplex: :returns: Read file status. """ if os.path.isfile(off_file): - return self.thisptr.read_point_cloud(str.encode(off_file)) + return self.thisptr.read_point_cloud(off_file.encode('utf-8')) else: print("file " + off_file + " not found.") return False @@ -212,7 +212,7 @@ cdef class CoverComplex: :type color_file_name: string """ if os.path.isfile(color_file_name): - self.thisptr.set_color_from_file(str.encode(color_file_name)) + self.thisptr.set_color_from_file(color_file_name.encode('utf-8')) else: print("file " + color_file_name + " not found.") @@ -233,7 +233,7 @@ cdef class CoverComplex: :type cover_file_name: string """ if os.path.isfile(cover_file_name): - self.thisptr.set_cover_from_file(str.encode(cover_file_name)) + self.thisptr.set_cover_from_file(cover_file_name.encode('utf-8')) else: print("file " + cover_file_name + " not found.") @@ -266,7 +266,7 @@ cdef class CoverComplex: :type func_file_name: string """ if os.path.isfile(func_file_name): - self.thisptr.set_function_from_file(str.encode(func_file_name)) + self.thisptr.set_function_from_file(func_file_name.encode('utf-8')) else: print("file " + func_file_name + " not found.") @@ -307,7 +307,7 @@ cdef class CoverComplex: :type graph_file_name: string """ if os.path.isfile(graph_file_name): - self.thisptr.set_graph_from_file(str.encode(graph_file_name)) + self.thisptr.set_graph_from_file(graph_file_name.encode('utf-8')) else: print("file " + graph_file_name + " not found.") @@ -368,7 +368,7 @@ cdef class CoverComplex: :param type: either "GIC" or "Nerve". :type type: string """ - self.thisptr.set_type(str.encode(type)) + self.thisptr.set_type(type.encode('utf-8')) def set_verbose(self, verbose): """Specifies whether the program should display information or not. diff --git a/src/python/gudhi/off_reader.pyx b/src/python/gudhi/off_reader.pyx index 58f05db8..a0d5bf25 100644 --- a/src/python/gudhi/off_reader.pyx +++ b/src/python/gudhi/off_reader.pyx @@ -30,7 +30,7 @@ def read_points_from_off_file(off_file=''): """ if off_file: if os.path.isfile(off_file): - return read_points_from_OFF_file(str.encode(off_file)) + return read_points_from_OFF_file(off_file.encode('utf-8')) else: print("file " + off_file + " not found.") return [] diff --git a/src/python/gudhi/periodic_cubical_complex.pyx b/src/python/gudhi/periodic_cubical_complex.pyx index b5dece10..37f76201 100644 --- a/src/python/gudhi/periodic_cubical_complex.pyx +++ b/src/python/gudhi/periodic_cubical_complex.pyx @@ -93,7 +93,7 @@ cdef class PeriodicCubicalComplex: elif ((dimensions is None) and (top_dimensional_cells is None) and (periodic_dimensions is None) and (perseus_file != '')): if os.path.isfile(perseus_file): - self.thisptr = new Periodic_cubical_complex_base_interface(str.encode(perseus_file)) + self.thisptr = new Periodic_cubical_complex_base_interface(perseus_file.encode('utf-8')) else: print("file " + perseus_file + " not found.") else: diff --git a/src/python/gudhi/reader_utils.pyx b/src/python/gudhi/reader_utils.pyx index 345c92f8..d6033b86 100644 --- a/src/python/gudhi/reader_utils.pyx +++ b/src/python/gudhi/reader_utils.pyx @@ -38,7 +38,7 @@ def read_lower_triangular_matrix_from_csv_file(csv_file='', separator=';'): """ if csv_file: if path.isfile(csv_file): - return read_matrix_from_csv_file(str.encode(csv_file), ord(separator[0])) + return read_matrix_from_csv_file(csv_file.encode('utf-8'), ord(separator[0])) print("file " + csv_file + " not set or not found.") return [] @@ -57,7 +57,7 @@ def read_persistence_intervals_grouped_by_dimension(persistence_file=''): """ if persistence_file: if path.isfile(persistence_file): - return read_pers_intervals_grouped_by_dimension(str.encode(persistence_file)) + return read_pers_intervals_grouped_by_dimension(persistence_file.encode('utf-8')) print("file " + persistence_file + " not set or not found.") return [] @@ -80,7 +80,7 @@ def read_persistence_intervals_in_dimension(persistence_file='', only_this_dim=- """ if persistence_file: if path.isfile(persistence_file): - return np_array(read_pers_intervals_in_dimension(str.encode( - persistence_file), only_this_dim)) + return np_array(read_pers_intervals_in_dimension(persistence_file.encode( + 'utf-8'), only_this_dim)) print("file " + persistence_file + " not set or not found.") return [] diff --git a/src/python/gudhi/simplex_tree.pyx b/src/python/gudhi/simplex_tree.pyx index 85d25492..b18627c4 100644 --- a/src/python/gudhi/simplex_tree.pyx +++ b/src/python/gudhi/simplex_tree.pyx @@ -508,7 +508,7 @@ cdef class SimplexTree: """ if self.pcohptr != NULL: if persistence_file != '': - self.pcohptr.write_output_diagram(str.encode(persistence_file)) + self.pcohptr.write_output_diagram(persistence_file.encode('utf-8')) else: print("persistence_file must be specified") else: diff --git a/src/python/gudhi/subsampling.pyx b/src/python/gudhi/subsampling.pyx index b1812087..c501d16b 100644 --- a/src/python/gudhi/subsampling.pyx +++ b/src/python/gudhi/subsampling.pyx @@ -52,10 +52,10 @@ def choose_n_farthest_points(points=None, off_file='', nb_points=0, starting_poi if off_file: if os.path.isfile(off_file): if starting_point == '': - return subsampling_n_farthest_points_from_file(str.encode(off_file), + return subsampling_n_farthest_points_from_file(off_file.encode('utf-8'), nb_points) else: - return subsampling_n_farthest_points_from_file(str.encode(off_file), + return subsampling_n_farthest_points_from_file(off_file.encode('utf-8'), nb_points, starting_point) else: @@ -88,7 +88,7 @@ def pick_n_random_points(points=None, off_file='', nb_points=0): """ if off_file: if os.path.isfile(off_file): - return subsampling_n_random_points_from_file(str.encode(off_file), + return subsampling_n_random_points_from_file(off_file.encode('utf-8'), nb_points) else: print("file " + off_file + " not found.") @@ -118,7 +118,7 @@ def sparsify_point_set(points=None, off_file='', min_squared_dist=0.0): """ if off_file: if os.path.isfile(off_file): - return subsampling_sparsify_points_from_file(str.encode(off_file), + return subsampling_sparsify_points_from_file(off_file.encode('utf-8'), min_squared_dist) else: print("file " + off_file + " not found.") diff --git a/src/python/gudhi/tangential_complex.pyx b/src/python/gudhi/tangential_complex.pyx index 0083033c..6391488c 100644 --- a/src/python/gudhi/tangential_complex.pyx +++ b/src/python/gudhi/tangential_complex.pyx @@ -66,7 +66,7 @@ cdef class TangentialComplex: def __cinit__(self, intrisic_dim, points=None, off_file=''): if off_file: if os.path.isfile(off_file): - self.thisptr = new Tangential_complex_interface(intrisic_dim, str.encode(off_file), True) + self.thisptr = new Tangential_complex_interface(intrisic_dim, off_file.encode('utf-8'), True) else: print("file " + off_file + " not found.") else: -- cgit v1.2.3 From f5e49792f809b198908a67e674672a676c0877ec Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Sat, 18 Jan 2020 22:56:22 +0100 Subject: Separate optional arguments from common arguments I copy-pasted what is done in RipsComplex. Before that, sphinx was grouping nb_points with off_file, as if it couldn't be used with points. --- src/python/gudhi/subsampling.pyx | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/python') diff --git a/src/python/gudhi/subsampling.pyx b/src/python/gudhi/subsampling.pyx index 4c84cb03..f77c6f75 100644 --- a/src/python/gudhi/subsampling.pyx +++ b/src/python/gudhi/subsampling.pyx @@ -40,6 +40,8 @@ def choose_n_farthest_points(points=None, off_file='', nb_points=0, starting_poi :param off_file: An OFF file style name. :type off_file: string + And in both cases + :param nb_points: Number of points of the subsample. :type nb_points: unsigned. :param starting_point: The iteration starts with the landmark `starting \ @@ -81,6 +83,8 @@ def pick_n_random_points(points=None, off_file='', nb_points=0): :param off_file: An OFF file style name. :type off_file: string + And in both cases + :param nb_points: Number of points of the subsample. :type nb_points: unsigned. :returns: The subsample point set. @@ -110,6 +114,8 @@ def sparsify_point_set(points=None, off_file='', min_squared_dist=0.0): :param off_file: An OFF file style name. :type off_file: string + And in both cases + :param min_squared_dist: Minimum squared distance separating the output \ points. :type min_squared_dist: float. -- cgit v1.2.3 From b36d27e63a6e60e3b84346aa3b3a95014b30068e Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Thu, 21 Nov 2019 23:49:07 +0100 Subject: Sprinkle some "except +" in cython files --- src/python/gudhi/alpha_complex.pyx | 11 +++++------ src/python/gudhi/euclidean_strong_witness_complex.pyx | 4 ++-- src/python/gudhi/euclidean_witness_complex.pyx | 4 ++-- src/python/gudhi/rips_complex.pyx | 2 +- src/python/gudhi/simplex_tree.pxd | 2 +- src/python/gudhi/strong_witness_complex.pyx | 4 ++-- src/python/gudhi/witness_complex.pyx | 4 ++-- src/python/include/Alpha_complex_interface.h | 10 +++------- 8 files changed, 18 insertions(+), 23 deletions(-) (limited to 'src/python') diff --git a/src/python/gudhi/alpha_complex.pyx b/src/python/gudhi/alpha_complex.pyx index f3ca3dd5..fff3e920 100644 --- a/src/python/gudhi/alpha_complex.pyx +++ b/src/python/gudhi/alpha_complex.pyx @@ -24,11 +24,11 @@ __license__ = "GPL v3" cdef extern from "Alpha_complex_interface.h" namespace "Gudhi": cdef cppclass Alpha_complex_interface "Gudhi::alpha_complex::Alpha_complex_interface": - Alpha_complex_interface(vector[vector[double]] points) + Alpha_complex_interface(vector[vector[double]] points) except + # 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) + Alpha_complex_interface(string off_file, bool from_file) except + + vector[double] get_point(int vertex) except + + void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, double max_alpha_square) except + # AlphaComplex python interface cdef class AlphaComplex: @@ -96,8 +96,7 @@ cdef class AlphaComplex: :rtype: list of float :returns: the point. """ - cdef vector[double] point = self.thisptr.get_point(vertex) - return point + return self.thisptr.get_point(vertex) def create_simplex_tree(self, max_alpha_square = float('inf')): """ diff --git a/src/python/gudhi/euclidean_strong_witness_complex.pyx b/src/python/gudhi/euclidean_strong_witness_complex.pyx index 9889f92c..aca6084e 100644 --- a/src/python/gudhi/euclidean_strong_witness_complex.pyx +++ b/src/python/gudhi/euclidean_strong_witness_complex.pyx @@ -22,9 +22,9 @@ __license__ = "GPL v3" cdef extern from "Euclidean_strong_witness_complex_interface.h" namespace "Gudhi": cdef cppclass Euclidean_strong_witness_complex_interface "Gudhi::witness_complex::Euclidean_strong_witness_complex_interface": Euclidean_strong_witness_complex_interface(vector[vector[double]] landmarks, vector[vector[double]] witnesses) - 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) except + void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, double max_alpha_square, - unsigned limit_dimension) + unsigned limit_dimension) except + vector[double] get_point(unsigned vertex) # EuclideanStrongWitnessComplex python interface diff --git a/src/python/gudhi/euclidean_witness_complex.pyx b/src/python/gudhi/euclidean_witness_complex.pyx index e3ce0e82..fb0c2201 100644 --- a/src/python/gudhi/euclidean_witness_complex.pyx +++ b/src/python/gudhi/euclidean_witness_complex.pyx @@ -22,9 +22,9 @@ __license__ = "GPL v3" cdef extern from "Euclidean_witness_complex_interface.h" namespace "Gudhi": cdef cppclass Euclidean_witness_complex_interface "Gudhi::witness_complex::Euclidean_witness_complex_interface": Euclidean_witness_complex_interface(vector[vector[double]] landmarks, vector[vector[double]] witnesses) - 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) except + void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, double max_alpha_square, - unsigned limit_dimension) + unsigned limit_dimension) except + vector[double] get_point(unsigned vertex) # EuclideanWitnessComplex python interface diff --git a/src/python/gudhi/rips_complex.pyx b/src/python/gudhi/rips_complex.pyx index 722cdcdc..deb8057a 100644 --- a/src/python/gudhi/rips_complex.pyx +++ b/src/python/gudhi/rips_complex.pyx @@ -28,7 +28,7 @@ cdef extern from "Rips_complex_interface.h" namespace "Gudhi": void init_matrix(vector[vector[double]] values, double threshold) void init_points_sparse(vector[vector[double]] values, double threshold, double sparse) void init_matrix_sparse(vector[vector[double]] values, double threshold, double sparse) - void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, int dim_max) + void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, int dim_max) except + # RipsComplex python interface cdef class RipsComplex: diff --git a/src/python/gudhi/simplex_tree.pxd b/src/python/gudhi/simplex_tree.pxd index 1066d44b..96d14079 100644 --- a/src/python/gudhi/simplex_tree.pxd +++ b/src/python/gudhi/simplex_tree.pxd @@ -39,7 +39,7 @@ cdef extern from "Simplex_tree_interface.h" namespace "Gudhi": vector[pair[vector[int], double]] get_star(vector[int] simplex) vector[pair[vector[int], double]] get_cofaces(vector[int] simplex, int dimension) - void expansion(int max_dim) + void expansion(int max_dim) except + void remove_maximal_simplex(vector[int] simplex) bool prune_above_filtration(double filtration) bool make_filtration_non_decreasing() diff --git a/src/python/gudhi/strong_witness_complex.pyx b/src/python/gudhi/strong_witness_complex.pyx index 2c33c3f2..9f89d3ae 100644 --- a/src/python/gudhi/strong_witness_complex.pyx +++ b/src/python/gudhi/strong_witness_complex.pyx @@ -22,9 +22,9 @@ __license__ = "MIT" cdef extern from "Strong_witness_complex_interface.h" namespace "Gudhi": cdef cppclass Strong_witness_complex_interface "Gudhi::witness_complex::Strong_witness_complex_interface": Strong_witness_complex_interface(vector[vector[pair[size_t, double]]] nearest_landmark_table) - 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) except + void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, double max_alpha_square, - unsigned limit_dimension) + unsigned limit_dimension) except + # StrongWitnessComplex python interface cdef class StrongWitnessComplex: diff --git a/src/python/gudhi/witness_complex.pyx b/src/python/gudhi/witness_complex.pyx index b032a5a1..e589d006 100644 --- a/src/python/gudhi/witness_complex.pyx +++ b/src/python/gudhi/witness_complex.pyx @@ -22,9 +22,9 @@ __license__ = "MIT" cdef extern from "Witness_complex_interface.h" namespace "Gudhi": cdef cppclass Witness_complex_interface "Gudhi::witness_complex::Witness_complex_interface": Witness_complex_interface(vector[vector[pair[size_t, double]]] nearest_landmark_table) - 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) except + void create_simplex_tree(Simplex_tree_interface_full_featured* simplex_tree, double max_alpha_square, - unsigned limit_dimension) + unsigned limit_dimension) except + # WitnessComplex python interface cdef class WitnessComplex: diff --git a/src/python/include/Alpha_complex_interface.h b/src/python/include/Alpha_complex_interface.h index e9bbadb0..8614eee3 100644 --- a/src/python/include/Alpha_complex_interface.h +++ b/src/python/include/Alpha_complex_interface.h @@ -50,13 +50,9 @@ class Alpha_complex_interface { std::vector get_point(int vh) { std::vector vd; - try { - Point_d const& ph = alpha_complex_->get_point(vh); - for (auto coord = ph.cartesian_begin(); coord != ph.cartesian_end(); coord++) - vd.push_back(CGAL::to_double(*coord)); - } catch (std::out_of_range const&) { - // std::out_of_range is thrown in case not found. Other exceptions must be re-thrown - } + Point_d const& ph = alpha_complex_->get_point(vh); + for (auto coord = ph.cartesian_begin(); coord != ph.cartesian_end(); coord++) + vd.push_back(CGAL::to_double(*coord)); return vd; } -- cgit v1.2.3 From d9bdb64a5bc016c5bc34f95f29773050e90aa7ed Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Fri, 22 Nov 2019 00:14:08 +0100 Subject: Adapt tests It is still failing by default, until I touch alpha_complex.pyx and rebuild it, after which it works ?! --- .../example/alpha_complex_from_points_example.py | 7 +++++- src/python/test/test_alpha_complex.py | 28 ++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) (limited to 'src/python') diff --git a/src/python/example/alpha_complex_from_points_example.py b/src/python/example/alpha_complex_from_points_example.py index a746998c..844d7a82 100755 --- a/src/python/example/alpha_complex_from_points_example.py +++ b/src/python/example/alpha_complex_from_points_example.py @@ -52,4 +52,9 @@ print("star([0])=", simplex_tree.get_star([0])) print("coface([0], 1)=", simplex_tree.get_cofaces([0], 1)) print("point[0]=", alpha_complex.get_point(0)) -print("point[5]=", alpha_complex.get_point(5)) +try: + print("point[5]=", alpha_complex.get_point(5)) +except IndexError: + pass +else: + assert False diff --git a/src/python/test/test_alpha_complex.py b/src/python/test/test_alpha_complex.py index 0d9e9e45..3761fe16 100755 --- a/src/python/test/test_alpha_complex.py +++ b/src/python/test/test_alpha_complex.py @@ -65,8 +65,18 @@ def test_infinite_alpha(): assert point_list[1] == alpha_complex.get_point(1) assert point_list[2] == alpha_complex.get_point(2) assert point_list[3] == alpha_complex.get_point(3) - assert alpha_complex.get_point(4) == [] - assert alpha_complex.get_point(125) == [] + try: + alpha_complex.get_point(4) == [] + except IndexError: + pass + else: + assert False + try: + alpha_complex.get_point(125) == [] + except IndexError: + pass + else: + assert False def test_filtered_alpha(): @@ -82,8 +92,18 @@ def test_filtered_alpha(): assert point_list[1] == filtered_alpha.get_point(1) assert point_list[2] == filtered_alpha.get_point(2) assert point_list[3] == filtered_alpha.get_point(3) - assert filtered_alpha.get_point(4) == [] - assert filtered_alpha.get_point(125) == [] + try: + filtered_alpha.get_point(4) == [] + except IndexError: + pass + else: + assert False + try: + filtered_alpha.get_point(125) == [] + except IndexError: + pass + else: + assert False assert simplex_tree.get_filtration() == [ ([0], 0.0), -- cgit v1.2.3