summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorROUVREAU Vincent <vincent.rouvreau@inria.fr>2019-12-18 10:44:17 +0100
committerROUVREAU Vincent <vincent.rouvreau@inria.fr>2019-12-18 10:44:17 +0100
commitb63be266effe24646823acc59fe397021bb13a3e (patch)
tree92e7bd9863a8823cca7934fe0d8cf1481417128a /src
parentb5510c0c362cd2bef79d82fd9809e654aea73957 (diff)
Reuse top_dimensional_cells instead of numpy_array argument to create a cubical
Diffstat (limited to 'src')
-rw-r--r--src/python/doc/cubical_complex_user.rst2
-rw-r--r--src/python/gudhi/cubical_complex.pyx25
-rw-r--r--src/python/gudhi/periodic_cubical_complex.pyx35
-rwxr-xr-xsrc/python/test/test_cubical_complex.py12
4 files changed, 37 insertions, 37 deletions
diff --git a/src/python/doc/cubical_complex_user.rst b/src/python/doc/cubical_complex_user.rst
index 21806038..d56c8789 100644
--- a/src/python/doc/cubical_complex_user.rst
+++ b/src/python/doc/cubical_complex_user.rst
@@ -143,7 +143,7 @@ Or it can be defined as follows:
from gudhi import PeriodicCubicalComplex as pcc
from numpy import array as np_array
- periodic_cc = pcc(numpy_array = np_array([[0, 0, 0], [0, 1, 0], [0, 0, 0]]),
+ periodic_cc = pcc(top_dimensional_cells = np_array([[0, 0, 0], [0, 1, 0], [0, 0, 0]]),
periodic_dimensions=[True, False])
result_str = 'Periodic cubical complex is of dimension ' + repr(periodic_cc.dimension()) + ' - ' + \
repr(periodic_cc.num_simplices()) + ' simplices.'
diff --git a/src/python/gudhi/cubical_complex.pyx b/src/python/gudhi/cubical_complex.pyx
index 2ec0146a..1aa1164c 100644
--- a/src/python/gudhi/cubical_complex.pyx
+++ b/src/python/gudhi/cubical_complex.pyx
@@ -47,7 +47,7 @@ cdef class CubicalComplex:
# Fake constructor that does nothing but documenting the constructor
def __init__(self, dimensions=None, top_dimensional_cells=None,
- numpy_array=None, perseus_file=''):
+ perseus_file=''):
"""CubicalComplex constructor from dimensions and
top_dimensional_cells or from a Perseus-style file name.
@@ -58,8 +58,9 @@ cdef class CubicalComplex:
Or
- :param numpy_array: Filtration values in a d-array.
- :type numpy_array: numpy ndarray
+ :param top_dimensional_cells: A multidimensional array of cells
+ filtration values.
+ :type top_dimensional_cells: numpy ndarray
Or
@@ -69,20 +70,20 @@ cdef class CubicalComplex:
# The real cython constructor
def __cinit__(self, dimensions=None, top_dimensional_cells=None,
- numpy_array=None, perseus_file=''):
+ perseus_file=''):
if ((dimensions is not None) and (top_dimensional_cells is not None)
- and (numpy_array is None) and (perseus_file == '')):
+ and (perseus_file == '')):
self.thisptr = new Bitmap_cubical_complex_base_interface(dimensions, top_dimensional_cells)
- elif ((dimensions is None) and (top_dimensional_cells is None)
- and (numpy_array is not None) and (perseus_file == '')):
- if isinstance(numpy_array, np.ndarray):
- dimensions = list(numpy_array.shape)
- top_dimensional_cells = numpy_array.flatten().tolist()
+ elif ((dimensions is None) and (top_dimensional_cells is not None)
+ and (perseus_file == '')):
+ if isinstance(top_dimensional_cells, np.ndarray):
+ dimensions = list(top_dimensional_cells.shape)
+ top_dimensional_cells = top_dimensional_cells.flatten().tolist()
self.thisptr = new Bitmap_cubical_complex_base_interface(dimensions, top_dimensional_cells)
else:
- print("numpy_array is not an instance of ndarray. It is a " + type(numpy_array))
+ print("top_dimensional_cells is not an instance of ndarray. It is a " + type(top_dimensional_cells))
elif ((dimensions is None) and (top_dimensional_cells is None)
- and (numpy_array is None) and (perseus_file != '')):
+ and (perseus_file != '')):
if os.path.isfile(perseus_file):
self.thisptr = new Bitmap_cubical_complex_base_interface(str.encode(perseus_file))
else:
diff --git a/src/python/gudhi/periodic_cubical_complex.pyx b/src/python/gudhi/periodic_cubical_complex.pyx
index 8318b7d3..e623058a 100644
--- a/src/python/gudhi/periodic_cubical_complex.pyx
+++ b/src/python/gudhi/periodic_cubical_complex.pyx
@@ -47,7 +47,7 @@ cdef class PeriodicCubicalComplex:
# Fake constructor that does nothing but documenting the constructor
def __init__(self, dimensions=None, top_dimensional_cells=None,
- numpy_array=None, periodic_dimensions=None, perseus_file=''):
+ periodic_dimensions=None, perseus_file=''):
"""PeriodicCubicalComplex constructor from dimensions and
top_dimensional_cells or from a Perseus-style file name.
@@ -60,8 +60,9 @@ cdef class PeriodicCubicalComplex:
Or
- :param numpy_array: Filtration values in a d-array.
- :type numpy_array: numpy ndarray
+ :param top_dimensional_cells: A multidimensional array of cells
+ filtration values.
+ :type top_dimensional_cells: numpy ndarray
:param periodic_dimensions: A list of top dimensional cells periodicity value.
:type periodic_dimensions: list of boolean
@@ -73,35 +74,33 @@ cdef class PeriodicCubicalComplex:
# The real cython constructor
def __cinit__(self, dimensions=None, top_dimensional_cells=None,
- numpy_array=None, periodic_dimensions=None,
- perseus_file=''):
+ periodic_dimensions=None, perseus_file=''):
if ((dimensions is not None) and (top_dimensional_cells is not None)
- and (numpy_array is None) and (periodic_dimensions is not None)
- and (perseus_file == '')):
+ and (periodic_dimensions is not None) and (perseus_file == '')):
self.thisptr = new Periodic_cubical_complex_base_interface(dimensions,
top_dimensional_cells,
periodic_dimensions)
- elif ((dimensions is None) and (top_dimensional_cells is None)
- and (numpy_array is not None) and (periodic_dimensions is not None)
- and (perseus_file == '')):
- if isinstance(numpy_array, np.ndarray):
- dimensions = list(numpy_array.shape)
- top_dimensional_cells = numpy_array.flatten().tolist()
+ elif ((dimensions is None) and (top_dimensional_cells is not None)
+ and (periodic_dimensions is not None) and (perseus_file == '')):
+ if isinstance(top_dimensional_cells, np.ndarray):
+ dimensions = list(top_dimensional_cells.shape)
+ top_dimensional_cells = top_dimensional_cells.flatten().tolist()
self.thisptr = new Periodic_cubical_complex_base_interface(dimensions,
top_dimensional_cells,
periodic_dimensions)
else:
- print("numpy_array is not an instance of ndarray. It is a " + type(numpy_array))
+ print("top_dimensional_cells is not an instance of ndarray. It is a " + type(top_dimensional_cells))
elif ((dimensions is None) and (top_dimensional_cells is None)
- and (numpy_array is None) and (periodic_dimensions is None)
- and (perseus_file != '')):
+ and (periodic_dimensions is None) and (perseus_file != '')):
if os.path.isfile(perseus_file):
self.thisptr = new Periodic_cubical_complex_base_interface(str.encode(perseus_file))
else:
print("file " + perseus_file + " not found.")
else:
- print("CubicalComplex can be constructed from dimensions and "
- "top_dimensional_cells or from a Perseus-style file name.")
+ print("CubicalComplex can be constructed from dimensions, "
+ "top_dimensional_cells and periodic_dimensions, or from "
+ "top_dimensional_cells and periodic_dimensions or from "
+ "a Perseus-style file name.")
def __dealloc__(self):
if self.thisptr != NULL:
diff --git a/src/python/test/test_cubical_complex.py b/src/python/test/test_cubical_complex.py
index a37d7821..6d4e0309 100755
--- a/src/python/test/test_cubical_complex.py
+++ b/src/python/test/test_cubical_complex.py
@@ -77,9 +77,9 @@ def test_simple_constructor_from_top_cells():
def test_simple_constructor_from_numpy_array():
cub = CubicalComplex(
- numpy_array=np.array([[1, 2, 3],
- [4, 5, 6],
- [7, 8, 9]])
+ top_dimensional_cells=np.array([[1, 2, 3],
+ [4, 5, 6],
+ [7, 8, 9]])
)
simple_constructor(cub)
@@ -103,9 +103,9 @@ def test_user_case_simple_constructor_from_top_cells():
def test_user_case_simple_constructor_from_numpy_array():
cub = CubicalComplex(
- numpy_array=np.array([[float("inf"), 0.0, 0.0],
- [0.0, 1.0, 0.0],
- [0.0, 0.0, 0.0]])
+ top_dimensional_cells=np.array([[float("inf"), 0.0, 0.0],
+ [0.0, 1.0, 0.0],
+ [0.0, 0.0, 0.0]])
)
user_case_simple_constructor(cub)