@@ -132,6 +132,41 @@ def test_store(tmp_path, spec, executor):
132132 assert_array_equal (target [:], np .array ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]]))
133133
134134
135+ def test_store_lazy_compute (tmp_path , spec ):
136+ a = xp .asarray ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]], chunks = (2 , 2 ), spec = spec )
137+
138+ store = tmp_path / "source.zarr"
139+ target = open_storage_array (
140+ store , mode = "w" , shape = a .shape , dtype = a .dtype , chunks = a .chunksize
141+ )
142+
143+ (b ,) = cubed .store (a , target , compute = False )
144+
145+ # target has not been computed yet
146+ with pytest .raises (AssertionError ):
147+ assert_array_equal (target [:], np .array ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]]))
148+
149+ b .compute ()
150+ assert_array_equal (target [:], np .array ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]]))
151+
152+
153+ def test_store_lazy_compute_more (tmp_path , spec ):
154+ a = xp .asarray ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]], chunks = (2 , 2 ), spec = spec )
155+
156+ store = tmp_path / "source.zarr"
157+ target = open_storage_array (
158+ store , mode = "w" , shape = a .shape , dtype = a .dtype , chunks = a .chunksize
159+ )
160+
161+ (b ,) = cubed .store (a , target , compute = False )
162+
163+ # do a further computation and check that store has not been optimized away
164+ c = b + 1
165+ res = c .compute ()
166+ assert_array_equal (target [:], np .array ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]]))
167+ assert_array_equal (res , np .array ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]]) + 1 )
168+
169+
135170def test_store_multiple (tmp_path , spec , executor ):
136171 a = xp .asarray ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]], chunks = (2 , 2 ), spec = spec )
137172 b = xp .asarray ([[1 , 1 , 1 ], [1 , 1 , 1 ], [1 , 1 , 1 ]], chunks = (2 , 2 ), spec = spec )
0 commit comments