MCPcopy Create free account
hub / github.com/dask/dask / functions_of

Function functions_of

dask/optimization.py:378–406  ·  view source on GitHub ↗

Set of functions contained within nested task Examples -------- >>> inc = lambda x: x + 1 >>> add = lambda x, y: x + y >>> mul = lambda x, y: x * y >>> task = (add, (mul, 1, 2), (inc, 3)) # doctest: +SKIP >>> functions_of(task) # doctest: +SKIP set([add, mul, inc])

(task)

Source from the content-addressed store, hash-verified

376
377
378def functions_of(task):
379 """Set of functions contained within nested task
380
381 Examples
382 --------
383 >>> inc = lambda x: x + 1
384 >>> add = lambda x, y: x + y
385 >>> mul = lambda x, y: x * y
386 >>> task = (add, (mul, 1, 2), (inc, 3)) # doctest: +SKIP
387 >>> functions_of(task) # doctest: +SKIP
388 set([add, mul, inc])
389 """
390 funcs = set()
391
392 work = [task]
393 sequence_types = {list, tuple}
394
395 while work:
396 new_work = []
397 for task in work:
398 if type(task) in sequence_types:
399 if istask(task):
400 funcs.add(unwrap_partial(task[0]))
401 new_work.extend(task[1:])
402 else:
403 new_work.extend(task)
404 work = new_work
405
406 return funcs
407
408
409def default_fused_keys_renamer(keys, max_fused_key_length=120):

Callers 2

test_functions_ofFunction · 0.90
inlinableFunction · 0.85

Calls 4

istaskFunction · 0.90
setClass · 0.85
unwrap_partialFunction · 0.85
addMethod · 0.45

Tested by 1

test_functions_ofFunction · 0.72