Fix ReebGraph.boundary_matrix(astype="map") dropping parallel edges - #126
Merged
lizliz merged 3 commits intoSep 24, 2026
Merged
Conversation
ishikaghosh2201
requested review from
lizliz
and
a lite review from Copilot
September 23, 2026 18:38
…graphboundary_matrixastypemap-drops-parallel-edges
lizliz
approved these changes
Sep 24, 2026
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
boundary_matrixbuilt its edge list withself.edges(), which leaves out the multigraph keys. Themapbranch then set every key to0, so all copies of a multi-edge were written to the same dictionary entry(u, v, 0), and only one survived. After an edge was removed, the map could also report a key that no longer exists.This PR:
self.edges(keys=True), so every edge keeps its real(u, v, key);mapbranch that set every key to0.The
numpybranch only readse[0]ande[1], so its output doesn't change.Changes:
cereeberus/cereeberus/reeb/reebgraph.py: two small edits inboundary_matrix.tests/test_reeb_class.py: three new tests (see below).Motivation and Context
Fixes #___
Example with the package's torus graph, which has a double edge
('b', 'c', 0)and('b', 'c', 1):ex_rg.torus().boundary_matrix(astype="map")('b', 'c', 1)missingremove_edge('b', 'c', 0)('b', 'c', 0), which was deleted('b', 'c', 1)Internal code isn't affected. Nothing in the repo uses the
mapform:plot_boundary_matrix,test_matricesand themapper_basicsdocs notebook all use the NumPy form, whose output is unchanged. Code outside the repo that reads the map will now see the real edge keys instead of0for every edge.Related: the open-slice fix (#___) changes a different method; the two PRs don't conflict.
How has this been tested?
New tests in
tests/test_reeb_class.py:test_boundary_map_parallel_edges: on the torus example, the map has exactly one entry per edge, including both copies of the double edge, and each entry maps to that edge's two endpoints.test_boundary_map_keys_after_edge_removal: afterremove_edge('b', 'c', 0), the map contains('b', 'c', 1)and not the removed key.test_boundary_matrix_numpy_with_parallel_edges: the NumPy matrix has one column per edge, and each column has exactly two 1s.The first two fail on
masterand pass with this change. The third passes on both, which confirms the NumPy output is unchanged.make tests: all 87 tests pass (84 existing + 3 new).I also compared the NumPy boundary matrix before and after the change on the package's example graphs (Reeb, mapper and merge trees) and on random Reeb graphs. Every matrix came out identical. The map changed only on graphs with parallel edges, and on each of those it went from missing entries to one entry per edge.
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).