@@ -1040,9 +1040,8 @@ def link(self, levels):
10401040 p .forward_cands = []
10411041
10421042 # Sort out what can go to what.
1043- if len (cur_level ) > 0 and len (prev_hash ) > 0 :
1044- assign_candidates (cur_level , prev_hash , self .search_range ,
1045- self .neighbor_strategy )
1043+ assign_candidates (cur_level , prev_hash , self .search_range ,
1044+ self .neighbor_strategy )
10461045
10471046 # sort the candidate lists by distance
10481047 for p in cur_set :
@@ -1233,15 +1232,18 @@ def assign_candidates(cur_level, prev_hash, search_range, neighbor_strategy):
12331232 p .back_cands .append ((wp , d ))
12341233 wp .forward_cands .append ((p , d ))
12351234 elif neighbor_strategy == 'KDTree' :
1236- hashpts = prev_hash .points
1237- cur_coords = np .array ([x .pos for x in cur_level ])
1238- dists , inds = prev_hash .kdtree .query (cur_coords , 10 , distance_upper_bound = search_range )
1239- nn = np .sum (np .isfinite (dists ), 1 ) # Number of neighbors of each particle
1240- for i , p in enumerate (cur_level ):
1241- for j in range (nn [i ]):
1242- wp = hashpts [inds [i , j ]]
1243- p .back_cands .append ((wp , dists [i , j ]))
1244- wp .forward_cands .append ((p , dists [i , j ]))
1235+ # kdtree.query() would raise exception on empty level.
1236+ if len (cur_level ) and len (prev_hash ):
1237+ cur_coords = np .array ([x .pos for x in cur_level ])
1238+ hashpts = prev_hash .points
1239+ dists , inds = prev_hash .kdtree .query (cur_coords , 10 ,
1240+ distance_upper_bound = search_range )
1241+ nn = np .sum (np .isfinite (dists ), 1 ) # Number of neighbors of each particle
1242+ for i , p in enumerate (cur_level ):
1243+ for j in range (nn [i ]):
1244+ wp = hashpts [inds [i , j ]]
1245+ p .back_cands .append ((wp , dists [i , j ]))
1246+ wp .forward_cands .append ((p , dists [i , j ]))
12451247
12461248
12471249class SubnetOversizeException (Exception ):
0 commit comments