MCPcopy Create free account
hub / github.com/dask/dask / compute

Function compute

dask/base.py:597–683  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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

Callers 10

test_compute_arrayFunction · 0.90
test_compute_dataframeFunction · 0.90
test_compute_array_bagFunction · 0.90
test_compute_nestedFunction · 0.90
test_optimize_nestedFunction · 0.90
test_persist_nestedFunction · 0.90
test_num_workers_configFunction · 0.90
computeMethod · 0.70

Calls 10

FinalizeComputeClass · 0.90
shorten_tracebackClass · 0.90
flattenFunction · 0.90
get_schedulerFunction · 0.85
collections_to_exprFunction · 0.85
scheduleFunction · 0.85
repackFunction · 0.85
unpack_collectionsFunction · 0.70
optimizeMethod · 0.45
__dask_keys__Method · 0.45

Tested by 9

test_compute_arrayFunction · 0.72
test_compute_dataframeFunction · 0.72
test_compute_array_bagFunction · 0.72
test_compute_nestedFunction · 0.72
test_optimize_nestedFunction · 0.72
test_persist_nestedFunction · 0.72
test_num_workers_configFunction · 0.72