J'essaie de construire un dictionnaire en parallèle à l'aide de Dask, mais je me heurte à une TypeError: Delayed objects of unspecified length are not iterable
.
J'essaie de calculer add
, subtract
y multiply
en même temps pour que le dictionnaire soit construit plus rapidement.
Voici un code représentatif de mon cas d'utilisation :
import dask
from dask.delayed import delayed
x1 = {'a': 1, 'b': 2, 'c': 3}
x2 = {'a': 4, 'b': 5, 'c': 6}
@delayed
def add(d1, d2):
z = {}
z['func1_a'] = d1['a'] + d2['a']
z['func1_b'] = d1['b'] + d2['b']
z['func1_c'] = d1['c'] + d2['c']
return z
@delayed
def subtract(d1, d2):
z = {}
z['func2_a'] = d1['a'] - d2['a']
z['func2_b'] = d1['b'] - d2['b']
z['func2_c'] = d1['c'] - d2['c']
return z
@delayed
def multiply(d1, d2):
z = {}
z['func3_a'] = d1['a'] * d2['a']
z['func3_b'] = d1['b'] * d2['b']
z['func3_c'] = d1['c'] * d2['c']
return z
@delayed
def last_step(d1, d2):
z = {}
z.update(add(d1, d2))
z.update(subtract(d1, d2))
z.update(multiply(d1, d2))
return z
Enfin, quand je cours :
>>> dask.compute(last_step(x1, x2))
<ipython-input-6-1153797c9d18> in final(d1, d2)
2 def last_step(d1, d2):
3 z = {}
----> 4 z.update(add(d1, d2))
5 z.update(subtract(d1, d2))
6 z.update(multiply(d1, d2))
/Users/me/anaconda3/lib/python3.6/site-packages/dask/delayed.py in __iter__(self)
409 def __iter__(self):
410 if getattr(self, '_length', None) is None:
--> 411 raise TypeError("Delayed objects of unspecified length are "
412 "not iterable")
413 for i in range(self._length):
TypeError: Delayed objects of unspecified length are not iterable
Qu'est-ce que je fais mal ici / que je ne comprends pas ?