summaryrefslogtreecommitdiff
path: root/python/src
diff options
context:
space:
mode:
Diffstat (limited to 'python/src')
-rw-r--r--python/src/self_test.py16
-rw-r--r--python/src/simple_example.py42
2 files changed, 26 insertions, 32 deletions
diff --git a/python/src/self_test.py b/python/src/self_test.py
index c8174fb..3f85fc1 100644
--- a/python/src/self_test.py
+++ b/python/src/self_test.py
@@ -8,15 +8,14 @@ if __name__=='__main__':
boundary_matrix = phat.boundary_matrix()
# This is broken for some reason
- if not boundary_matrix.load_binary(test_data):
- # if not boundary_matrix.load_ascii(test_data):
+ if not boundary_matrix.load(test_data):
print("Error: test data %s not found!" % test_data)
sys.exit(1)
error = False
def compute_chunked(mat):
- return phat.compute_persistence_pairs(mat, phat.reductions.chunk_reduction)
+ return mat.compute_persistence_pairs(phat.reductions.chunk_reduction)
print("Comparing representations using Chunk algorithm ...")
print("Running Chunk - Sparse ...")
@@ -88,7 +87,8 @@ if __name__=='__main__':
reps = phat.representations
reds = phat.reductions
- pairs = phat.compute_persistence_pairs
+ def pairs(mat, red):
+ return mat.compute_persistence_pairs(red)
twist_boundary_matrix = bit_tree_mat()
twist_pairs = pairs(twist_boundary_matrix, reds.twist_reduction)
@@ -132,10 +132,10 @@ if __name__=='__main__':
print("Comparing primal and dual approach using Chunk - Full ...")
primal_boundary_matrix = phat.boundary_matrix(reps.full_pivot_column, boundary_matrix)
- primal_pairs = phat.compute_persistence_pairs(primal_boundary_matrix, reds.chunk_reduction)
+ primal_pairs = primal_boundary_matrix.compute_persistence_pairs(reds.chunk_reduction)
dual_boundary_matrix = phat.boundary_matrix(reps.full_pivot_column, boundary_matrix)
- dual_pairs = phat.compute_persistence_pairs_dualized(dual_boundary_matrix)
+ dual_pairs = dual_boundary_matrix.compute_persistence_pairs_dualized()
if primal_pairs != dual_pairs:
print("Error: primal and dual differ!", file=sys.stderr)
@@ -149,11 +149,9 @@ if __name__=='__main__':
print("Testing vector<vector> interface ...")
- (vector_vector_matrix, vector_dims) = boundary_matrix.get_vector_vector()
-
vector_vector_boundary_matrix = phat.boundary_matrix(phat.representations.bit_tree_pivot_column)
- vector_vector_boundary_matrix.load_vector_vector(vector_vector_matrix, vector_dims)
+ vector_vector_boundary_matrix.columns = boundary_matrix.columns
if vector_vector_boundary_matrix != boundary_matrix:
print("Error: [load|save]_vector_vector bug", file=sys.stderr)
diff --git a/python/src/simple_example.py b/python/src/simple_example.py
index 82cf6be..955e213 100644
--- a/python/src/simple_example.py
+++ b/python/src/simple_example.py
@@ -21,39 +21,35 @@ if __name__ == "__main__":
import phat
- # set the dimension of the cell that each column represents:
- dimensions = [0, 0, 1, 0, 1, 1, 2]
-
# define a boundary matrix with the chosen internal representation
boundary_matrix = phat.boundary_matrix(representation = phat.representations.vector_vector)
- # set the respective columns -- the columns entries have to be sorted
- boundary_matrix.set_dims(dimensions)
- boundary_matrix.set_col(0, [])
- boundary_matrix.set_col(1, [])
- boundary_matrix.set_col(2, [0,1])
- boundary_matrix.set_col(3, [])
- boundary_matrix.set_col(4, [1,3])
- boundary_matrix.set_col(5, [0,3])
- boundary_matrix.set_col(6, [2,4,5])
+ # set the respective columns -- (dimension, boundary) pairs
+ boundary_matrix.columns = [ (0, []),
+ (0, []),
+ (1, [0,1]),
+ (0, []),
+ (1, [1,3]),
+ (1, [0,3]),
+ (2, [2,4,5])]
+
+ # or equivalently, boundary_matrix = phat.boundary_matrix(representation = ..., columns = ...)
+ # would combine the creation of the matrix and the assignment of the columns
# print some information of the boundary matrix:
- print()
- print("The boundary matrix has %d columns:" % boundary_matrix.get_num_cols())
- for col_idx in range(boundary_matrix.get_num_cols()):
- s = "Column %d represents a cell of dimension %d." % (col_idx, boundary_matrix.get_dim(col_idx))
- if (not boundary_matrix.is_empty(col_idx)):
- s = s + " Its boundary consists of the cells " + " ".join([str(c) for c in boundary_matrix.get_col(col_idx)])
+ print("\nThe boundary matrix has %d columns:" % len(boundary_matrix.columns))
+ for col in boundary_matrix.columns:
+ s = "Column %d represents a cell of dimension %d." % (col.index, col.dimension)
+ if (col.boundary):
+ s = s + " Its boundary consists of the cells " + " ".join([str(c) for c in col.boundary])
print(s)
- print("Overall, the boundary matrix has %d entries." % boundary_matrix.get_num_entries())
+ print("Overall, the boundary matrix has %d entries." % len(boundary_matrix))
- pairs = phat.compute_persistence_pairs(boundary_matrix)
+ pairs = boundary_matrix.compute_persistence_pairs()
pairs.sort()
- print()
-
- print("There are %d persistence pairs: " % len(pairs))
+ print("\nThere are %d persistence pairs: " % len(pairs))
for pair in pairs:
print("Birth: %d, Death: %d" % pair)