Skip to content

Commit

Permalink
Document SimplexTree __eq__, __getstate__ and __setstate__
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentRouvreau committed Apr 17, 2023
1 parent 0b4ae5f commit bdfe6a1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/python/doc/simplex_tree_ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ Simplex tree reference manual

.. autoclass:: gudhi.SimplexTree
:members:
:special-members: __eq__, __getstate__, __setstate__
:show-inheritance:
6 changes: 5 additions & 1 deletion src/python/gudhi/simplex_tree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -812,16 +812,19 @@ cdef class SimplexTree:

def __eq__(self, other:SimplexTree):
"""Test for structural equality
:returns: True if the 2 simplex trees are equal, False otherwise.
:rtype: bool
"""
return dereference(self.get_ptr()) == dereference(other.get_ptr())

def __getstate__(self):
"""Pickle the SimplexTree data structure as a Python Byte Array
:raises MemoryError: In the case the serialization allocates a too large block of memory.
:returns: Serialized SimplexTree data structure
:rtype: numpy.array of shape (n,)
:raises MemoryError: In the case the serialization allocates a too large block of memory.
"""
cdef size_t buffer_size = self.get_ptr().get_serialization_size()
# Let's use numpy to allocate a buffer. Will be deleted automatically
Expand All @@ -835,6 +838,7 @@ cdef class SimplexTree:

def __setstate__(self, state):
"""Construct the SimplexTree data structure from a Python Byte Array
:param state: Serialized SimplexTree data structure
:type state: numpy.array of shape (n,)
"""
Expand Down

0 comments on commit bdfe6a1

Please sign in to comment.