Skip to content

Commit 84219d9

Browse files
committed
runs but not quicker
1 parent df32d77 commit 84219d9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

ot/lp/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def emd(a, b, M):
7878

7979
return emd_c(a, b, M)
8080

81-
def emd2(a, b, M,processes=None):
81+
def emd2(a, b, M,processes=multiprocessing.cpu_count()):
8282
"""Solves the Earth Movers distance problem and returns the loss
8383
8484
.. math::
@@ -149,9 +149,11 @@ def emd2(a, b, M,processes=None):
149149
else:
150150
nb=b.shape[1]
151151
ls=[(a,b[:,k],M) for k in range(nb)]
152+
def f(l):
153+
return emd2(l[0],l[1],l[2])
152154
# run emd in multiprocessing
153-
res=parmap(emd2, ls,processes)
154-
np.array(res)
155+
res=parmap(f, ls,processes)
156+
return np.array(res)
155157
# with Pool(processes) as p:
156158
# res=p.map(f, ls)
157159
# return np.array(res)
@@ -164,7 +166,7 @@ def fun(f, q_in, q_out):
164166
break
165167
q_out.put((i, f(x)))
166168

167-
def parmap(f, X, nprocs):
169+
def parmap(f, X, nprocs=multiprocessing.cpu_count()):
168170
q_in = multiprocessing.Queue(1)
169171
q_out = multiprocessing.Queue()
170172

0 commit comments

Comments
 (0)