From dd2b530f95f5094b0a6c1771d6cbfbd3f3f534f7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Al=C3=A1n=20Mu=C3=B1oz?= <alan.munoz@ed.ac.uk>
Date: Thu, 29 Sep 2022 22:09:58 +0100
Subject: [PATCH] fix(post): finally ensure proper merge filtering

---
 src/agora/io/signal.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/agora/io/signal.py b/src/agora/io/signal.py
index 5c52f2d3..7f8af048 100644
--- a/src/agora/io/signal.py
+++ b/src/agora/io/signal.py
@@ -435,6 +435,10 @@ def validate_merges(merges: np.ndarray, indices: np.ndarray) -> np.ndarray:
     # valid_ndmerges = merges.swapaxes(1, 2)[..., None] == indices.T[:, None, :]
     valid_ndmerges = merges[..., None] == indices.T[None, ...]
 
-    valid_merges = merges[valid_ndmerges.all(axis=2).any(axis=2).any(axis=1)]
+    # Casting is confusing (but efficient):
+    # - First we check the dimension across trap and cell id, to ensure both match
+    # - Then we check the dimension that crosses all indices, to ensure the pair is present there
+    # - Finally we check the merge tuples to check which cases have both target and source
+    valid_merges = merges[valid_ndmerges.all(axis=2).any(axis=2).all(axis=1)]
     # valid_merges = merges[allnan.any(axis=1)]
     return valid_merges
-- 
GitLab