From eb5bf7fbd66abfc798bc272a4aefcb972f61c55f Mon Sep 17 00:00:00 2001 From: Muriithi Frederick Muriuki Date: Fri, 23 Jul 2021 08:11:55 +0300 Subject: Fix issue caught in `nearest` while testing `slink` Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * While running tests for slink, to try and understand what it is doing in order to write the appropriate tests for it, an issue arose that pointed a blindspot in the former understanding of now `nearest` should work. This commit fixes the issue found in both the expected data, and the code. --- gn3/computations/slink.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gn3/computations') diff --git a/gn3/computations/slink.py b/gn3/computations/slink.py index 103a853..0c74789 100644 --- a/gn3/computations/slink.py +++ b/gn3/computations/slink.py @@ -108,9 +108,9 @@ def nearest(lists, i, j): if type(i) == int and type(j) == int: # From member i to member j return lists[i][j] elif type(i) == int and __is_list_or_tuple(j): - return min(map(lambda j_new: nearest(lists, i, j_new), j)) + return min(map(lambda j_new: nearest(lists, i, j_new), j[:-1])) elif type(j) == int and __is_list_or_tuple(i): - return min(map(lambda i_new: nearest(lists, i_new, j), i)) + return min(map(lambda i_new: nearest(lists, i_new, j), i[:-1])) elif __is_list_or_tuple(i) and __is_list_or_tuple(j): partial_i = map(lambda x:partial(nearest, lists, x), i[:-1]) ns = list(map(lambda f, x: f(x), partial_i, j[:1])) -- cgit v1.2.3