[aligner] Continue to use 1xM matrices for KDTree
authorSimon Chabot <simon.chabot@logilab.fr>
Thu, 08 Nov 2012 15:38:05 +0100
changeset 98 20f79a013965
parent 97 f70fb53a019e
child 99 a8b6d9262c20
[aligner] Continue to use 1xM matrices for KDTree
aligner.py
--- a/aligner.py	Thu Nov 08 14:44:08 2012 +0100
+++ b/aligner.py	Thu Nov 08 15:38:05 2012 +0100
@@ -51,15 +51,12 @@
         # XXX : If there are more than 2 dimensions ??
         aligntree  = KDTree([elt[indexes[0]] or (0, 0) for elt in alignset])
         targettree = KDTree([elt[indexes[1]] or (0, 0) for elt in targetset])
-        intraneighbours = aligntree.query_ball_tree(aligntree, threshold)
         extraneighbours = aligntree.query_ball_tree(targettree, threshold)
         neighbours = []
-        for intra in intraneighbours:#XXX: Return an iterator
-            neighbours.append([intra, []])
-            for i in intra:
-                neighbours[-1][1].extend(extraneighbours[i])
-            if len(neighbours[-1][1] == 0):
-                neighbours[-1].pop()
+        for ind in xrange(len(alignset)):
+            neighbours.append([[ind], extraneighbours[ind]])
+            if len(neighbours[-1][1]) == 0:
+                neighbours.pop()
         return neighbours
 
 #### Minhashing #####
@@ -78,7 +75,7 @@
                     neighbours[-1][1].append(i - len(alignset))
                 else:
                     neighbours[-1][0].append(i)
-            if len(neighbours[-1][0]) == 0 or len(neighbours[-1][1] == 0):
+            if len(neighbours[-1][0]) == 0 or len(neighbours[-1][1]) == 0:
                 neighbours.pop()
         return neighbours