17
17
from cubed .backend_array_api import IS_IMMUTABLE_ARRAY , numpy_array_to_backend_array
18
18
from cubed .backend_array_api import namespace as nxp
19
19
from cubed .core .array import CoreArray , check_array_specs , compute , gensym
20
- from cubed .core .plan import Plan , new_temp_path
20
+ from cubed .core .plan import Plan , context_dir_path
21
21
from cubed .primitive .blockwise import blockwise as primitive_blockwise
22
22
from cubed .primitive .blockwise import general_blockwise as primitive_general_blockwise
23
23
from cubed .primitive .memory import get_buffer_copies
24
24
from cubed .primitive .rechunk import rechunk as primitive_rechunk
25
25
from cubed .spec import spec_from_config
26
26
from cubed .storage .backend import open_backend_array
27
+ from cubed .storage .zarr import lazy_zarr_array
27
28
from cubed .types import T_RegularChunks , T_Shape
28
29
from cubed .utils import (
29
30
array_memory ,
@@ -157,6 +158,14 @@ def store(sources: Union["Array", Sequence["Array"]], targets, executor=None, **
157
158
for source , target in zip (sources , targets ):
158
159
identity = lambda a : a
159
160
ind = tuple (range (source .ndim ))
161
+
162
+ if target is not None and not isinstance (target , zarr .Array ):
163
+ target = lazy_zarr_array (
164
+ target ,
165
+ shape = source .shape ,
166
+ dtype = source .dtype ,
167
+ chunks = source .chunksize ,
168
+ )
160
169
array = blockwise (
161
170
identity ,
162
171
ind ,
@@ -192,6 +201,14 @@ def to_zarr(x: "Array", store, path=None, executor=None, **kwargs):
192
201
# by map fusion (if it was produced with a blockwise operation).
193
202
identity = lambda a : a
194
203
ind = tuple (range (x .ndim ))
204
+ if store is not None and not isinstance (store , zarr .Array ):
205
+ store = lazy_zarr_array (
206
+ store ,
207
+ shape = x .shape ,
208
+ dtype = x .dtype ,
209
+ chunks = x .chunksize ,
210
+ path = path ,
211
+ )
195
212
out = blockwise (
196
213
identity ,
197
214
ind ,
@@ -200,7 +217,6 @@ def to_zarr(x: "Array", store, path=None, executor=None, **kwargs):
200
217
dtype = x .dtype ,
201
218
align_arrays = False ,
202
219
target_store = store ,
203
- target_path = path ,
204
220
)
205
221
out .compute (executor = executor , _return_in_memory_array = False , ** kwargs )
206
222
@@ -298,7 +314,7 @@ def blockwise(
298
314
spec = check_array_specs (arrays )
299
315
buffer_copies = get_buffer_copies (spec )
300
316
if target_store is None :
301
- target_store = new_temp_path ( name = name , spec = spec )
317
+ target_store = context_dir_path ( spec = spec )
302
318
op = primitive_blockwise (
303
319
func ,
304
320
out_ind ,
@@ -452,14 +468,14 @@ def _general_blockwise(
452
468
if isinstance (target_stores , list ): # multiple outputs
453
469
name = [gensym () for _ in range (len (target_stores ))]
454
470
target_stores = [
455
- ts if ts is not None else new_temp_path ( name = n , spec = spec )
456
- for n , ts in zip ( name , target_stores )
471
+ ts if ts is not None else context_dir_path ( spec = spec )
472
+ for ts in target_stores
457
473
]
458
474
target_names = name
459
475
else : # single output
460
476
name = gensym ()
461
477
if target_stores is None :
462
- target_stores = [new_temp_path ( name = name , spec = spec )]
478
+ target_stores = [context_dir_path ( spec = spec )]
463
479
target_names = [name ]
464
480
465
481
op = primitive_general_blockwise (
@@ -886,18 +902,17 @@ def rechunk(x, chunks, *, target_store=None, min_mem=None, use_new_impl=True):
886
902
name = gensym ()
887
903
spec = x .spec
888
904
if target_store is None :
889
- target_store = new_temp_path ( name = name , spec = spec )
905
+ target_store = context_dir_path ( spec = spec )
890
906
name_int = f"{ name } -int"
891
- temp_store = new_temp_path (name = name_int , spec = spec )
892
907
ops = primitive_rechunk (
893
908
x ._zarray ,
894
- source_array_name = name ,
909
+ source_array_name = x . name ,
895
910
int_array_name = name_int ,
911
+ target_array_name = name ,
896
912
target_chunks = target_chunks ,
897
913
allowed_mem = spec .allowed_mem ,
898
914
reserved_mem = spec .reserved_mem ,
899
915
target_store = target_store ,
900
- temp_store = temp_store ,
901
916
storage_options = spec .storage_options ,
902
917
)
903
918
0 commit comments