| 1 |
API |
| 2 |
=== |
| 3 |
|
| 4 |
The ``dask.delayed`` interface consists of one function, ``delayed``: |
| 5 |
|
| 6 |
- ``delayed`` wraps functions |
| 7 |
|
| 8 |
Wraps functions. Can be used as a decorator, or around function calls |
| 9 |
directly (i.e. ``delayed(foo)(a, b, c)``). Outputs from functions wrapped in |
| 10 |
``delayed`` are proxy objects of type ``Delayed`` that contain a graph of |
| 11 |
all operations done to get to this result. |
| 12 |
|
| 13 |
- ``delayed`` wraps objects |
| 14 |
|
| 15 |
Wraps objects. Used to create ``Delayed`` proxies directly. |
| 16 |
|
| 17 |
``Delayed`` objects can be thought of as representing a key in the dask task |
| 18 |
graph. A ``Delayed`` supports *most* python operations, each of which creates |
| 19 |
another ``Delayed`` representing the result: |
| 20 |
|
| 21 |
- Most operators (``*``, ``-``, and so on) |
| 22 |
- Item access and slicing (``a[0]``) |
| 23 |
- Attribute access (``a.size``) |
| 24 |
- Method calls (``a.index(0)``) |
| 25 |
|
| 26 |
Operations that aren't supported include: |
| 27 |
|
| 28 |
- Mutating operators (``a += 1``) |
| 29 |
- Mutating magics such as ``__setitem__``/``__setattr__`` (``a[0] = 1``, ``a.foo = 1``) |
| 30 |
- Iteration. (``for i in a: ...``) |
| 31 |
- Use as a predicate (``if a: ...``) |
| 32 |
|
| 33 |
The last two points in particular mean that ``Delayed`` objects cannot be used for |
| 34 |
control flow, meaning that no ``Delayed`` can appear in a loop or if statement. |
| 35 |
In other words you can't iterate over a ``Delayed`` object, or use it as part of |
| 36 |
a condition in an if statement, but ``Delayed`` object can be used in a body of a loop |
| 37 |
or if statement (i.e. the example above is fine, but if ``data`` was a ``Delayed`` |
| 38 |
object it wouldn't be). |
| 39 |
Even with this limitation, many workflows can easily be parallelized. |
| 40 |
|
| 41 |
.. currentmodule:: dask.delayed |
| 42 |
|
| 43 |
.. autosummary:: |
| 44 |
delayed |
| 45 |
Delayed |
| 46 |
|
| 47 |
.. autofunction:: delayed |
| 48 |
.. autoclass:: Delayed |