| 596 | |
| 597 | |
| 598 | def test_array_delayed_complex_optimization_kwargs(): |
| 599 | # Ensure that collections that if multiple collections are passed to a |
| 600 | # Delayed function that they are optimized together |
| 601 | np = pytest.importorskip("numpy") |
| 602 | pytest.importorskip("dask.array") |
| 603 | from dask.array.core import from_func |
| 604 | from dask.array.utils import assert_eq |
| 605 | |
| 606 | called = False |
| 607 | |
| 608 | def only_once(): |
| 609 | nonlocal called |
| 610 | if called: |
| 611 | raise RuntimeError("Already executed") |
| 612 | |
| 613 | called = True |
| 614 | return np.arange(100).reshape((10, 10)) |
| 615 | |
| 616 | darr = from_func(only_once, shape=(10, 10), dtype=int) |
| 617 | a = darr + 1 |
| 618 | b = darr + 2 |
| 619 | |
| 620 | def sum_kwargs_only(*, a, b, c): |
| 621 | return sum([a, b, c]) |
| 622 | |
| 623 | val = delayed(sum_kwargs_only)(a=a, b=b, c=1) |
| 624 | assert isinstance(val, Delayed) |
| 625 | np_arr = np.arange(100).reshape((10, 10)) |
| 626 | assert_eq(val.compute(), (np_arr + 1) + (np_arr + 2) + 1) |
| 627 | |
| 628 | |
| 629 | def test_array_bag_delayed(): |