MCPcopy
hub / github.com/dask/dask / subs

Function subs

dask/core.py:323–359  ·  view source on GitHub ↗

Perform a substitution on a task Examples -------- >>> def inc(x): ... return x + 1 >>> subs((inc, 'x'), 'x', 1) # doctest: +ELLIPSIS ( , 1)

(task, key, val)

Source from the content-addressed store, hash-verified

321
322
323def subs(task, key, val):
324 """Perform a substitution on a task
325
326 Examples
327 --------
328 >>> def inc(x):
329 ... return x + 1
330
331 >>> subs((inc, 'x'), 'x', 1) # doctest: +ELLIPSIS
332 (<function inc at ...>, 1)
333 """
334 type_task = type(task)
335 if not (type_task is tuple and task and callable(task[0])): # istask(task):
336 try:
337 if type_task is type(key) and task == key:
338 return val
339 except Exception:
340 pass
341 if type_task is list:
342 return [subs(x, key, val) for x in task]
343 return task
344 newargs = []
345 hash_key = {key}
346 for arg in task[1:]:
347 type_arg = type(arg)
348 if type_arg is tuple and arg and callable(arg[0]): # istask(task):
349 arg = subs(arg, key, val)
350 elif type_arg is list:
351 arg = [subs(x, key, val) for x in arg]
352 else:
353 try:
354 if arg in hash_key: # Hash and equality match
355 arg = val
356 except TypeError: # not hashable
357 pass
358 newargs.append(arg)
359 return task[:1] + tuple(newargs)
360
361
362def _toposort(dsk, keys=None, returncycle=False, dependencies=None):

Callers 9

_applyMethod · 0.90
fuse_linearFunction · 0.90
inlineFunction · 0.90
fuseFunction · 0.90
test_subsFunction · 0.90
test_subs_no_key_data_eqFunction · 0.90
test_subs_arbitrary_keyFunction · 0.90

Calls

no outgoing calls

Tested by 5

test_subsFunction · 0.72
test_subs_no_key_data_eqFunction · 0.72
test_subs_arbitrary_keyFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…