MCPcopy
hub / github.com/dask/dask / bind

Function bind

dask/graph_manipulation.py:210–312  ·  view source on GitHub ↗

Make ``children`` collection(s), optionally omitting sub-collections, dependent on ``parents`` collection(s). Two examples follow. The first example creates an array ``b2`` whose computation first computes an array ``a`` completely and then computes ``b`` completely, recomputing ``

(
    children: T,
    parents,
    *,
    omit=None,
    seed: Hashable | None = None,
    assume_layers: bool = True,
    split_every: float | Literal[False] | None = None,
)

Source from the content-addressed store, hash-verified

208
209
210def bind(
211 children: T,
212 parents,
213 *,
214 omit=None,
215 seed: Hashable | None = None,
216 assume_layers: bool = True,
217 split_every: float | Literal[False] | None = None,
218) -> T:
219 """
220 Make ``children`` collection(s), optionally omitting sub-collections, dependent on
221 ``parents`` collection(s). Two examples follow.
222
223 The first example creates an array ``b2`` whose computation first computes an array
224 ``a`` completely and then computes ``b`` completely, recomputing ``a`` in the
225 process:
226
227 >>> import dask
228 >>> import dask.array as da
229 >>> a = da.ones(4, chunks=2)
230 >>> b = a + 1
231 >>> b2 = bind(b, a)
232 >>> len(b2.dask)
233 9
234 >>> b2.compute()
235 array([2., 2., 2., 2.])
236
237 The second example creates arrays ``b3`` and ``c3``, whose computation first
238 computes an array ``a`` and then computes the additions, this time not
239 recomputing ``a`` in the process:
240
241 >>> c = a + 2
242 >>> b3, c3 = bind((b, c), a, omit=a)
243 >>> len(b3.dask), len(c3.dask)
244 (7, 7)
245 >>> dask.compute(b3, c3)
246 (array([2., 2., 2., 2.]), array([3., 3., 3., 3.]))
247
248 Parameters
249 ----------
250 children
251 Dask collection or nested structure of Dask collections
252 parents
253 Dask collection or nested structure of Dask collections
254 omit
255 Dask collection or nested structure of Dask collections
256 seed
257 Hashable used to seed the key regeneration. Omit to default to a random number
258 that will produce different keys at every call.
259 assume_layers
260 True
261 Use a fast algorithm that works at layer level, which assumes that all
262 collections in ``children`` and ``omit``
263
264 #. use :class:`~dask.highlevelgraph.HighLevelGraph`,
265 #. define the ``__dask_layers__()`` method, and
266 #. never had their graphs squashed and rebuilt between the creation of the
267 ``omit`` collections and the ``children`` collections; in other words if

Callers 3

test_bindFunction · 0.90
test_split_everyFunction · 0.90
cloneFunction · 0.85

Calls 7

unpack_collectionsFunction · 0.90
checkpointFunction · 0.85
setClass · 0.85
repackFunction · 0.85
_bind_oneFunction · 0.85
__dask_layers__Method · 0.45
__dask_graph__Method · 0.45

Tested by 2

test_bindFunction · 0.72
test_split_everyFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…