| 2086 | |
| 2087 | |
| 2088 | def test_store_delayed_target(): |
| 2089 | from dask.delayed import delayed |
| 2090 | |
| 2091 | d = da.ones((4, 4), chunks=(2, 2)) |
| 2092 | a, b = d + 1, d + 2 |
| 2093 | |
| 2094 | # empty buffers to be used as targets |
| 2095 | targs = {} |
| 2096 | |
| 2097 | def make_target(key): |
| 2098 | a = np.empty((4, 4)) |
| 2099 | targs[key] = a |
| 2100 | return a |
| 2101 | |
| 2102 | # delayed calls to these targets |
| 2103 | atd = delayed(make_target)("at") |
| 2104 | btd = delayed(make_target)("bt") |
| 2105 | |
| 2106 | # test not keeping result |
| 2107 | st = store([a, b], [atd, btd]) |
| 2108 | |
| 2109 | at = targs["at"] |
| 2110 | bt = targs["bt"] |
| 2111 | |
| 2112 | assert st is None |
| 2113 | assert_eq(at, a) |
| 2114 | assert_eq(bt, b) |
| 2115 | |
| 2116 | # test keeping result |
| 2117 | for st_compute in [False, True]: |
| 2118 | targs.clear() |
| 2119 | st = store([a, b], [atd, btd], return_stored=True, compute=st_compute) |
| 2120 | if st_compute: |
| 2121 | for arr in st: |
| 2122 | assert_has_persisted_data(arr) |
| 2123 | |
| 2124 | st = dask.compute(*st) |
| 2125 | |
| 2126 | at = targs["at"] |
| 2127 | bt = targs["bt"] |
| 2128 | |
| 2129 | assert st is not None |
| 2130 | assert isinstance(st, tuple) |
| 2131 | assert all([isinstance(v, np.ndarray) for v in st]) |
| 2132 | assert_eq(at, a) |
| 2133 | assert_eq(bt, b) |
| 2134 | assert_eq(st[0], a) |
| 2135 | assert_eq(st[1], b) |
| 2136 | |
| 2137 | pytest.raises(ValueError, lambda at=at, bt=bt: store([a], [at, bt])) |
| 2138 | pytest.raises(ValueError, lambda at=at: store(at, at)) |
| 2139 | pytest.raises(ValueError, lambda at=at, bt=bt: store([at, bt], [at, bt])) |
| 2140 | |
| 2141 | |
| 2142 | def test_store(): |