Fix open ReebGraph.slice dropping edges whose endpoints lie on the slice bounds - #124
Merged
lizliz merged 3 commits intoSep 24, 2026
Conversation
ishikaghosh2201
requested review from
lizliz
and
a lite review from Copilot
September 23, 2026 18:25
…graphslicetypeopen-drops-edges-whose-endpoints-lie-exactly-on-the-slice-bounds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes two problems in
ReebGraph.slicewhentype="open"(the default):f(u) < a and f(v) > b). In an open slice, a vertex at exactlyaorbis excluded fromv_list, so an edge running fromatobmatched neither rule and disappeared. The check is nowf(u) <= a and f(v) >= b. It also skips edges already picked up through an included endpoint, so no edge is counted twice.slice(a, a, type="open")now returns an emptyReebGraph, since(a, a)is the empty set.For closed slices, an endpoint outside
[a, b]withf(u) <= amust havef(u) < a, so the new condition reduces to the old strict one. Closed-slice output doesn't change.Changes:
cereeberus/cereeberus/reeb/reebgraph.py: early return for a zero-width open slice; updated crossing-edge condition and comment inslice.tests/test_reeb_class.py: four new tests (see below).Motivation and Context
Fixes #___
Example with the package's torus graph (vertices at heights 0, 1, 4, 5 and a double edge from 1 to 4):
ex_rg.torus().slice(1, 4)ex_rg.torus().slice(0, 1)ex_rg.torus().slice(2, 2)Internal code isn't affected.
smoothing_and_maps,smoothingandthickening_distanceonly callslice(..., type="closed"), so their output doesn't change, and neither does the interleaving code built on them.Related: #115 / #116 (performance changes to
slice). The two PRs touch different lines ofreebgraph.pyand merge there without conflicts. Both add tests totests/test_reeb_class.py, so whichever merges second will need a small conflict resolution in that file (keep both sets of tests).How has this been tested?
New tests in
tests/test_reeb_class.py:test_slice_open_endpoint_on_bound: a single edge from 0 to 2, sliced at(0, 2),(0, 1)and(1, 2), gives 2 vertices, 1 edge and 1 component, with the new vertices ataandb. Also run with the edge added high→low.test_slice_open_parallel_edges_on_bounds: three parallel edges sliced at(0, 2)stay as 3 separate components, andtorus.slice(1, 4)gives 2 arcs.test_slice_open_zero_width_is_empty:torus.slice(a, a)is empty at every height.test_slice_closed_unchanged: closed slices give the same results as before, including single-height slices.The first three fail on
masterand pass with this change. The fourth passes on both, which confirms closed slices are unchanged.make tests: all 88 tests pass (84 existing + 4 new).I also compared the old and new code on the package's example graphs (Reeb, mapper and merge trees) and on random Reeb graphs:
smoothing_and_maps,thickening_distanceand the interleaving distance oninterleave_example_Avsinterleave_example_Bdidn't change.Types of changes
Checklist
pyproject.tomlfile if a new version needs to be pushed to pypi. Note that if the number isn't incremented, the package will not be pushed to pypi, which is useful if this PR is only for updating documentation.make formatto clean up the code withblack.make tests).