| 569 | |
| 570 | |
| 571 | def test_array_delayed_complex_optimization(): |
| 572 | # Ensure that when multiple collections are passed to a Delayed function, |
| 573 | # they are optimized together |
| 574 | np = pytest.importorskip("numpy") |
| 575 | pytest.importorskip("dask.array") |
| 576 | from dask.array.core import from_func |
| 577 | from dask.array.utils import assert_eq |
| 578 | |
| 579 | called = False |
| 580 | |
| 581 | def only_once(): |
| 582 | nonlocal called |
| 583 | if called: |
| 584 | raise RuntimeError("Already executed") |
| 585 | |
| 586 | called = True |
| 587 | return np.arange(100).reshape((10, 10)) |
| 588 | |
| 589 | darr = from_func(only_once, shape=(10, 10), dtype=int) |
| 590 | a = darr + 1 |
| 591 | b = darr + 2 |
| 592 | val = delayed(sum)([a, b, 1]) |
| 593 | assert isinstance(val, Delayed) |
| 594 | np_arr = np.arange(100).reshape((10, 10)) |
| 595 | assert_eq(val.compute(), (np_arr + 1) + (np_arr + 2) + 1) |
| 596 | |
| 597 | |
| 598 | def test_array_delayed_complex_optimization_kwargs(): |