Compute several dask collections at once. Parameters ---------- args : object Any number of objects. If it is a dask object, it's computed and the result is returned. By default, python builtin collections are also traversed to look for dask objects (for more inf
(
*args,
traverse=True,
optimize_graph=True,
scheduler=None,
get=None,
**kwargs,
)
| 599 | |
| 600 | |
| 601 | def compute( |
| 602 | *args, |
| 603 | traverse=True, |
| 604 | optimize_graph=True, |
| 605 | scheduler=None, |
| 606 | get=None, |
| 607 | **kwargs, |
| 608 | ): |
| 609 | """Compute several dask collections at once. |
| 610 | |
| 611 | Parameters |
| 612 | ---------- |
| 613 | args : object |
| 614 | Any number of objects. If it is a dask object, it's computed and the |
| 615 | result is returned. By default, python builtin collections are also |
| 616 | traversed to look for dask objects (for more information see the |
| 617 | ``traverse`` keyword). Non-dask arguments are passed through unchanged. |
| 618 | traverse : bool, optional |
| 619 | By default dask traverses builtin python collections looking for dask |
| 620 | objects passed to ``compute``. For large collections this can be |
| 621 | expensive. If none of the arguments contain any dask objects, set |
| 622 | ``traverse=False`` to avoid doing this traversal. |
| 623 | scheduler : string, optional |
| 624 | Which scheduler to use like "threads", "synchronous" or "processes". |
| 625 | If not provided, the default is to check the global settings first, |
| 626 | and then fall back to the collection defaults. |
| 627 | optimize_graph : bool, optional |
| 628 | If True [default], the optimizations for each collection are applied |
| 629 | before computation. Otherwise the graph is run as is. This can be |
| 630 | useful for debugging. |
| 631 | get : ``None`` |
| 632 | Should be left to ``None`` The get= keyword has been removed. |
| 633 | kwargs |
| 634 | Extra keywords to forward to the scheduler function. |
| 635 | |
| 636 | Examples |
| 637 | -------- |
| 638 | >>> import dask |
| 639 | >>> import dask.array as da |
| 640 | >>> a = da.arange(10, chunks=2).sum() |
| 641 | >>> b = da.arange(10, chunks=2).mean() |
| 642 | >>> dask.compute(a, b) |
| 643 | (np.int64(45), np.float64(4.5)) |
| 644 | |
| 645 | By default, dask objects inside python collections will also be computed: |
| 646 | |
| 647 | >>> dask.compute({'a': a, 'b': b, 'c': 1}) |
| 648 | ({'a': np.int64(45), 'b': np.float64(4.5), 'c': 1},) |
| 649 | """ |
| 650 | |
| 651 | collections, repack = unpack_collections(*args, traverse=traverse) |
| 652 | if not collections: |
| 653 | return args |
| 654 | |
| 655 | schedule = get_scheduler( |
| 656 | scheduler=scheduler, |
| 657 | collections=collections, |
| 658 | get=get, |
searching dependent graphs…