summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorROUVREAU Vincent <vincent.rouvreau@inria.fr>2019-12-20 16:57:36 +0100
committerROUVREAU Vincent <vincent.rouvreau@inria.fr>2019-12-20 16:57:36 +0100
commitba406558f707f55b638be92d197ae3039595b29a (patch)
treee576f54df58c5c74ab8bff256ac58d03074f946f /src
parent32a9c5e4df26e59f5f376e54c05c7bec92012cff (diff)
Fix dimension cell linearization and test connected sublevel sets
Diffstat (limited to 'src')
-rw-r--r--src/python/gudhi/cubical_complex.pyx2
-rw-r--r--src/python/gudhi/periodic_cubical_complex.pyx2
-rwxr-xr-xsrc/python/test/test_cubical_complex.py28
3 files changed, 29 insertions, 3 deletions
diff --git a/src/python/gudhi/cubical_complex.pyx b/src/python/gudhi/cubical_complex.pyx
index 756a9dab..04b22921 100644
--- a/src/python/gudhi/cubical_complex.pyx
+++ b/src/python/gudhi/cubical_complex.pyx
@@ -78,7 +78,7 @@ cdef class CubicalComplex:
and (perseus_file == '')):
if isinstance(top_dimensional_cells, np.ndarray):
dimensions = top_dimensional_cells.shape
- top_dimensional_cells = top_dimensional_cells.ravel(order='C')
+ top_dimensional_cells = top_dimensional_cells.ravel(order='F')
self.thisptr = new Bitmap_cubical_complex_base_interface(dimensions, top_dimensional_cells)
else:
print("top_dimensional_cells is not an instance of ndarray. It is a " + type(top_dimensional_cells))
diff --git a/src/python/gudhi/periodic_cubical_complex.pyx b/src/python/gudhi/periodic_cubical_complex.pyx
index c3d64123..1d6f1e59 100644
--- a/src/python/gudhi/periodic_cubical_complex.pyx
+++ b/src/python/gudhi/periodic_cubical_complex.pyx
@@ -84,7 +84,7 @@ cdef class PeriodicCubicalComplex:
and (periodic_dimensions is not None) and (perseus_file == '')):
if isinstance(top_dimensional_cells, np.ndarray):
dimensions = top_dimensional_cells.shape
- top_dimensional_cells = top_dimensional_cells.ravel(order='C')
+ top_dimensional_cells = top_dimensional_cells.ravel(order='F')
self.thisptr = new Periodic_cubical_complex_base_interface(dimensions,
top_dimensional_cells,
periodic_dimensions)
diff --git a/src/python/test/test_cubical_complex.py b/src/python/test/test_cubical_complex.py
index 6d4e0309..121da12a 100755
--- a/src/python/test/test_cubical_complex.py
+++ b/src/python/test/test_cubical_complex.py
@@ -1,4 +1,4 @@
-from gudhi import CubicalComplex
+from gudhi import CubicalComplex, PeriodicCubicalComplex
import numpy as np
""" This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
@@ -121,3 +121,29 @@ def test_dimension_file_constructor():
assert cub.__is_persistence_defined() == True
assert cub.betti_numbers() == [1, 0, 0]
assert cub.persistent_betti_numbers(0, 1000) == [1, 0, 0]
+
+def test_connected_sublevel_sets():
+ array_cells = np.array([[3, 3], [2, 2], [4, 4]])
+ linear_cells = [3, 3, 2, 2, 4, 4]
+ dimensions = [2, 3]
+ periodic_dimensions = [False, False]
+ # with a numpy array version
+ cub = CubicalComplex(top_dimensional_cells = array_cells)
+ assert cub.persistence() == [(0, (2.0, float("inf")))]
+ assert cub.betti_numbers() == [1, 0, 0]
+ # with vector of dimensions
+ cub = CubicalComplex(dimensions = dimensions,
+ top_dimensional_cells = linear_cells)
+ assert cub.persistence() == [(0, (2.0, float("inf")))]
+ assert cub.betti_numbers() == [1, 0, 0]
+ # periodic with a numpy array version
+ cub = PeriodicCubicalComplex(top_dimensional_cells = array_cells,
+ periodic_dimensions = periodic_dimensions)
+ assert cub.persistence() == [(0, (2.0, float("inf")))]
+ assert cub.betti_numbers() == [1, 0, 0]
+ # periodic with vector of dimensions
+ cub = PeriodicCubicalComplex(dimensions = dimensions,
+ top_dimensional_cells = linear_cells,
+ periodic_dimensions = periodic_dimensions)
+ assert cub.persistence() == [(0, (2.0, float("inf")))]
+ assert cub.betti_numbers() == [1, 0, 0]