Dask Delayed
It is an interface provided dask to make the function calls lazy and supporting parallelism.
import dask
def mean(a):
return np.mean(a)
mean
becomes lazy. Calling it won’t give back the result. We need to explicitly call compute
.
delayed = dask.delayed(mean)(a)
delayed.compute()
Dask actually creates a task graph of function calls which can be chained together.
For example,
def inc(x):
return x + 1
def dec(x):
return x - 1
def add(x, y):
return x + y
z = dask.delayed(add)(
dask.delayed(inc)(1),
dask.delayed(dec)(2)
)
dask.visualise(z)
Refer notebook for more details.