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,
)
| 683 | |
| 684 | |
| 685 | def compute( |
| 686 | *args, |
| 687 | traverse=True, |
| 688 | optimize_graph=True, |
| 689 | scheduler=None, |
| 690 | get=None, |
| 691 | **kwargs, |
| 692 | ): |
| 693 | """Compute several dask collections at once. |
| 694 | |
| 695 | Parameters |
| 696 | ---------- |
| 697 | args : object |
| 698 | Any number of objects. If it is a dask object, it's computed and the |
| 699 | result is returned. By default, python builtin collections are also |
| 700 | traversed to look for dask objects (for more information see the |
| 701 | ``traverse`` keyword). Non-dask arguments are passed through unchanged. |
| 702 | traverse : bool, optional |
| 703 | By default dask traverses builtin python collections looking for dask |
| 704 | objects passed to ``compute``. For large collections this can be |
| 705 | expensive. If none of the arguments contain any dask objects, set |
| 706 | ``traverse=False`` to avoid doing this traversal. |
| 707 | scheduler : string, optional |
| 708 | Which scheduler to use like "threads", "synchronous" or "processes". |
| 709 | If not provided, the default is to check the global settings first, |
| 710 | and then fall back to the collection defaults. |
| 711 | optimize_graph : bool, optional |
| 712 | If True [default], the optimizations for each collection are applied |
| 713 | before computation. Otherwise the graph is run as is. This can be |
| 714 | useful for debugging. |
| 715 | get : ``None`` |
| 716 | Should be left to ``None`` The get= keyword has been removed. |
| 717 | kwargs |
| 718 | Extra keywords to forward to the scheduler function. |
| 719 | |
| 720 | Examples |
| 721 | -------- |
| 722 | >>> import dask |
| 723 | >>> import dask.array as da |
| 724 | >>> a = da.arange(10, chunks=2).sum() |
| 725 | >>> b = da.arange(10, chunks=2).mean() |
| 726 | >>> dask.compute(a, b) |
| 727 | (np.int64(45), np.float64(4.5)) |
| 728 | |
| 729 | By default, dask objects inside python collections will also be computed: |
| 730 | |
| 731 | >>> dask.compute({'a': a, 'b': b, 'c': 1}) |
| 732 | ({'a': np.int64(45), 'b': np.float64(4.5), 'c': 1},) |
| 733 | """ |
| 734 | |
| 735 | collections, repack = unpack_collections(*args, traverse=traverse) |
| 736 | if not collections: |
| 737 | return args |
| 738 | |
| 739 | schedule = get_scheduler( |
| 740 | scheduler=scheduler, |
| 741 | collections=collections, |
| 742 | get=get, |