def _dense_distance_dual(lock, list1, list2, global_idx, shared_arr, dist_function):
"""Parallelize a general computation of a distance matrix.
Parameters
----------
lock : multiprocessing.synchronize.Lock
Value returned from multiprocessing.Lock().
input_list : list
List of values to compare to input_list[idx] (from 'idx' on).
shared_arr : array_like
Numpy array created as a shared object. Iteratively updated with the
result.
Example:
shared_array = np.frombuffer(mp.Array('d', n*n).get_obj()).reshape((n,n))
Returns
-------
"""
list_len = len(list1)
# PID = os.getpid()
# print("PID {} takes index {}".format(PID, index_i))
while global_idx.value < list_len:
with lock:
if not global_idx.value < list_len: return
idx = global_idx.value
global_idx.value += 1
# if idx % 100 == 0: progressbar(idx, list_len)
elem_1 = list1[idx]
for idx_j in range(len(list2)):
shared_arr[idx, idx_j] = dist_function(elem_1, list2[idx_j])
评论列表
文章目录