1717from cubed .backend_array_api import IS_IMMUTABLE_ARRAY , numpy_array_to_backend_array
1818from cubed .backend_array_api import namespace as nxp
1919from 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
2121from cubed .primitive .blockwise import blockwise as primitive_blockwise
2222from cubed .primitive .blockwise import general_blockwise as primitive_general_blockwise
2323from cubed .primitive .memory import get_buffer_copies
2424from cubed .primitive .rechunk import rechunk as primitive_rechunk
2525from cubed .spec import spec_from_config
2626from cubed .storage .backend import open_backend_array
27+ from cubed .storage .zarr import lazy_zarr_array
2728from cubed .types import T_RegularChunks , T_Shape
2829from cubed .utils import (
2930 array_memory ,
@@ -157,6 +158,14 @@ def store(sources: Union["Array", Sequence["Array"]], targets, executor=None, **
157158 for source , target in zip (sources , targets ):
158159 identity = lambda a : a
159160 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+ )
160169 array = blockwise (
161170 identity ,
162171 ind ,
@@ -192,6 +201,14 @@ def to_zarr(x: "Array", store, path=None, executor=None, **kwargs):
192201 # by map fusion (if it was produced with a blockwise operation).
193202 identity = lambda a : a
194203 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+ )
195212 out = blockwise (
196213 identity ,
197214 ind ,
@@ -200,7 +217,6 @@ def to_zarr(x: "Array", store, path=None, executor=None, **kwargs):
200217 dtype = x .dtype ,
201218 align_arrays = False ,
202219 target_store = store ,
203- target_path = path ,
204220 )
205221 out .compute (executor = executor , _return_in_memory_array = False , ** kwargs )
206222
@@ -298,7 +314,7 @@ def blockwise(
298314 spec = check_array_specs (arrays )
299315 buffer_copies = get_buffer_copies (spec )
300316 if target_store is None :
301- target_store = new_temp_path ( name = name , spec = spec )
317+ target_store = context_dir_path ( spec = spec )
302318 op = primitive_blockwise (
303319 func ,
304320 out_ind ,
@@ -452,14 +468,14 @@ def _general_blockwise(
452468 if isinstance (target_stores , list ): # multiple outputs
453469 name = [gensym () for _ in range (len (target_stores ))]
454470 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
457473 ]
458474 target_names = name
459475 else : # single output
460476 name = gensym ()
461477 if target_stores is None :
462- target_stores = [new_temp_path ( name = name , spec = spec )]
478+ target_stores = [context_dir_path ( spec = spec )]
463479 target_names = [name ]
464480
465481 op = primitive_general_blockwise (
@@ -886,18 +902,17 @@ def rechunk(x, chunks, *, target_store=None, min_mem=None, use_new_impl=True):
886902 name = gensym ()
887903 spec = x .spec
888904 if target_store is None :
889- target_store = new_temp_path ( name = name , spec = spec )
905+ target_store = context_dir_path ( spec = spec )
890906 name_int = f"{ name } -int"
891- temp_store = new_temp_path (name = name_int , spec = spec )
892907 ops = primitive_rechunk (
893908 x ._zarray ,
894- source_array_name = name ,
909+ source_array_name = x . name ,
895910 int_array_name = name_int ,
911+ target_array_name = name ,
896912 target_chunks = target_chunks ,
897913 allowed_mem = spec .allowed_mem ,
898914 reserved_mem = spec .reserved_mem ,
899915 target_store = target_store ,
900- temp_store = temp_store ,
901916 storage_options = spec .storage_options ,
902917 )
903918
0 commit comments