~tfardet/nngt-developers

NNGT: Bugfix - delete_edges with nngt backend v1 APPLIED

~tfardet
~tfardet: 1
 Bugfix - delete_edges with nngt backend

 2 files changed, 23 insertions(+), 0 deletions(-)
#567397 .build.yml failed
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~tfardet/nngt-developers/patches/24417/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH NNGT] Bugfix - delete_edges with nngt backend Export this patch

~tfardet
From: Tanguy Fardet <tanguyfardet@protonmail.com>

Correctly update in- and out-degrees after edge deletion.
---
 nngt/core/nngt_graph.py |  6 ++++++
 testing/test_basics.py  | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/nngt/core/nngt_graph.py b/nngt/core/nngt_graph.py
index a3e592f..d3853dd 100644
--- a/nngt/core/nngt_graph.py
+++ b/nngt/core/nngt_graph.py
@@ -896,6 +896,12 @@ class _NNGTGraph(GraphInterface):
                    del g._edges[e]
                    del g._edges[e[::-1]]

            # update in and out degrees
            s, t = e

            g._in_deg[t] -= 1
            g._out_deg[s] -= 1

        # reset eids
        for i, e in enumerate(g._unique):
            g._unique[e] = i
diff --git a/testing/test_basics.py b/testing/test_basics.py
index 9dc5175..0daf15c 100755
--- a/testing/test_basics.py
+++ b/testing/test_basics.py
@@ -590,6 +590,9 @@ def test_delete():
    num_nodes = 6
    num_edges = 12

    in_deg = [2, 3, 2, 1, 2, 2]
    out_deg = [3, 2, 2, 2, 2, 1]

    # make positions and structure
    rng = np.random.default_rng()

@@ -608,6 +611,9 @@ def test_delete():
    # delete one edge (eid = 2)
    edge = (0, 5)

    in_deg[5] -= 1
    out_deg[0] -= 1

    g.delete_edges(edge)

    num_edges -= 1
@@ -616,6 +622,9 @@ def test_delete():

    assert len(g.get_weights()) == num_edges

    assert np.array_equal(in_deg, g.get_degrees("in"))
    assert np.array_equal(out_deg, g.get_degrees("out"))

    mat[edge] = 0

    adj = g.adjacency_matrix(weights=True, mformat="dense")
@@ -627,12 +636,20 @@ def test_delete():

    g.delete_edges(edges)

    in_deg[4] -= 1
    out_deg[1] -= 1
    in_deg[1] -= 1
    out_deg[3] -= 1

    num_edges -= len(edges)

    assert g.edge_nb() == num_edges

    assert len(g.get_weights()) == num_edges

    assert np.array_equal(in_deg, g.get_degrees("in"))
    assert np.array_equal(out_deg, g.get_degrees("out"))

    for e in edges:
        mat[e] = 0

-- 
2.32.0