diff options
author | ROUVREAU Vincent <vincent.rouvreau@inria.fr> | 2021-06-22 17:48:26 +0200 |
---|---|---|
committer | ROUVREAU Vincent <vincent.rouvreau@inria.fr> | 2021-06-22 17:48:26 +0200 |
commit | 1da601457d00dfe951c89ee97b6f8053e2699c78 (patch) | |
tree | 0b3efc53c89db275a0a7962614f66174682e50e3 /src/python | |
parent | 6d7c79a352023dd380b7361057cb7db371c5d269 (diff) |
Add exception when input points not in 3d
Diffstat (limited to 'src/python')
-rw-r--r-- | src/python/gudhi/alpha_complex_3d.pyx | 5 | ||||
-rwxr-xr-x | src/python/test/test_alpha_complex_3d.py | 10 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/python/gudhi/alpha_complex_3d.pyx b/src/python/gudhi/alpha_complex_3d.pyx index 40f1b43a..578011a7 100644 --- a/src/python/gudhi/alpha_complex_3d.pyx +++ b/src/python/gudhi/alpha_complex_3d.pyx @@ -71,6 +71,7 @@ cdef class AlphaComplex3D: :param precision: Alpha complex precision can be 'fast', 'safe' or 'exact'. Default is 'safe'. :type precision: string + :raises ValueError: If the given points are not in 3d. :raises ValueError: In case of inconsistency between the number of points and weights. """ @@ -80,6 +81,10 @@ cdef class AlphaComplex3D: cdef bool fast = precision == 'fast' cdef bool exact = precision == 'exact' + if len(points) > 0: + if len(points[0]) != 3: + raise ValueError("AlphaComplex3D only accepts 3d points as an input") + # weights are set but is inconsistent with the number of points if len(weights) != 0 and len(weights) != len(points): raise ValueError("Inconsistency between the number of points and weights") diff --git a/src/python/test/test_alpha_complex_3d.py b/src/python/test/test_alpha_complex_3d.py index f7bd4fda..a5d9373b 100755 --- a/src/python/test/test_alpha_complex_3d.py +++ b/src/python/test/test_alpha_complex_3d.py @@ -10,6 +10,7 @@ from gudhi import AlphaComplex3D import pytest +import numpy as np try: # python3 @@ -147,3 +148,12 @@ def _weighted_doc_example(precision): def test_weighted_doc_example(): for precision in ['fast', 'safe', 'exact']: _weighted_doc_example(precision) + +def test_points_not_in_3d(): + with pytest.raises(ValueError): + alpha = AlphaComplex3D(points = np.random.rand(6,2)) + with pytest.raises(ValueError): + alpha = AlphaComplex3D(points = np.random.rand(6,4)) + + alpha = AlphaComplex3D(points = np.random.rand(6,3)) + assert alpha.__is_defined() == True
\ No newline at end of file |