MCPcopy
hub / github.com/dask/dask / ndependencies

Function ndependencies

dask/order.py:705–751  ·  view source on GitHub ↗

Number of total data elements on which this key depends For each key we return the number of tasks that must be run for us to run this task. Examples -------- >>> inc = lambda x: x + 1 >>> dsk = {'a': 1, 'b': (inc, 'a'), 'c': (inc, 'b')} >>> dependencies, dependents = g

(
    dependencies: Mapping[Key, set[Key]], dependents: Mapping[Key, set[Key]]
)

Source from the content-addressed store, hash-verified

703
704
705def ndependencies(
706 dependencies: Mapping[Key, set[Key]], dependents: Mapping[Key, set[Key]]
707) -> tuple[dict[Key, int], dict[Key, int]]:
708 """Number of total data elements on which this key depends
709
710 For each key we return the number of tasks that must be run for us to run
711 this task.
712
713 Examples
714 --------
715 >>> inc = lambda x: x + 1
716 >>> dsk = {'a': 1, 'b': (inc, 'a'), 'c': (inc, 'b')}
717 >>> dependencies, dependents = get_deps(dsk)
718 >>> num_dependencies, total_dependencies = ndependencies(dependencies, dependents)
719 >>> sorted(total_dependencies.items())
720 [('a', 1), ('b', 2), ('c', 3)]
721
722 Returns
723 -------
724 num_dependencies: Dict[key, int]
725 total_dependencies: Dict[key, int]
726 """
727 num_needed = {}
728 result = {}
729 for k, v in dependencies.items():
730 num_needed[k] = len(v)
731 if not v:
732 result[k] = 1
733
734 num_dependencies = num_needed.copy()
735 current: list[Key] = []
736 current_pop = current.pop
737 current_append = current.append
738
739 for key in result:
740 for parent in dependents[key]:
741 num_needed[parent] -= 1
742 if not num_needed[parent]:
743 current_append(parent)
744 while current:
745 key = current_pop()
746 result[key] = 1 + sum(result[child] for child in dependencies[key])
747 for parent in dependents[key]:
748 num_needed[parent] -= 1
749 if not num_needed[parent]:
750 current_append(parent)
751 return num_dependencies, result
752
753
754OrderInfo = namedtuple(

Callers 2

test_stacklimitFunction · 0.90
orderFunction · 0.85

Calls 3

sumFunction · 0.50
itemsMethod · 0.45
copyMethod · 0.45

Tested by 1

test_stacklimitFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…