summaryrefslogtreecommitdiff
path: root/src/cython/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/cython/test')
-rwxr-xr-xsrc/cython/test/test_alpha_complex.py58
-rwxr-xr-xsrc/cython/test/test_bottleneck_distance.py8
-rwxr-xr-xsrc/cython/test/test_cover_complex.py59
-rwxr-xr-xsrc/cython/test/test_cubical_complex.py59
-rwxr-xr-xsrc/cython/test/test_euclidean_witness_complex.py68
-rwxr-xr-xsrc/cython/test/test_reader_utils.py105
-rwxr-xr-xsrc/cython/test/test_rips_complex.py92
-rwxr-xr-xsrc/cython/test/test_simplex_tree.py133
-rwxr-xr-xsrc/cython/test/test_subsampling.py140
-rwxr-xr-xsrc/cython/test/test_tangential_complex.py16
-rwxr-xr-xsrc/cython/test/test_witness_complex.py40
11 files changed, 524 insertions, 254 deletions
diff --git a/src/cython/test/test_alpha_complex.py b/src/cython/test/test_alpha_complex.py
index a573115a..24f8bf53 100755
--- a/src/cython/test/test_alpha_complex.py
+++ b/src/cython/test/test_alpha_complex.py
@@ -16,9 +16,10 @@ __license__ = "MIT"
def test_empty_alpha():
- alpha_complex = AlphaComplex(points=[[0,0]])
+ alpha_complex = AlphaComplex(points=[[0, 0]])
assert alpha_complex.__is_defined() == True
+
def test_infinite_alpha():
point_list = [[0, 0], [1, 0], [0, 1], [1, 1]]
alpha_complex = AlphaComplex(points=point_list)
@@ -29,18 +30,28 @@ def test_infinite_alpha():
assert simplex_tree.num_simplices() == 11
assert simplex_tree.num_vertices() == 4
-
- assert simplex_tree.get_filtration() == \
- [([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)]
- assert simplex_tree.get_star([0]) == \
- [([0], 0.0), ([0, 1], 0.25), ([0, 1, 2], 0.5),
- ([0, 2], 0.25)]
- assert simplex_tree.get_cofaces([0], 1) == \
- [([0, 1], 0.25), ([0, 2], 0.25)]
-
+
+ assert simplex_tree.get_filtration() == [
+ ([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),
+ ]
+ assert simplex_tree.get_star([0]) == [
+ ([0], 0.0),
+ ([0, 1], 0.25),
+ ([0, 1, 2], 0.5),
+ ([0, 2], 0.25),
+ ]
+ assert simplex_tree.get_cofaces([0], 1) == [([0, 1], 0.25), ([0, 2], 0.25)]
+
assert point_list[0] == alpha_complex.get_point(0)
assert point_list[1] == alpha_complex.get_point(1)
assert point_list[2] == alpha_complex.get_point(2)
@@ -48,6 +59,7 @@ def test_infinite_alpha():
assert alpha_complex.get_point(4) == []
assert alpha_complex.get_point(125) == []
+
def test_filtered_alpha():
point_list = [[0, 0], [1, 0], [0, 1], [1, 1]]
filtered_alpha = AlphaComplex(points=point_list)
@@ -64,11 +76,15 @@ def test_filtered_alpha():
assert filtered_alpha.get_point(4) == []
assert filtered_alpha.get_point(125) == []
- assert simplex_tree.get_filtration() == \
- [([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)]
- assert simplex_tree.get_star([0]) == \
- [([0], 0.0), ([0, 1], 0.25), ([0, 2], 0.25)]
- assert simplex_tree.get_cofaces([0], 1) == \
- [([0, 1], 0.25), ([0, 2], 0.25)]
+ assert simplex_tree.get_filtration() == [
+ ([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),
+ ]
+ assert simplex_tree.get_star([0]) == [([0], 0.0), ([0, 1], 0.25), ([0, 2], 0.25)]
+ assert simplex_tree.get_cofaces([0], 1) == [([0, 1], 0.25), ([0, 2], 0.25)]
diff --git a/src/cython/test/test_bottleneck_distance.py b/src/cython/test/test_bottleneck_distance.py
index 409fba9c..f5f019b9 100755
--- a/src/cython/test/test_bottleneck_distance.py
+++ b/src/cython/test/test_bottleneck_distance.py
@@ -16,8 +16,8 @@ __license__ = "MIT"
def test_basic_bottleneck():
- diag1 = [[2.7, 3.7],[9.6, 14.],[34.2, 34.974], [3.,float('Inf')]]
- diag2 = [[2.8, 4.45],[9.5, 14.1],[3.2,float('Inf')]]
+ diag1 = [[2.7, 3.7], [9.6, 14.0], [34.2, 34.974], [3.0, float("Inf")]]
+ diag2 = [[2.8, 4.45], [9.5, 14.1], [3.2, float("Inf")]]
- assert(gudhi.bottleneck_distance(diag1, diag2, 0.1) == 0.8081763781405569)
- assert(gudhi.bottleneck_distance(diag1, diag2) == 0.75)
+ assert gudhi.bottleneck_distance(diag1, diag2, 0.1) == 0.8081763781405569
+ assert gudhi.bottleneck_distance(diag1, diag2) == 0.75
diff --git a/src/cython/test/test_cover_complex.py b/src/cython/test/test_cover_complex.py
index 1eb4ed37..8cd12272 100755
--- a/src/cython/test/test_cover_complex.py
+++ b/src/cython/test/test_cover_complex.py
@@ -20,61 +20,66 @@ def test_empty_constructor():
cover = CoverComplex()
assert cover.__is_defined() == True
+
def test_non_existing_file_read():
# Try to open a non existing file
cover = CoverComplex()
- assert (cover.read_point_cloud('pouetpouettralala.toubiloubabdou') == False)
+ assert cover.read_point_cloud("pouetpouettralala.toubiloubabdou") == False
+
def test_files_creation():
# Create test file
- cloud_file = open('cloud', 'w')
- cloud_file.write('nOFF\n3\n3 0 0\n0 0 0\n2 1 0\n4 0 0')
+ cloud_file = open("cloud", "w")
+ cloud_file.write("nOFF\n3\n3 0 0\n0 0 0\n2 1 0\n4 0 0")
cloud_file.close()
- cover_file = open('cover', 'w')
- cover_file.write('1\n2\n3')
+ cover_file = open("cover", "w")
+ cover_file.write("1\n2\n3")
cover_file.close()
- graph_file = open('graph', 'w')
- graph_file.write('0 1\n0 2\n1 2')
+ graph_file = open("graph", "w")
+ graph_file.write("0 1\n0 2\n1 2")
graph_file.close()
+
def test_nerve():
nerve = CoverComplex()
- nerve.set_type('Nerve')
- assert (nerve.read_point_cloud('cloud') == True)
+ nerve.set_type("Nerve")
+ assert nerve.read_point_cloud("cloud") == True
nerve.set_color_from_coordinate()
- nerve.set_graph_from_file('graph')
- nerve.set_cover_from_file('cover')
+ nerve.set_graph_from_file("graph")
+ nerve.set_cover_from_file("cover")
nerve.find_simplices()
stree = nerve.create_simplex_tree()
- assert (stree.num_vertices() == 3)
- assert ((stree.num_simplices() - stree.num_vertices()) == 0)
- assert (stree.dimension() == 0)
+ assert stree.num_vertices() == 3
+ assert (stree.num_simplices() - stree.num_vertices()) == 0
+ assert stree.dimension() == 0
+
def test_graph_induced_complex():
gic = CoverComplex()
- gic.set_type('GIC')
- assert (gic.read_point_cloud('cloud') == True)
+ gic.set_type("GIC")
+ assert gic.read_point_cloud("cloud") == True
gic.set_color_from_coordinate()
- gic.set_graph_from_file('graph')
- gic.set_cover_from_file('cover')
+ gic.set_graph_from_file("graph")
+ gic.set_cover_from_file("cover")
gic.find_simplices()
stree = gic.create_simplex_tree()
- assert (stree.num_vertices() == 3)
- assert ((stree.num_simplices() - stree.num_vertices()) == 4)
- assert (stree.dimension() == 2)
+ assert stree.num_vertices() == 3
+ assert (stree.num_simplices() - stree.num_vertices()) == 4
+ assert stree.dimension() == 2
+
def test_voronoi_graph_induced_complex():
gic = CoverComplex()
- gic.set_type('GIC')
- assert (gic.read_point_cloud('cloud') == True)
+ gic.set_type("GIC")
+ assert gic.read_point_cloud("cloud") == True
gic.set_color_from_coordinate()
- gic.set_graph_from_file('graph')
+ gic.set_graph_from_file("graph")
gic.set_cover_from_Voronoi(2)
gic.find_simplices()
stree = gic.create_simplex_tree()
- assert (stree.num_vertices() == 2)
- assert ((stree.num_simplices() - stree.num_vertices()) == 1)
- assert (stree.dimension() == 1)
+ assert stree.num_vertices() == 2
+ assert (stree.num_simplices() - stree.num_vertices()) == 1
+ assert stree.dimension() == 1
diff --git a/src/cython/test/test_cubical_complex.py b/src/cython/test/test_cubical_complex.py
index 6dc7fdfc..68f54fbe 100755
--- a/src/cython/test/test_cubical_complex.py
+++ b/src/cython/test/test_cubical_complex.py
@@ -21,65 +21,78 @@ def test_empty_constructor():
assert cub.__is_defined() == False
assert cub.__is_persistence_defined() == False
+
def test_non_existing_perseus_file_constructor():
# Try to open a non existing file
- cub = CubicalComplex(perseus_file='pouetpouettralala.toubiloubabdou')
+ cub = CubicalComplex(perseus_file="pouetpouettralala.toubiloubabdou")
assert cub.__is_defined() == False
assert cub.__is_persistence_defined() == False
+
def test_dimension_or_perseus_file_constructor():
# Create test file
- test_file = open('CubicalOneSphere.txt', 'w')
- test_file.write('2\n3\n3\n0\n0\n0\n0\n100\n0\n0\n0\n0\n')
+ test_file = open("CubicalOneSphere.txt", "w")
+ test_file.write("2\n3\n3\n0\n0\n0\n0\n100\n0\n0\n0\n0\n")
test_file.close()
# CubicalComplex can be constructed from dimensions and
# top_dimensional_cells OR from a Perseus-style file name.
- cub = CubicalComplex(dimensions=[3, 3],
- top_dimensional_cells = [1,2,3,4,5,6,7,8,9],
- perseus_file='CubicalOneSphere.txt')
+ cub = CubicalComplex(
+ dimensions=[3, 3],
+ top_dimensional_cells=[1, 2, 3, 4, 5, 6, 7, 8, 9],
+ perseus_file="CubicalOneSphere.txt",
+ )
assert cub.__is_defined() == False
assert cub.__is_persistence_defined() == False
- cub = CubicalComplex(top_dimensional_cells = [1,2,3,4,5,6,7,8,9],
- perseus_file='CubicalOneSphere.txt')
+ cub = CubicalComplex(
+ top_dimensional_cells=[1, 2, 3, 4, 5, 6, 7, 8, 9],
+ perseus_file="CubicalOneSphere.txt",
+ )
assert cub.__is_defined() == False
assert cub.__is_persistence_defined() == False
- cub = CubicalComplex(dimensions=[3, 3],
- perseus_file='CubicalOneSphere.txt')
+ cub = CubicalComplex(dimensions=[3, 3], perseus_file="CubicalOneSphere.txt")
assert cub.__is_defined() == False
assert cub.__is_persistence_defined() == False
+
def test_dimension_simple_constructor():
- cub = CubicalComplex(dimensions=[3, 3],
- top_dimensional_cells = [1,2,3,4,5,6,7,8,9])
+ cub = CubicalComplex(
+ dimensions=[3, 3], top_dimensional_cells=[1, 2, 3, 4, 5, 6, 7, 8, 9]
+ )
assert cub.__is_defined() == True
assert cub.__is_persistence_defined() == False
- assert cub.persistence() == [(0, (1.0, float('inf')))]
+ assert cub.persistence() == [(0, (1.0, float("inf")))]
assert cub.__is_persistence_defined() == True
assert cub.betti_numbers() == [1, 0, 0]
assert cub.persistent_betti_numbers(0, 1000) == [0, 0, 0]
+
def test_user_case_simple_constructor():
- cub = CubicalComplex(dimensions=[3, 3],
- top_dimensional_cells = [float('inf'), 0.,0.,0.,1.,0.,0.,0.,0.])
+ cub = CubicalComplex(
+ dimensions=[3, 3],
+ top_dimensional_cells=[float("inf"), 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0],
+ )
assert cub.__is_defined() == True
assert cub.__is_persistence_defined() == False
- assert cub.persistence() == [(1, (0.0, 1.0)), (0, (0.0, float('inf')))]
+ assert cub.persistence() == [(1, (0.0, 1.0)), (0, (0.0, float("inf")))]
assert cub.__is_persistence_defined() == True
- other_cub = CubicalComplex(dimensions=[3, 3],
- top_dimensional_cells = [1000., 0.,0.,0.,1.,0.,0.,0.,0.])
- assert other_cub.persistence() == [(1, (0.0, 1.0)), (0, (0.0, float('inf')))]
+ other_cub = CubicalComplex(
+ dimensions=[3, 3],
+ top_dimensional_cells=[1000.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0],
+ )
+ assert other_cub.persistence() == [(1, (0.0, 1.0)), (0, (0.0, float("inf")))]
+
def test_dimension_file_constructor():
# Create test file
- test_file = open('CubicalOneSphere.txt', 'w')
- test_file.write('2\n3\n3\n0\n0\n0\n0\n100\n0\n0\n0\n0\n')
+ test_file = open("CubicalOneSphere.txt", "w")
+ test_file.write("2\n3\n3\n0\n0\n0\n0\n100\n0\n0\n0\n0\n")
test_file.close()
- cub = CubicalComplex(perseus_file='CubicalOneSphere.txt')
+ cub = CubicalComplex(perseus_file="CubicalOneSphere.txt")
assert cub.__is_defined() == True
assert cub.__is_persistence_defined() == False
- assert cub.persistence() == [(1, (0.0, 100.0)), (0, (0.0, float('inf')))]
+ assert cub.persistence() == [(1, (0.0, 100.0)), (0, (0.0, float("inf")))]
assert cub.__is_persistence_defined() == True
assert cub.betti_numbers() == [1, 0, 0]
assert cub.persistent_betti_numbers(0, 1000) == [1, 0, 0]
diff --git a/src/cython/test/test_euclidean_witness_complex.py b/src/cython/test/test_euclidean_witness_complex.py
index c8510b1e..f5eae5fa 100755
--- a/src/cython/test/test_euclidean_witness_complex.py
+++ b/src/cython/test/test_euclidean_witness_complex.py
@@ -19,31 +19,60 @@ def test_empty_euclidean_witness_complex():
euclidean_witness = gudhi.EuclideanWitnessComplex()
assert euclidean_witness.__is_defined() == False
+
def test_witness_complex():
- point_cloud = [[1.0, 1.0], [7.0, 0.0], [4.0, 6.0], [9.0, 6.0],
- [0.0, 14.0], [2.0, 19.0], [9.0, 17.0]]
+ point_cloud = [
+ [1.0, 1.0],
+ [7.0, 0.0],
+ [4.0, 6.0],
+ [9.0, 6.0],
+ [0.0, 14.0],
+ [2.0, 19.0],
+ [9.0, 17.0],
+ ]
landmarks = [[1.0, 1.0], [7.0, 0.0], [4.0, 6.0]]
- euclidean_witness_complex = gudhi.EuclideanWitnessComplex(landmarks=landmarks, witnesses = point_cloud)
+ euclidean_witness_complex = gudhi.EuclideanWitnessComplex(
+ landmarks=landmarks, witnesses=point_cloud
+ )
simplex_tree = euclidean_witness_complex.create_simplex_tree(max_alpha_square=4.1)
assert landmarks[0] == euclidean_witness_complex.get_point(0)
assert landmarks[1] == euclidean_witness_complex.get_point(1)
assert landmarks[2] == euclidean_witness_complex.get_point(2)
- assert simplex_tree.get_filtration() == [([0], 0.0), ([1], 0.0),
- ([0, 1], 0.0), ([2], 0.0), ([0, 2], 0.0), ([1, 2], 0.0),
- ([0, 1, 2], 0.0)]
+ assert simplex_tree.get_filtration() == [
+ ([0], 0.0),
+ ([1], 0.0),
+ ([0, 1], 0.0),
+ ([2], 0.0),
+ ([0, 2], 0.0),
+ ([1, 2], 0.0),
+ ([0, 1, 2], 0.0),
+ ]
+
def test_empty_euclidean_strong_witness_complex():
euclidean_strong_witness = gudhi.EuclideanStrongWitnessComplex()
assert euclidean_strong_witness.__is_defined() == False
+
def test_strong_witness_complex():
- point_cloud = [[1.0, 1.0], [7.0, 0.0], [4.0, 6.0], [9.0, 6.0],
- [0.0, 14.0], [2.0, 19.0], [9.0, 17.0]]
+ point_cloud = [
+ [1.0, 1.0],
+ [7.0, 0.0],
+ [4.0, 6.0],
+ [9.0, 6.0],
+ [0.0, 14.0],
+ [2.0, 19.0],
+ [9.0, 17.0],
+ ]
landmarks = [[1.0, 1.0], [7.0, 0.0], [4.0, 6.0]]
- euclidean_strong_witness_complex = gudhi.EuclideanStrongWitnessComplex(landmarks=landmarks, witnesses = point_cloud)
- simplex_tree = euclidean_strong_witness_complex.create_simplex_tree(max_alpha_square=14.9)
+ euclidean_strong_witness_complex = gudhi.EuclideanStrongWitnessComplex(
+ landmarks=landmarks, witnesses=point_cloud
+ )
+ simplex_tree = euclidean_strong_witness_complex.create_simplex_tree(
+ max_alpha_square=14.9
+ )
assert landmarks[0] == euclidean_strong_witness_complex.get_point(0)
assert landmarks[1] == euclidean_strong_witness_complex.get_point(1)
@@ -51,9 +80,16 @@ def test_strong_witness_complex():
assert simplex_tree.get_filtration() == [([0], 0.0), ([1], 0.0), ([2], 0.0)]
- simplex_tree = euclidean_strong_witness_complex.create_simplex_tree(max_alpha_square=100.0)
-
- assert simplex_tree.get_filtration() == [([0], 0.0), ([1], 0.0),
- ([2], 0.0), ([1, 2], 15.0), ([0, 2], 34.0), ([0, 1], 37.0),
- ([0, 1, 2], 37.0)]
-
+ simplex_tree = euclidean_strong_witness_complex.create_simplex_tree(
+ max_alpha_square=100.0
+ )
+
+ assert simplex_tree.get_filtration() == [
+ ([0], 0.0),
+ ([1], 0.0),
+ ([2], 0.0),
+ ([1, 2], 15.0),
+ ([0, 2], 34.0),
+ ([0, 1], 37.0),
+ ([0, 1, 2], 37.0),
+ ]
diff --git a/src/cython/test/test_reader_utils.py b/src/cython/test/test_reader_utils.py
index 4b87adf2..4c7b32c2 100755
--- a/src/cython/test/test_reader_utils.py
+++ b/src/cython/test/test_reader_utils.py
@@ -18,60 +18,109 @@ __license__ = "MIT"
def test_non_existing_csv_file():
# Try to open a non existing file
- matrix = gudhi.read_lower_triangular_matrix_from_csv_file(csv_file='pouetpouettralala.toubiloubabdou')
+ matrix = gudhi.read_lower_triangular_matrix_from_csv_file(
+ csv_file="pouetpouettralala.toubiloubabdou"
+ )
assert matrix == []
+
def test_full_square_distance_matrix_csv_file():
# Create test file
- test_file = open('full_square_distance_matrix.csv', 'w')
- test_file.write('0;1;2;3;\n1;0;4;5;\n2;4;0;6;\n3;5;6;0;')
+ test_file = open("full_square_distance_matrix.csv", "w")
+ test_file.write("0;1;2;3;\n1;0;4;5;\n2;4;0;6;\n3;5;6;0;")
test_file.close()
- matrix = gudhi.read_lower_triangular_matrix_from_csv_file(csv_file="full_square_distance_matrix.csv")
+ matrix = gudhi.read_lower_triangular_matrix_from_csv_file(
+ csv_file="full_square_distance_matrix.csv"
+ )
assert matrix == [[], [1.0], [2.0, 4.0], [3.0, 5.0, 6.0]]
+
def test_lower_triangular_distance_matrix_csv_file():
# Create test file
- test_file = open('lower_triangular_distance_matrix.csv', 'w')
- test_file.write('\n1,\n2,3,\n4,5,6,\n7,8,9,10,')
+ test_file = open("lower_triangular_distance_matrix.csv", "w")
+ test_file.write("\n1,\n2,3,\n4,5,6,\n7,8,9,10,")
test_file.close()
- matrix = gudhi.read_lower_triangular_matrix_from_csv_file(csv_file="lower_triangular_distance_matrix.csv", separator=",")
+ matrix = gudhi.read_lower_triangular_matrix_from_csv_file(
+ csv_file="lower_triangular_distance_matrix.csv", separator=","
+ )
assert matrix == [[], [1.0], [2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0, 10.0]]
+
def test_non_existing_persistence_file():
# Try to open a non existing file
- persistence = gudhi.read_persistence_intervals_grouped_by_dimension(persistence_file='pouetpouettralala.toubiloubabdou')
+ persistence = gudhi.read_persistence_intervals_grouped_by_dimension(
+ persistence_file="pouetpouettralala.toubiloubabdou"
+ )
assert persistence == []
- persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='pouetpouettralala.toubiloubabdou', only_this_dim=1)
+ persistence = gudhi.read_persistence_intervals_in_dimension(
+ persistence_file="pouetpouettralala.toubiloubabdou", only_this_dim=1
+ )
np.testing.assert_array_equal(persistence, [])
+
def test_read_persistence_intervals_without_dimension():
# Create test file
- test_file = open('persistence_intervals_without_dimension.pers', 'w')
- test_file.write('# Simple persistence diagram without dimension\n2.7 3.7\n9.6 14.\n34.2 34.974\n3. inf')
+ test_file = open("persistence_intervals_without_dimension.pers", "w")
+ test_file.write(
+ "# Simple persistence diagram without dimension\n2.7 3.7\n9.6 14.\n34.2 34.974\n3. inf"
+ )
test_file.close()
- persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='persistence_intervals_without_dimension.pers')
- np.testing.assert_array_equal(persistence, [(2.7, 3.7), (9.6, 14.), (34.2, 34.974), (3., float('Inf'))])
- persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='persistence_intervals_without_dimension.pers', only_this_dim=0)
+ persistence = gudhi.read_persistence_intervals_in_dimension(
+ persistence_file="persistence_intervals_without_dimension.pers"
+ )
+ np.testing.assert_array_equal(
+ persistence, [(2.7, 3.7), (9.6, 14.0), (34.2, 34.974), (3.0, float("Inf"))]
+ )
+ persistence = gudhi.read_persistence_intervals_in_dimension(
+ persistence_file="persistence_intervals_without_dimension.pers", only_this_dim=0
+ )
np.testing.assert_array_equal(persistence, [])
- persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='persistence_intervals_without_dimension.pers', only_this_dim=1)
+ persistence = gudhi.read_persistence_intervals_in_dimension(
+ persistence_file="persistence_intervals_without_dimension.pers", only_this_dim=1
+ )
np.testing.assert_array_equal(persistence, [])
- persistence = gudhi.read_persistence_intervals_grouped_by_dimension(persistence_file='persistence_intervals_without_dimension.pers')
- assert persistence == {-1: [(2.7, 3.7), (9.6, 14.0), (34.2, 34.974), (3.0, float('Inf'))]}
+ persistence = gudhi.read_persistence_intervals_grouped_by_dimension(
+ persistence_file="persistence_intervals_without_dimension.pers"
+ )
+ assert persistence == {
+ -1: [(2.7, 3.7), (9.6, 14.0), (34.2, 34.974), (3.0, float("Inf"))]
+ }
+
def test_read_persistence_intervals_with_dimension():
# Create test file
- test_file = open('persistence_intervals_with_dimension.pers', 'w')
- test_file.write('# Simple persistence diagram with dimension\n0 2.7 3.7\n1 9.6 14.\n3 34.2 34.974\n1 3. inf')
+ test_file = open("persistence_intervals_with_dimension.pers", "w")
+ test_file.write(
+ "# Simple persistence diagram with dimension\n0 2.7 3.7\n1 9.6 14.\n3 34.2 34.974\n1 3. inf"
+ )
test_file.close()
- persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='persistence_intervals_with_dimension.pers')
- np.testing.assert_array_equal(persistence, [(2.7, 3.7), (9.6, 14.), (34.2, 34.974), (3., float('Inf'))])
- persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='persistence_intervals_with_dimension.pers', only_this_dim=0)
+ persistence = gudhi.read_persistence_intervals_in_dimension(
+ persistence_file="persistence_intervals_with_dimension.pers"
+ )
+ np.testing.assert_array_equal(
+ persistence, [(2.7, 3.7), (9.6, 14.0), (34.2, 34.974), (3.0, float("Inf"))]
+ )
+ persistence = gudhi.read_persistence_intervals_in_dimension(
+ persistence_file="persistence_intervals_with_dimension.pers", only_this_dim=0
+ )
np.testing.assert_array_equal(persistence, [(2.7, 3.7)])
- persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='persistence_intervals_with_dimension.pers', only_this_dim=1)
- np.testing.assert_array_equal(persistence, [(9.6, 14.), (3., float('Inf'))])
- persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='persistence_intervals_with_dimension.pers', only_this_dim=2)
+ persistence = gudhi.read_persistence_intervals_in_dimension(
+ persistence_file="persistence_intervals_with_dimension.pers", only_this_dim=1
+ )
+ np.testing.assert_array_equal(persistence, [(9.6, 14.0), (3.0, float("Inf"))])
+ persistence = gudhi.read_persistence_intervals_in_dimension(
+ persistence_file="persistence_intervals_with_dimension.pers", only_this_dim=2
+ )
np.testing.assert_array_equal(persistence, [])
- persistence = gudhi.read_persistence_intervals_in_dimension(persistence_file='persistence_intervals_with_dimension.pers', only_this_dim=3)
+ persistence = gudhi.read_persistence_intervals_in_dimension(
+ persistence_file="persistence_intervals_with_dimension.pers", only_this_dim=3
+ )
np.testing.assert_array_equal(persistence, [(34.2, 34.974)])
- persistence = gudhi.read_persistence_intervals_grouped_by_dimension(persistence_file='persistence_intervals_with_dimension.pers')
- assert persistence == {0: [(2.7, 3.7)], 1: [(9.6, 14.0), (3.0, float('Inf'))], 3: [(34.2, 34.974)]}
+ persistence = gudhi.read_persistence_intervals_grouped_by_dimension(
+ persistence_file="persistence_intervals_with_dimension.pers"
+ )
+ assert persistence == {
+ 0: [(2.7, 3.7)],
+ 1: [(9.6, 14.0), (3.0, float("Inf"))],
+ 3: [(34.2, 34.974)],
+ }
diff --git a/src/cython/test/test_rips_complex.py b/src/cython/test/test_rips_complex.py
index 975b447a..d55ae22f 100755
--- a/src/cython/test/test_rips_complex.py
+++ b/src/cython/test/test_rips_complex.py
@@ -19,6 +19,7 @@ __license__ = "MIT"
def test_empty_rips():
rips_complex = RipsComplex()
+
def test_rips_from_points():
point_list = [[0, 0], [1, 0], [0, 1], [1, 1]]
rips_complex = RipsComplex(points=point_list, max_edge_length=42)
@@ -31,17 +32,30 @@ def test_rips_from_points():
assert simplex_tree.num_simplices() == 10
assert simplex_tree.num_vertices() == 4
- assert simplex_tree.get_filtration() == \
- [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0),
- ([0, 1], 1.0), ([0, 2], 1.0), ([1, 3], 1.0),
- ([2, 3], 1.0), ([1, 2], 1.4142135623730951),
- ([0, 3], 1.4142135623730951)]
- assert simplex_tree.get_star([0]) == \
- [([0], 0.0), ([0, 1], 1.0), ([0, 2], 1.0),
- ([0, 3], 1.4142135623730951)]
- assert simplex_tree.get_cofaces([0], 1) == \
- [([0, 1], 1.0), ([0, 2], 1.0),
- ([0, 3], 1.4142135623730951)]
+ assert simplex_tree.get_filtration() == [
+ ([0], 0.0),
+ ([1], 0.0),
+ ([2], 0.0),
+ ([3], 0.0),
+ ([0, 1], 1.0),
+ ([0, 2], 1.0),
+ ([1, 3], 1.0),
+ ([2, 3], 1.0),
+ ([1, 2], 1.4142135623730951),
+ ([0, 3], 1.4142135623730951),
+ ]
+ assert simplex_tree.get_star([0]) == [
+ ([0], 0.0),
+ ([0, 1], 1.0),
+ ([0, 2], 1.0),
+ ([0, 3], 1.4142135623730951),
+ ]
+ assert simplex_tree.get_cofaces([0], 1) == [
+ ([0, 1], 1.0),
+ ([0, 2], 1.0),
+ ([0, 3], 1.4142135623730951),
+ ]
+
def test_filtered_rips_from_points():
point_list = [[0, 0], [1, 0], [0, 1], [1, 1]]
@@ -55,10 +69,10 @@ def test_filtered_rips_from_points():
assert simplex_tree.num_simplices() == 8
assert simplex_tree.num_vertices() == 4
+
def test_sparse_filtered_rips_from_points():
point_list = [[0, 0], [1, 0], [0, 1], [1, 1]]
- filtered_rips = RipsComplex(points=point_list, max_edge_length=1.0,
- sparse=.001)
+ filtered_rips = RipsComplex(points=point_list, max_edge_length=1.0, sparse=0.001)
simplex_tree = filtered_rips.create_simplex_tree(max_dimension=1)
@@ -68,13 +82,10 @@ def test_sparse_filtered_rips_from_points():
assert simplex_tree.num_simplices() == 8
assert simplex_tree.num_vertices() == 4
+
def test_rips_from_distance_matrix():
- distance_matrix = [[0],
- [1, 0],
- [1, sqrt(2), 0],
- [sqrt(2), 1, 1, 0]]
- rips_complex = RipsComplex(distance_matrix=distance_matrix,
- max_edge_length=42)
+ distance_matrix = [[0], [1, 0], [1, sqrt(2), 0], [sqrt(2), 1, 1, 0]]
+ rips_complex = RipsComplex(distance_matrix=distance_matrix, max_edge_length=42)
simplex_tree = rips_complex.create_simplex_tree(max_dimension=1)
@@ -84,25 +95,34 @@ def test_rips_from_distance_matrix():
assert simplex_tree.num_simplices() == 10
assert simplex_tree.num_vertices() == 4
- assert simplex_tree.get_filtration() == \
- [([0], 0.0), ([1], 0.0), ([2], 0.0), ([3], 0.0),
- ([0, 1], 1.0), ([0, 2], 1.0), ([1, 3], 1.0),
- ([2, 3], 1.0), ([1, 2], 1.4142135623730951),
- ([0, 3], 1.4142135623730951)]
- assert simplex_tree.get_star([0]) == \
- [([0], 0.0), ([0, 1], 1.0), ([0, 2], 1.0),
- ([0, 3], 1.4142135623730951)]
- assert simplex_tree.get_cofaces([0], 1) == \
- [([0, 1], 1.0), ([0, 2], 1.0),
- ([0, 3], 1.4142135623730951)]
+ assert simplex_tree.get_filtration() == [
+ ([0], 0.0),
+ ([1], 0.0),
+ ([2], 0.0),
+ ([3], 0.0),
+ ([0, 1], 1.0),
+ ([0, 2], 1.0),
+ ([1, 3], 1.0),
+ ([2, 3], 1.0),
+ ([1, 2], 1.4142135623730951),
+ ([0, 3], 1.4142135623730951),
+ ]
+ assert simplex_tree.get_star([0]) == [
+ ([0], 0.0),
+ ([0, 1], 1.0),
+ ([0, 2], 1.0),
+ ([0, 3], 1.4142135623730951),
+ ]
+ assert simplex_tree.get_cofaces([0], 1) == [
+ ([0, 1], 1.0),
+ ([0, 2], 1.0),
+ ([0, 3], 1.4142135623730951),
+ ]
+
def test_filtered_rips_from_distance_matrix():
- distance_matrix = [[0],
- [1, 0],
- [1, sqrt(2), 0],
- [sqrt(2), 1, 1, 0]]
- filtered_rips = RipsComplex(distance_matrix=distance_matrix,
- max_edge_length=1.0)
+ distance_matrix = [[0], [1, 0], [1, sqrt(2), 0], [sqrt(2), 1, 1, 0]]
+ filtered_rips = RipsComplex(distance_matrix=distance_matrix, max_edge_length=1.0)
simplex_tree = filtered_rips.create_simplex_tree(max_dimension=1)
diff --git a/src/cython/test/test_simplex_tree.py b/src/cython/test/test_simplex_tree.py
index 5c903d93..8d8971c1 100755
--- a/src/cython/test/test_simplex_tree.py
+++ b/src/cython/test/test_simplex_tree.py
@@ -39,7 +39,7 @@ def test_insertion():
assert st.find([0]) == True
assert st.find([1]) == True
assert st.find([2]) == True
- assert st.find([3]) == False
+ assert st.find([3]) == False
assert st.find([0, 3]) == False
assert st.find([1, 3]) == False
assert st.find([2, 3]) == False
@@ -55,21 +55,36 @@ def test_insertion():
assert st.filtration([1]) == 0.0
# skeleton test
- assert st.get_skeleton(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)]
- assert st.get_skeleton(1) == \
- [([0, 1], 0.0), ([0, 2], 4.0), ([0], 0.0),
- ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)]
- assert st.get_skeleton(0) == \
- [([0], 0.0), ([1], 0.0), ([2], 4.0)]
+ assert st.get_skeleton(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),
+ ]
+ assert st.get_skeleton(1) == [
+ ([0, 1], 0.0),
+ ([0, 2], 4.0),
+ ([0], 0.0),
+ ([1, 2], 4.0),
+ ([1], 0.0),
+ ([2], 4.0),
+ ]
+ assert st.get_skeleton(0) == [([0], 0.0), ([1], 0.0), ([2], 4.0)]
# remove_maximal_simplex test
assert st.get_cofaces([0, 1, 2], 1) == []
st.remove_maximal_simplex([0, 1, 2])
- assert st.get_skeleton(2) == \
- [([0, 1], 0.0), ([0, 2], 4.0), ([0], 0.0),
- ([1, 2], 4.0), ([1], 0.0), ([2], 4.0)]
+ assert st.get_skeleton(2) == [
+ ([0, 1], 0.0),
+ ([0, 2], 4.0),
+ ([0], 0.0),
+ ([1, 2], 4.0),
+ ([1], 0.0),
+ ([2], 4.0),
+ ]
assert st.find([0, 1, 2]) == False
assert st.find([0, 1]) == True
assert st.find([0, 2]) == True
@@ -78,7 +93,10 @@ def test_insertion():
assert st.find([2]) == True
st.initialize_filtration()
- assert st.persistence(persistence_dim_max = True) == [(1, (4.0, float('inf'))), (0, (0.0, float('inf')))]
+ assert st.persistence(persistence_dim_max=True) == [
+ (1, (4.0, float("inf"))),
+ (0, (0.0, float("inf"))),
+ ]
assert st.__is_persistence_defined() == True
assert st.betti_numbers() == [1, 1]
@@ -88,6 +106,7 @@ def test_insertion():
assert st.persistent_betti_numbers(4.0, 10000.0) == [1, 1]
assert st.persistent_betti_numbers(9999.0, 10000.0) == [1, 1]
+
def test_expansion():
st = SimplexTree()
assert st.__is_defined() == True
@@ -107,21 +126,56 @@ def test_expansion():
assert st.num_vertices() == 7
assert st.num_simplices() == 17
- assert st.get_filtration() == [([2], 0.1), ([3], 0.1), ([2, 3], 0.1),
- ([0], 0.2), ([0, 2], 0.2), ([1], 0.3), ([0, 1], 0.3), ([1, 3], 0.4),
- ([1, 2], 0.5), ([5], 0.6), ([6], 0.6), ([5, 6], 0.6), ([4], 0.7),
- ([2, 4], 0.7), ([0, 3], 0.8), ([4, 6], 0.9), ([3, 6], 1.0)]
+ assert st.get_filtration() == [
+ ([2], 0.1),
+ ([3], 0.1),
+ ([2, 3], 0.1),
+ ([0], 0.2),
+ ([0, 2], 0.2),
+ ([1], 0.3),
+ ([0, 1], 0.3),
+ ([1, 3], 0.4),
+ ([1, 2], 0.5),
+ ([5], 0.6),
+ ([6], 0.6),
+ ([5, 6], 0.6),
+ ([4], 0.7),
+ ([2, 4], 0.7),
+ ([0, 3], 0.8),
+ ([4, 6], 0.9),
+ ([3, 6], 1.0),
+ ]
st.expansion(3)
assert st.num_vertices() == 7
assert st.num_simplices() == 22
st.initialize_filtration()
- assert st.get_filtration() == [([2], 0.1), ([3], 0.1), ([2, 3], 0.1),
- ([0], 0.2), ([0, 2], 0.2), ([1], 0.3), ([0, 1], 0.3), ([1, 3], 0.4),
- ([1, 2], 0.5), ([0, 1, 2], 0.5), ([1, 2, 3], 0.5), ([5], 0.6), ([6], 0.6),
- ([5, 6], 0.6), ([4], 0.7), ([2, 4], 0.7), ([0, 3], 0.8), ([0, 1, 3], 0.8),
- ([0, 2, 3], 0.8), ([0, 1, 2, 3], 0.8), ([4, 6], 0.9), ([3, 6], 1.0)]
+ assert st.get_filtration() == [
+ ([2], 0.1),
+ ([3], 0.1),
+ ([2, 3], 0.1),
+ ([0], 0.2),
+ ([0, 2], 0.2),
+ ([1], 0.3),
+ ([0, 1], 0.3),
+ ([1, 3], 0.4),
+ ([1, 2], 0.5),
+ ([0, 1, 2], 0.5),
+ ([1, 2, 3], 0.5),
+ ([5], 0.6),
+ ([6], 0.6),
+ ([5, 6], 0.6),
+ ([4], 0.7),
+ ([2, 4], 0.7),
+ ([0, 3], 0.8),
+ ([0, 1, 3], 0.8),
+ ([0, 2, 3], 0.8),
+ ([0, 1, 2, 3], 0.8),
+ ([4, 6], 0.9),
+ ([3, 6], 1.0),
+ ]
+
def test_automatic_dimension():
st = SimplexTree()
@@ -129,8 +183,8 @@ def test_automatic_dimension():
assert st.__is_persistence_defined() == False
# insert test
- assert st.insert([0,1,3], filtration=0.5) == True
- assert st.insert([0,1,2], filtration=1.) == True
+ assert st.insert([0, 1, 3], filtration=0.5) == True
+ assert st.insert([0, 1, 2], filtration=1.0) == True
assert st.num_vertices() == 4
assert st.num_simplices() == 11
@@ -150,6 +204,7 @@ def test_automatic_dimension():
assert st.dimension() == 1
assert st.upper_bound_dimension() == 1
+
def test_make_filtration_non_decreasing():
st = SimplexTree()
assert st.__is_defined() == True
@@ -171,25 +226,25 @@ def test_make_filtration_non_decreasing():
# Because of non decreasing property of simplex tree, { 0 } , { 1 } and
# { 0, 1 } are going to be set from value 2.0 to 1.0
- st.insert([0, 1, 6, 7], filtration=1.0);
+ st.insert([0, 1, 6, 7], filtration=1.0)
assert st.make_filtration_non_decreasing() == False
# Modify specific values to test make_filtration_non_decreasing
- st.assign_filtration([0,1,6,7], 0.8);
- st.assign_filtration([0,1,6], 0.9);
- st.assign_filtration([0,6], 0.6);
- st.assign_filtration([3,4,5], 1.2);
- st.assign_filtration([3,4], 1.1);
- st.assign_filtration([4,5], 1.99);
+ st.assign_filtration([0, 1, 6, 7], 0.8)
+ st.assign_filtration([0, 1, 6], 0.9)
+ st.assign_filtration([0, 6], 0.6)
+ st.assign_filtration([3, 4, 5], 1.2)
+ st.assign_filtration([3, 4], 1.1)
+ st.assign_filtration([4, 5], 1.99)
assert st.make_filtration_non_decreasing() == True
- assert st.filtration([0,1,6,7]) == 1.
- assert st.filtration([0,1,6]) == 1.
- assert st.filtration([0,1]) == 1.
- assert st.filtration([0]) == 1.
- assert st.filtration([1]) == 1.
- assert st.filtration([3,4,5]) == 2.
- assert st.filtration([3,4]) == 2.
- assert st.filtration([4,5]) == 2.
+ assert st.filtration([0, 1, 6, 7]) == 1.0
+ assert st.filtration([0, 1, 6]) == 1.0
+ assert st.filtration([0, 1]) == 1.0
+ assert st.filtration([0]) == 1.0
+ assert st.filtration([1]) == 1.0
+ assert st.filtration([3, 4, 5]) == 2.0
+ assert st.filtration([3, 4]) == 2.0
+ assert st.filtration([4, 5]) == 2.0
diff --git a/src/cython/test/test_subsampling.py b/src/cython/test/test_subsampling.py
index f7a97539..c816e203 100755
--- a/src/cython/test/test_subsampling.py
+++ b/src/cython/test/test_subsampling.py
@@ -28,45 +28,72 @@ def test_write_off_file_for_tests():
file.write("9.0 17.0\n")
file.close()
+
def test_simple_choose_n_farthest_points_with_a_starting_point():
- point_set = [[0,1], [0,0], [1,0], [1,1]]
+ point_set = [[0, 1], [0, 0], [1, 0], [1, 1]]
i = 0
for point in point_set:
# The iteration starts with the given starting point
- sub_set = gudhi.choose_n_farthest_points(points = point_set, nb_points = 1, starting_point = i)
+ sub_set = gudhi.choose_n_farthest_points(
+ points=point_set, nb_points=1, starting_point=i
+ )
assert sub_set[0] == point_set[i]
i = i + 1
# The iteration finds then the farthest
- sub_set = gudhi.choose_n_farthest_points(points = point_set, nb_points = 2, starting_point = 1)
+ sub_set = gudhi.choose_n_farthest_points(
+ points=point_set, nb_points=2, starting_point=1
+ )
assert sub_set[1] == point_set[3]
- sub_set = gudhi.choose_n_farthest_points(points = point_set, nb_points = 2, starting_point = 3)
+ sub_set = gudhi.choose_n_farthest_points(
+ points=point_set, nb_points=2, starting_point=3
+ )
assert sub_set[1] == point_set[1]
- sub_set = gudhi.choose_n_farthest_points(points = point_set, nb_points = 2, starting_point = 0)
+ sub_set = gudhi.choose_n_farthest_points(
+ points=point_set, nb_points=2, starting_point=0
+ )
assert sub_set[1] == point_set[2]
- sub_set = gudhi.choose_n_farthest_points(points = point_set, nb_points = 2, starting_point = 2)
+ sub_set = gudhi.choose_n_farthest_points(
+ points=point_set, nb_points=2, starting_point=2
+ )
assert sub_set[1] == point_set[0]
# Test the limits
- assert gudhi.choose_n_farthest_points(points = [], nb_points = 0, starting_point = 0) == []
- assert gudhi.choose_n_farthest_points(points = [], nb_points = 1, starting_point = 0) == []
- assert gudhi.choose_n_farthest_points(points = [], nb_points = 0, starting_point = 1) == []
- assert gudhi.choose_n_farthest_points(points = [], nb_points = 1, starting_point = 1) == []
+ assert (
+ gudhi.choose_n_farthest_points(points=[], nb_points=0, starting_point=0) == []
+ )
+ assert (
+ gudhi.choose_n_farthest_points(points=[], nb_points=1, starting_point=0) == []
+ )
+ assert (
+ gudhi.choose_n_farthest_points(points=[], nb_points=0, starting_point=1) == []
+ )
+ assert (
+ gudhi.choose_n_farthest_points(points=[], nb_points=1, starting_point=1) == []
+ )
# From off file test
- for i in range (0, 7):
- assert len(gudhi.choose_n_farthest_points(off_file = 'subsample.off', nb_points = i, starting_point = i)) == i
+ for i in range(0, 7):
+ assert (
+ len(
+ gudhi.choose_n_farthest_points(
+ off_file="subsample.off", nb_points=i, starting_point=i
+ )
+ )
+ == i
+ )
+
def test_simple_choose_n_farthest_points_randomed():
- point_set = [[0,1], [0,0], [1,0], [1,1]]
+ point_set = [[0, 1], [0, 0], [1, 0], [1, 1]]
# Test the limits
- assert gudhi.choose_n_farthest_points(points = [], nb_points = 0) == []
- assert gudhi.choose_n_farthest_points(points = [], nb_points = 1) == []
- assert gudhi.choose_n_farthest_points(points = point_set, nb_points = 0) == []
+ assert gudhi.choose_n_farthest_points(points=[], nb_points=0) == []
+ assert gudhi.choose_n_farthest_points(points=[], nb_points=1) == []
+ assert gudhi.choose_n_farthest_points(points=point_set, nb_points=0) == []
# Go furter than point set on purpose
- for iter in range(1,10):
- sub_set = gudhi.choose_n_farthest_points(points = point_set, nb_points = iter)
+ for iter in range(1, 10):
+ sub_set = gudhi.choose_n_farthest_points(points=point_set, nb_points=iter)
for sub in sub_set:
found = False
for point in point_set:
@@ -76,19 +103,23 @@ def test_simple_choose_n_farthest_points_randomed():
assert found == True
# From off file test
- for i in range (0, 7):
- assert len(gudhi.choose_n_farthest_points(off_file = 'subsample.off', nb_points = i)) == i
+ for i in range(0, 7):
+ assert (
+ len(gudhi.choose_n_farthest_points(off_file="subsample.off", nb_points=i))
+ == i
+ )
+
def test_simple_pick_n_random_points():
- point_set = [[0,1], [0,0], [1,0], [1,1]]
+ point_set = [[0, 1], [0, 0], [1, 0], [1, 1]]
# Test the limits
- assert gudhi.pick_n_random_points(points = [], nb_points = 0) == []
- assert gudhi.pick_n_random_points(points = [], nb_points = 1) == []
- assert gudhi.pick_n_random_points(points = point_set, nb_points = 0) == []
+ assert gudhi.pick_n_random_points(points=[], nb_points=0) == []
+ assert gudhi.pick_n_random_points(points=[], nb_points=1) == []
+ assert gudhi.pick_n_random_points(points=point_set, nb_points=0) == []
# Go furter than point set on purpose
- for iter in range(1,10):
- sub_set = gudhi.pick_n_random_points(points = point_set, nb_points = iter)
+ for iter in range(1, 10):
+ sub_set = gudhi.pick_n_random_points(points=point_set, nb_points=iter)
print(5)
for sub in sub_set:
found = False
@@ -99,23 +130,50 @@ def test_simple_pick_n_random_points():
assert found == True
# From off file test
- for i in range (0, 7):
- assert len(gudhi.pick_n_random_points(off_file = 'subsample.off', nb_points = i)) == i
+ for i in range(0, 7):
+ assert (
+ len(gudhi.pick_n_random_points(off_file="subsample.off", nb_points=i)) == i
+ )
+
def test_simple_sparsify_points():
- point_set = [[0,1], [0,0], [1,0], [1,1]]
+ point_set = [[0, 1], [0, 0], [1, 0], [1, 1]]
# Test the limits
# assert gudhi.sparsify_point_set(points = [], min_squared_dist = 0.0) == []
# assert gudhi.sparsify_point_set(points = [], min_squared_dist = 10.0) == []
- assert gudhi.sparsify_point_set(points = point_set, min_squared_dist = 0.0) == point_set
- assert gudhi.sparsify_point_set(points = point_set, min_squared_dist = 1.0) == point_set
- assert gudhi.sparsify_point_set(points = point_set, min_squared_dist = 2.0) == [[0,1], [1,0]]
- assert gudhi.sparsify_point_set(points = point_set, min_squared_dist = 2.01) == [[0,1]]
-
- assert len(gudhi.sparsify_point_set(off_file = 'subsample.off', min_squared_dist = 0.0)) == 7
- assert len(gudhi.sparsify_point_set(off_file = 'subsample.off', min_squared_dist = 30.0)) == 5
- assert len(gudhi.sparsify_point_set(off_file = 'subsample.off', min_squared_dist = 40.0)) == 4
- assert len(gudhi.sparsify_point_set(off_file = 'subsample.off', min_squared_dist = 90.0)) == 3
- assert len(gudhi.sparsify_point_set(off_file = 'subsample.off', min_squared_dist = 100.0)) == 2
- assert len(gudhi.sparsify_point_set(off_file = 'subsample.off', min_squared_dist = 325.0)) == 2
- assert len(gudhi.sparsify_point_set(off_file = 'subsample.off', min_squared_dist = 325.01)) == 1
+ assert gudhi.sparsify_point_set(points=point_set, min_squared_dist=0.0) == point_set
+ assert gudhi.sparsify_point_set(points=point_set, min_squared_dist=1.0) == point_set
+ assert gudhi.sparsify_point_set(points=point_set, min_squared_dist=2.0) == [
+ [0, 1],
+ [1, 0],
+ ]
+ assert gudhi.sparsify_point_set(points=point_set, min_squared_dist=2.01) == [[0, 1]]
+
+ assert (
+ len(gudhi.sparsify_point_set(off_file="subsample.off", min_squared_dist=0.0))
+ == 7
+ )
+ assert (
+ len(gudhi.sparsify_point_set(off_file="subsample.off", min_squared_dist=30.0))
+ == 5
+ )
+ assert (
+ len(gudhi.sparsify_point_set(off_file="subsample.off", min_squared_dist=40.0))
+ == 4
+ )
+ assert (
+ len(gudhi.sparsify_point_set(off_file="subsample.off", min_squared_dist=90.0))
+ == 3
+ )
+ assert (
+ len(gudhi.sparsify_point_set(off_file="subsample.off", min_squared_dist=100.0))
+ == 2
+ )
+ assert (
+ len(gudhi.sparsify_point_set(off_file="subsample.off", min_squared_dist=325.0))
+ == 2
+ )
+ assert (
+ len(gudhi.sparsify_point_set(off_file="subsample.off", min_squared_dist=325.01))
+ == 1
+ )
diff --git a/src/cython/test/test_tangential_complex.py b/src/cython/test/test_tangential_complex.py
index aa3820d1..0f828d8e 100755
--- a/src/cython/test/test_tangential_complex.py
+++ b/src/cython/test/test_tangential_complex.py
@@ -17,7 +17,7 @@ __license__ = "MIT"
def test_tangential():
point_list = [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0]]
- tc = TangentialComplex(intrisic_dim = 1, points=point_list)
+ tc = TangentialComplex(intrisic_dim=1, points=point_list)
assert tc.__is_defined() == True
assert tc.num_vertices() == 4
assert tc.num_simplices() == 0
@@ -36,11 +36,17 @@ def test_tangential():
assert st.num_simplices() == 6
assert st.num_vertices() == 4
-
- assert st.get_filtration() == \
- [([0], 0.0), ([1], 0.0), ([2], 0.0), ([0, 2], 0.0), ([3], 0.0), ([1, 3], 0.0)]
+
+ assert st.get_filtration() == [
+ ([0], 0.0),
+ ([1], 0.0),
+ ([2], 0.0),
+ ([0, 2], 0.0),
+ ([3], 0.0),
+ ([1, 3], 0.0),
+ ]
assert st.get_cofaces([0], 1) == [([0, 2], 0.0)]
-
+
assert point_list[0] == tc.get_point(0)
assert point_list[1] == tc.get_point(1)
assert point_list[2] == tc.get_point(2)
diff --git a/src/cython/test/test_witness_complex.py b/src/cython/test/test_witness_complex.py
index 70511107..36ced635 100755
--- a/src/cython/test/test_witness_complex.py
+++ b/src/cython/test/test_witness_complex.py
@@ -19,32 +19,44 @@ def test_empty_witness_complex():
witness = WitnessComplex()
assert witness.__is_defined() == False
+
def test_witness_complex():
- nearest_landmark_table = [[[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]],
- [[1, 0], [2, 1], [3, 2], [4, 3], [0, 4]],
- [[2, 0], [3, 1], [4, 2], [0, 3], [1, 4]],
- [[3, 0], [4, 1], [0, 2], [1, 3], [2, 4]],
- [[4, 0], [0, 1], [1, 2], [2, 3], [3, 4]]]
+ nearest_landmark_table = [
+ [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]],
+ [[1, 0], [2, 1], [3, 2], [4, 3], [0, 4]],
+ [[2, 0], [3, 1], [4, 2], [0, 3], [1, 4]],
+ [[3, 0], [4, 1], [0, 2], [1, 3], [2, 4]],
+ [[4, 0], [0, 1], [1, 2], [2, 3], [3, 4]],
+ ]
witness_complex = WitnessComplex(nearest_landmark_table=nearest_landmark_table)
simplex_tree = witness_complex.create_simplex_tree(max_alpha_square=4.1)
assert simplex_tree.num_vertices() == 5
assert simplex_tree.num_simplices() == 31
- simplex_tree = witness_complex.create_simplex_tree(max_alpha_square=4.1, limit_dimension=2)
+ simplex_tree = witness_complex.create_simplex_tree(
+ max_alpha_square=4.1, limit_dimension=2
+ )
assert simplex_tree.num_vertices() == 5
assert simplex_tree.num_simplices() == 25
-def test_strong_witness_complex():
- nearest_landmark_table = [[[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]],
- [[1, 0], [2, 1], [3, 2], [4, 3], [0, 4]],
- [[2, 0], [3, 1], [4, 2], [0, 3], [1, 4]],
- [[3, 0], [4, 1], [0, 2], [1, 3], [2, 4]],
- [[4, 0], [0, 1], [1, 2], [2, 3], [3, 4]]]
- strong_witness_complex = StrongWitnessComplex(nearest_landmark_table=nearest_landmark_table)
+def test_strong_witness_complex():
+ nearest_landmark_table = [
+ [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4]],
+ [[1, 0], [2, 1], [3, 2], [4, 3], [0, 4]],
+ [[2, 0], [3, 1], [4, 2], [0, 3], [1, 4]],
+ [[3, 0], [4, 1], [0, 2], [1, 3], [2, 4]],
+ [[4, 0], [0, 1], [1, 2], [2, 3], [3, 4]],
+ ]
+
+ strong_witness_complex = StrongWitnessComplex(
+ nearest_landmark_table=nearest_landmark_table
+ )
simplex_tree = strong_witness_complex.create_simplex_tree(max_alpha_square=4.1)
assert simplex_tree.num_vertices() == 5
assert simplex_tree.num_simplices() == 31
- simplex_tree = strong_witness_complex.create_simplex_tree(max_alpha_square=4.1, limit_dimension=2)
+ simplex_tree = strong_witness_complex.create_simplex_tree(
+ max_alpha_square=4.1, limit_dimension=2
+ )
assert simplex_tree.num_vertices() == 5
assert simplex_tree.num_simplices() == 25