summaryrefslogtreecommitdiff
path: root/cython/cython/simplex_tree.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'cython/cython/simplex_tree.pyx')
-rw-r--r--cython/cython/simplex_tree.pyx81
1 files changed, 46 insertions, 35 deletions
diff --git a/cython/cython/simplex_tree.pyx b/cython/cython/simplex_tree.pyx
index 9d40a8b5..45487158 100644
--- a/cython/cython/simplex_tree.pyx
+++ b/cython/cython/simplex_tree.pyx
@@ -2,6 +2,7 @@ from cython cimport numeric
from libcpp.vector cimport vector
from libcpp.utility cimport pair
from libcpp cimport bool
+from libcpp.string cimport string
"""This file is part of the Gudhi Library. The Gudhi library
(Geometric Understanding in Higher Dimensions) is a generic C++
@@ -35,9 +36,7 @@ cdef extern from "Simplex_tree_interface.h" namespace "Gudhi":
cdef cppclass Simplex_tree_interface_full_featured "Gudhi::Simplex_tree_interface<Gudhi::Simplex_tree_options_full_featured>":
Simplex_tree()
- double filtration()
double simplex_filtration(vector[int] simplex)
- void set_filtration(double filtration)
void initialize_filtration()
int num_vertices()
int num_simplices()
@@ -61,6 +60,7 @@ cdef extern from "Persistent_cohomology_interface.h" namespace "Gudhi":
vector[int] betti_numbers()
vector[int] persistent_betti_numbers(double from_value, double to_value)
vector[pair[double,double]] intervals_in_dimension(int dimension)
+ void write_output_diagram(string diagram_file_name)
# SimplexTree python interface
cdef class SimplexTree:
@@ -113,14 +113,6 @@ cdef class SimplexTree:
"""
return self.thisptr.simplex_filtration(simplex)
- def set_filtration(self, filtration):
- """This function sets the main simplicial complex filtration value.
-
- :param filtration: The filtration value.
- :type filtration: float.
- """
- self.thisptr.set_filtration(<double> filtration)
-
def initialize_filtration(self):
"""This function initializes and sorts the simplicial complex
filtration vector.
@@ -183,10 +175,10 @@ cdef class SimplexTree:
:returns: true if the simplex was found, false otherwise.
:rtype: bool
"""
- cdef vector[int] complex
+ cdef vector[int] csimplex
for i in simplex:
- complex.push_back(i)
- return self.thisptr.find_simplex(complex)
+ csimplex.push_back(i)
+ return self.thisptr.find_simplex(csimplex)
def insert(self, simplex, filtration=0.0):
"""This function inserts the given N-simplex and its subfaces with the
@@ -200,10 +192,10 @@ cdef class SimplexTree:
:returns: true if the simplex was found, false otherwise.
:rtype: bool
"""
- cdef vector[int] complex
+ cdef vector[int] csimplex
for i in simplex:
- complex.push_back(i)
- return self.thisptr.insert_simplex_and_subfaces(complex,
+ csimplex.push_back(i)
+ return self.thisptr.insert_simplex_and_subfaces(csimplex,
<double>filtration)
def get_filtration(self):
@@ -232,35 +224,35 @@ cdef class SimplexTree:
:returns: The (simplices of the) skeleton of a maximum dimension.
:rtype: list of tuples(simplex, filtration)
"""
- cdef vector[pair[vector[int], double]] skeletons \
+ cdef vector[pair[vector[int], double]] skeleton \
= self.thisptr.get_skeleton(<int>dimension)
ct = []
- for filtered_complex in skeletons:
+ for filtered_simplex in skeleton:
v = []
- for vertex in filtered_complex.first:
+ for vertex in filtered_simplex.first:
v.append(vertex)
- ct.append((v, filtered_complex.second))
+ ct.append((v, filtered_simplex.second))
return ct
def get_star(self, simplex):
- """This function returns the stars of a given N-simplex.
+ """This function returns the star of a given N-simplex.
:param simplex: The N-simplex, represented by a list of vertex.
:type simplex: list of int.
:returns: The (simplices of the) star of a simplex.
:rtype: list of tuples(simplex, filtration)
"""
- cdef vector[int] complex
+ cdef vector[int] csimplex
for i in simplex:
- complex.push_back(i)
- cdef vector[pair[vector[int], double]] stars \
- = self.thisptr.get_star(complex)
+ csimplex.push_back(i)
+ cdef vector[pair[vector[int], double]] star \
+ = self.thisptr.get_star(csimplex)
ct = []
- for filtered_complex in stars:
+ for filtered_simplex in star:
v = []
- for vertex in filtered_complex.first:
+ for vertex in filtered_simplex.first:
v.append(vertex)
- ct.append((v, filtered_complex.second))
+ ct.append((v, filtered_simplex.second))
return ct
def get_cofaces(self, simplex, codimension):
@@ -275,17 +267,17 @@ cdef class SimplexTree:
:returns: The (simplices of the) cofaces of a simplex
:rtype: list of tuples(simplex, filtration)
"""
- cdef vector[int] complex
+ cdef vector[int] csimplex
for i in simplex:
- complex.push_back(i)
+ csimplex.push_back(i)
cdef vector[pair[vector[int], double]] cofaces \
- = self.thisptr.get_cofaces(complex, <int>codimension)
+ = self.thisptr.get_cofaces(csimplex, <int>codimension)
ct = []
- for filtered_complex in cofaces:
+ for filtered_simplex in cofaces:
v = []
- for vertex in filtered_complex.first:
+ for vertex in filtered_simplex.first:
v.append(vertex)
- ct.append((v, filtered_complex.second))
+ ct.append((v, filtered_simplex.second))
return ct
def remove_maximal_simplex(self, simplex):
@@ -385,7 +377,7 @@ cdef class SimplexTree:
complex in a specific dimension.
:param dimension: The specific dimension.
- :type from_value: int.
+ :type dimension: int.
:returns: The persistence intervals.
:rtype: list of pair of float
@@ -399,3 +391,22 @@ cdef class SimplexTree:
print("intervals_in_dim function requires persistence function"
" to be launched first.")
return intervals_result
+
+ def write_persistence_diagram(self, persistence_file=''):
+ """This function writes the persistence intervals of the simplicial
+ complex in a user given file name.
+
+ :param persistence_file: The specific dimension.
+ :type persistence_file: string.
+
+ :note: intervals_in_dim function requires persistence function to be
+ launched first.
+ """
+ if self.pcohptr != NULL:
+ if persistence_file != '':
+ self.pcohptr.write_output_diagram(str.encode(persistence_file))
+ else:
+ print("persistence_file must be specified")
+ else:
+ print("intervals_in_dim function requires persistence function"
+ " to be launched first.")