-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New format for persistence #925
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -612,7 +612,7 @@ cdef class SimplexTree: | |
""" | ||
self.get_ptr().expansion_with_blockers_callback(max_dim, callback, <void*>blocker_func) | ||
|
||
def persistence(self, homology_coeff_field=11, min_persistence=0, persistence_dim_max = False): | ||
def persistence(self, homology_coeff_field=11, min_persistence=0, persistence_dim_max = False, output_type = 'old'): | ||
"""This function computes and returns the persistence of the simplicial complex. | ||
|
||
:param homology_coeff_field: The homology coefficient field. Must be a | ||
|
@@ -627,11 +627,18 @@ cdef class SimplexTree: | |
maximal dimension in the complex is computed. If false, it is | ||
ignored. Default is false. | ||
:type persistence_dim_max: bool | ||
:param output_type: Format of the output. 'old' for the legacy list of (dim,(birth,death)), | ||
'array by dimension' for a list of nx2 numpy arrays (one per dimension). | ||
:type output_type: str | ||
:returns: The persistence of the simplicial complex. | ||
:rtype: list of pairs(dimension, pair(birth, death)) | ||
""" | ||
self.compute_persistence(homology_coeff_field, min_persistence, persistence_dim_max) | ||
return self.pcohptr.get_persistence() | ||
if output_type == 'array by dimension': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "array by dimension" seems a bit long to me, is "arrays" ok ? and 'old' isn't very telling : "tuples" ? |
||
v = self.pcohptr.intervals_by_dimension() | ||
return [ np.asarray(dgm) for dgm in v ] # std::move(dgm)? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably do the usual workaround for empty dgm to get a shape (0,2). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tuples are slightly faster than lists in python, but that's negligible here. |
||
else: | ||
return self.pcohptr.get_persistence() | ||
|
||
def compute_persistence(self, homology_coeff_field=11, min_persistence=0, persistence_dim_max = False): | ||
"""This function computes the persistence of the simplicial complex, so it can be accessed through | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-- Not completely related to this PR, but I think we should do type annotations here, i.e.,
especially to have auto-completion for long arguments such as "array by dimension".
I also changed the
False
to aNone
.