Skip to content

Commit

Permalink
code review: confusion true/false when rename + doc for python module
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentRouvreau committed Jan 29, 2025
1 parent 1d89305 commit 5ea4175
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
47 changes: 25 additions & 22 deletions src/python/gudhi/delaunay_complex.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ cdef class DelaunayComplex:
points (Iterable[Iterable[float]]): A list of points in d-Dimension.
weights (Optional[Iterable[float]]): A list of weights. If set, the number of weights must correspond to
the number of points.
precision (str): Complex precision can be 'fast', 'safe' or 'exact'. Default is 'safe'.
precision (str): Complex precision can be `'fast'`, `'safe'` or `'exact'`. Default is `'safe'`.
:raises ValueError: In case of inconsistency between the number of points and weights.
"""
Expand Down Expand Up @@ -104,7 +104,7 @@ cdef class DelaunayComplex:
del self.this_ptr

def _is_defined(self):
"""Returns true if DelaunayComplex pointer is not NULL.
"""Returns `True` if DelaunayComplex pointer is not NULL.
"""
return self.this_ptr != NULL

Expand All @@ -118,7 +118,7 @@ cdef class DelaunayComplex:
filtration: Set this value to `None` (default value) if filtration values are not needed to be computed
(will be set to `NaN`). Set it to `alpha` to compute the filtration values with the Alpha complex, or
to `cech` to compute the Delaunay Cech complex.
output_squared_values: Square root filtration values when True. Default is False.
output_squared_values: Square root filtration values when `True`. Default is `False`.
Returns:
SimplexTree: A simplex tree created from the Delaunay Triangulation. The vertex `k` corresponds to the k-th
input point. The vertices may not be numbered contiguously as some points may be discarded in the
Expand Down Expand Up @@ -184,15 +184,16 @@ cdef class AlphaComplex(DelaunayComplex):
"""
def create_simplex_tree(self, double max_alpha_square: float = float('inf'),
default_filtration_value: bool = False,
bool output_squared_values: bool = False) -> SimplexTree:
bool output_squared_values: bool = True) -> SimplexTree:
"""
Args:
max_alpha_square: The maximum alpha square threshold the simplices shall not exceed. Default is set to
infinity, and there is very little point using anything else since it does not save time.
default_filtration_value: [Deprecated] Default value is `False` (which means compute the filtration
values). Set this value to `True` if filtration values are not needed to be computed (will be set to
`NaN`), but please consider constructing a :class:`~gudhi.DelaunayComplex` instead.
output_squared_values: Square root filtration values when True. Default is False.
output_squared_values: Square root filtration values when `True`. Default is `True` to keep backward
compatibility.
Returns:
SimplexTree: A simplex tree created from the Delaunay Triangulation. The vertex `k` corresponds to the k-th input
point. The vertices may not be numbered contiguously as some points may be discarded in the triangulation
Expand All @@ -201,8 +202,8 @@ cdef class AlphaComplex(DelaunayComplex):
filtration = 'alpha'
if default_filtration_value:
filtration = None
warnings.warn('''Since Gudhi 3.10, creating an AlphaComplex with default_filtration_value=True is deprecated.
Please consider constructing a DelaunayComplex instead.
warnings.warn('''Since Gudhi 3.10, creating an AlphaComplex with default_filtration_value=True is
deprecated. Please consider constructing a DelaunayComplex instead.
''', DeprecationWarning)
return super().create_simplex_tree(max_alpha_square, filtration, output_squared_values)

Expand All @@ -225,12 +226,12 @@ def delaunay_cech_complex(
points: Iterable[Iterable[float]] = [],
precision: Literal["fast", "safe", "exact"] = "safe",
max_alpha: float = float("inf"),
output_squared_values: bool = True,
output_squared_values: bool = False,
) -> SimplexTree:
"""Delaunay Čech complex is a simplicial complex constructed from the finite cells of a Delaunay Triangulation.

The filtration value of each simplex is equal to the radius (squared if `output_squared_values` is set to False) of
its minimal enclosing ball (MEB).
The filtration value of each simplex is equal to the radius (squared if `output_squared_values` is set to `True`)
of its minimal enclosing ball (MEB).

All simplices that have a filtration value strictly greater than a given alpha value are not inserted into the
complex.
Expand All @@ -241,15 +242,15 @@ def delaunay_cech_complex(

Args:
points: A list of points in d-Dimension.
precision: Delaunay Čech complex precision can be 'fast', 'safe' or 'exact'. Default is 'safe'.
precision: Delaunay Čech complex precision can be `'fast'`, `'safe'` or `'exact'`. Default is `'safe'`.
max_alpha: The maximum alpha square threshold the simplices shall not exceed. Default is set to infinity, and
there is very little point using anything else since it does not save time.
output_squared_values: Square root filtration values when True. Default is True, but computation is faster when
set to False.
output_squared_values: Square root filtration values when `False`. Default is `False`, but computation is
faster when set to `True`.
Returns:
SimplexTree: A simplex tree created from the Delaunay Triangulation. The vertex `k` corresponds to the k-th
input point. The vertices may not be numbered contiguously as some points may be discarded in the triangulation
(duplicate points, weighted hidden point, ...).
(duplicate points, ...).
"""
cpx = DelaunayComplex(points=points, weights=None, precision=precision)
return cpx.create_simplex_tree(
Expand Down Expand Up @@ -279,12 +280,12 @@ def alpha_complex(
points: Iterable[Iterable[float]] = [],
precision: Literal["fast", "safe", "exact"] = "safe",
double max_alpha: float = float("inf"),
bool output_squared_values: bool = True
bool output_squared_values: bool = False
) -> SimplexTree:
"""Alpha complex is a simplicial complex constructed from the finite cells of a Delaunay Triangulation.

The filtration value of each simplex is computed as the radius of the smallest empty sphere passing through all of
its vertices.
The filtration value of each simplex is computed as the radius (squared if `output_squared_values` is set to
`True`) of the smallest empty sphere passing through all of its vertices.

All simplices that have a filtration value strictly greater than a given alpha value are not inserted into the
complex.
Expand All @@ -298,11 +299,11 @@ def alpha_complex(

Args:
points: A list of points in d-Dimension.
precision: Alpha complex precision can be 'fast', 'safe' or 'exact'. Default is 'safe'.
precision: Alpha complex precision can be `'fast'`, `'safe'` or `'exact'`. Default is `'safe'`.
max_alpha: The maximum alpha threshold the simplices shall not exceed. Default is set to infinity, and there is
very little point using anything else since it does not save time.
output_squared_values: Square root filtration values when True. Default is True, but computation is faster when
set to False.
output_squared_values: Square root filtration values when `False`. Default is `False`, but computation is
faster when set to `True`.
Returns:
SimplexTree: A simplex tree created from the Delaunay Triangulation. The vertex `k` corresponds to the k-th
input point. The vertices may not be numbered contiguously as some points may be discarded in the triangulation
Expand Down Expand Up @@ -337,7 +338,7 @@ def weighted_alpha_complex(
Args:
points: A list of points in d-Dimension.
weights: A list of weights. If set, the number of weights must correspond to the number of points.
precision: Weighted Alpha complex precision can be 'fast', 'safe' or 'exact'. Default is 'safe'.
precision: Weighted Alpha complex precision can be `'fast'`, `'safe'` or `'exact'`. Default is `'safe'`.
max_power_distance: The maximum alpha square threshold the simplices shall not exceed. Default is set to
infinity, and there is very little point using anything else since it does not save time.
Returns:
Expand All @@ -348,6 +349,8 @@ def weighted_alpha_complex(
:raises ValueError: In case of inconsistency between the number of points and weights.
"""
cpx = DelaunayComplex(points=points, weights=weights, precision=precision)
# There is no added value to set output_squared_values to False, as filtration values can be negative in a weighted
# case. If output_squared_values is set to False, filtration values would be NaN.
return cpx.create_simplex_tree(
max_alpha_square=max_power_distance, filtration="alpha", output_squared_values=False
max_alpha_square=max_power_distance, filtration="alpha", output_squared_values=True
)
6 changes: 3 additions & 3 deletions src/python/include/Delaunay_complex_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ bool create_complex(Delaunay_complex& delaunay_complex, Simplex_tree_interface*
true);
if (result == true) {
// Construct the Delaunay-Cech complex by assigning filtration values with MEB
if (output_squared_values) {
Gudhi::cech_complex::assign_MEB_filtration<true>(Kernel(), *simplex_tree, points);
if (!output_squared_values) {
Gudhi::cech_complex::assign_MEB_filtration<false>(Kernel(), *simplex_tree, points);
simplex_tree->prune_above_filtration(std::sqrt(max_alpha_square));
} else {
Gudhi::cech_complex::assign_MEB_filtration<false>(Kernel(), *simplex_tree, points);
Gudhi::cech_complex::assign_MEB_filtration<true>(Kernel(), *simplex_tree, points);
simplex_tree->prune_above_filtration(max_alpha_square);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/python/test/test_delaunay_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ def test_output_squared_values():
for max_alpha in [float('inf'), math.sqrt(20.)]:
pts=[[1, 1], [7, 0], [4, 6], [9, 6], [0, 14], [2, 19], [9, 17]]
stree = simplicial_complex_helper(points=pts, precision=precision,
output_squared_values=False, max_alpha=max_alpha)
output_squared_values=True, max_alpha=max_alpha)
stree_sqrt = simplicial_complex_helper(points=pts, precision=precision,
output_squared_values=True, max_alpha=max_alpha)
output_squared_values=False, max_alpha=max_alpha)
assert stree.num_simplices() == stree_sqrt.num_simplices()
for simplex, filt in stree_sqrt.get_filtration():
# np.testing.assert_almost_equal(float('nan'), float('nan')) is ok
Expand Down

0 comments on commit 5ea4175

Please sign in to comment.