|
11 | 11 | # License: MIT License |
12 | 12 |
|
13 | 13 | import multiprocessing |
14 | | - |
| 14 | +import sys |
15 | 15 | import numpy as np |
16 | 16 | from scipy.sparse import coo_matrix |
17 | 17 |
|
@@ -151,6 +151,8 @@ def emd2(a, b, M, processes=multiprocessing.cpu_count(), |
151 | 151 | Target histogram (uniform weight if empty list) |
152 | 152 | M : (ns,nt) numpy.ndarray, float64 |
153 | 153 | Loss matrix (c-order array with type float64) |
| 154 | + processes : int, optional (default=nb cpu) |
| 155 | + Nb of processes used for multiple emd computation (not used on windows) |
154 | 156 | numItermax : int, optional (default=100000) |
155 | 157 | The maximum number of iterations before stopping the optimization |
156 | 158 | algorithm if it has not converged. |
@@ -200,6 +202,10 @@ def emd2(a, b, M, processes=multiprocessing.cpu_count(), |
200 | 202 | b = np.asarray(b, dtype=np.float64) |
201 | 203 | M = np.asarray(M, dtype=np.float64) |
202 | 204 |
|
| 205 | + # problem with pikling Forks |
| 206 | + if sys.platform.endswith('win32'): |
| 207 | + processes=1 |
| 208 | + |
203 | 209 | # if empty array given then use uniform distributions |
204 | 210 | if len(a) == 0: |
205 | 211 | a = np.ones((M.shape[0],), dtype=np.float64) / M.shape[0] |
@@ -228,7 +234,11 @@ def f(b): |
228 | 234 | return f(b) |
229 | 235 | nb = b.shape[1] |
230 | 236 |
|
231 | | - res = parmap(f, [b[:, i] for i in range(nb)], processes) |
| 237 | + if processes>1: |
| 238 | + res = parmap(f, [b[:, i] for i in range(nb)], processes) |
| 239 | + else: |
| 240 | + res = list(map(f, [b[:, i].copy() for i in range(nb)])) |
| 241 | + |
232 | 242 | return res |
233 | 243 |
|
234 | 244 |
|
|
0 commit comments