From 7e8a3347cc04433c55a5f6a3f528e9163fee6543 Mon Sep 17 00:00:00 2001 From: Muriithi Frederick Muriuki Date: Fri, 23 Jul 2021 09:03:12 +0300 Subject: Iterate through all valid pairs Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * gn3/computations/slink.py: Fix the iteration construct. Given two lists of member coordinates, such as [0, 1] and [3, 5], the initial code would iterate over the pairs [0, 3] and [1, 5]. This commit fixes the iteration constructs such that the new code iterates over the pairs [0, 3], [0, 5], [1, 3] and [1, 5]. --- gn3/computations/slink.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gn3/computations') diff --git a/gn3/computations/slink.py b/gn3/computations/slink.py index 7ee9b5e..59d0975 100644 --- a/gn3/computations/slink.py +++ b/gn3/computations/slink.py @@ -115,9 +115,9 @@ def nearest(lists, i, j): elif type(j) == int and __is_list_or_tuple(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])) - return min(ns) + coordinate_pairs = __flatten_list_of_lists( + [[(itemi, itemj) for itemj in j[:-1]] for itemi in i[:-1]]) + return min(map(lambda x: nearest(lists, x[0], x[1]), coordinate_pairs)) else: raise ValueError("member values (i or j) should be lists/tuples of integers or integers") -- cgit v1.2.3