@@ -44,8 +44,8 @@ class BlockwiseSpec:
44
44
45
45
Attributes
46
46
----------
47
- block_function : Callable
48
- A function that maps an output chunk index to one or more input chunk indexes .
47
+ key_function : Callable
48
+ A function that maps an output chunk key to one or more input chunk keys .
49
49
function : Callable
50
50
A function that maps input chunks to an output chunk.
51
51
function_nargs: int
@@ -58,28 +58,29 @@ class BlockwiseSpec:
58
58
Write proxy with an ``array`` attribute that supports ``__setitem__``.
59
59
"""
60
60
61
- block_function : Callable [..., Any ]
61
+ key_function : Callable [..., Any ]
62
62
function : Callable [..., Any ]
63
63
function_nargs : int
64
64
num_input_blocks : Tuple [int , ...]
65
65
reads_map : Dict [str , CubedArrayProxy ]
66
66
write : CubedArrayProxy
67
67
68
68
69
- def apply_blockwise (out_key : List [int ], * , config : BlockwiseSpec ) -> None :
69
+ def apply_blockwise (out_coords : List [int ], * , config : BlockwiseSpec ) -> None :
70
70
"""Stage function for blockwise."""
71
71
# lithops needs params to be lists not tuples, so convert back
72
- out_key_tuple = tuple (out_key )
72
+ out_coords_tuple = tuple (out_coords )
73
73
out_chunk_key = key_to_slices (
74
- out_key_tuple , config .write .array , config .write .chunks
74
+ out_coords_tuple , config .write .array , config .write .chunks
75
75
)
76
76
77
77
# get array chunks for input keys, preserving any nested list structure
78
78
args = []
79
79
get_chunk_config = partial (get_chunk , config = config )
80
- name_chunk_inds = config .block_function (("out" ,) + out_key_tuple )
81
- for name_chunk_ind in name_chunk_inds :
82
- arg = map_nested (get_chunk_config , name_chunk_ind )
80
+ out_key = ("out" ,) + out_coords_tuple # array name is ignored by key_function
81
+ in_keys = config .key_function (out_key )
82
+ for in_key in in_keys :
83
+ arg = map_nested (get_chunk_config , in_key )
83
84
args .append (arg )
84
85
85
86
result = config .function (* args )
@@ -100,13 +101,13 @@ def key_to_slices(
100
101
return get_item (chunks , key )
101
102
102
103
103
- def get_chunk (name_chunk_ind , config ):
104
+ def get_chunk (in_key , config ):
104
105
"""Read a chunk from the named array"""
105
- name = name_chunk_ind [0 ]
106
- chunk_ind = name_chunk_ind [1 :]
106
+ name = in_key [0 ]
107
+ in_coords = in_key [1 :]
107
108
arr = config .reads_map [name ].open ()
108
- chunk_key = key_to_slices (chunk_ind , arr )
109
- arg = arr [chunk_key ]
109
+ selection = key_to_slices (in_coords , arr )
110
+ arg = arr [selection ]
110
111
arg = numpy_array_to_backend_array (arg )
111
112
return arg
112
113
@@ -188,7 +189,7 @@ def blockwise(
188
189
for name , ind in zip (array_names , inds ):
189
190
argindsstr .extend ((name , ind ))
190
191
191
- block_function = make_blockwise_function_flattened (
192
+ key_function = make_blockwise_key_function_flattened (
192
193
func ,
193
194
out_name or "out" ,
194
195
out_ind ,
@@ -199,7 +200,7 @@ def blockwise(
199
200
200
201
return general_blockwise (
201
202
func ,
202
- block_function ,
203
+ key_function ,
203
204
* arrays ,
204
205
allowed_mem = allowed_mem ,
205
206
reserved_mem = reserved_mem ,
@@ -219,7 +220,7 @@ def blockwise(
219
220
220
221
def general_blockwise (
221
222
func : Callable [..., Any ],
222
- block_function : Callable [..., Any ],
223
+ key_function : Callable [..., Any ],
223
224
* arrays : Any ,
224
225
allowed_mem : int ,
225
226
reserved_mem : int ,
@@ -242,8 +243,8 @@ def general_blockwise(
242
243
----------
243
244
func : callable
244
245
Function to apply to individual tuples of blocks
245
- block_function : callable
246
- A function that maps an output chunk index to one or more input chunk indexes .
246
+ key_function : callable
247
+ A function that maps an output chunk key to one or more input chunk keys .
247
248
*arrays : sequence of Array
248
249
The input arrays.
249
250
allowed_mem : int
@@ -291,7 +292,7 @@ def general_blockwise(
291
292
}
292
293
write_proxy = CubedArrayProxy (target_array , chunksize )
293
294
spec = BlockwiseSpec (
294
- block_function ,
295
+ key_function ,
295
296
func_with_kwargs ,
296
297
len (arrays ),
297
298
num_input_blocks ,
@@ -460,10 +461,8 @@ def fuse(
460
461
461
462
mappable = pipeline2 .mappable
462
463
463
- def fused_blockwise_func (out_key ):
464
- return pipeline1 .config .block_function (
465
- * pipeline2 .config .block_function (out_key )
466
- )
464
+ def fused_key_func (out_key ):
465
+ return pipeline1 .config .key_function (* pipeline2 .config .key_function (out_key ))
467
466
468
467
def fused_func (* args ):
469
468
return pipeline2 .config .function (pipeline1 .config .function (* args ))
@@ -476,7 +475,7 @@ def fused_func(*args):
476
475
for n in pipeline1 .config .num_input_blocks
477
476
)
478
477
spec = BlockwiseSpec (
479
- fused_blockwise_func ,
478
+ fused_key_func ,
480
479
fused_func ,
481
480
function_nargs ,
482
481
num_input_blocks ,
@@ -530,36 +529,36 @@ def fuse_multiple(
530
529
531
530
mappable = pipeline .mappable
532
531
533
- def apply_pipeline_block_func (pipeline , n_input_blocks , arg ):
532
+ def apply_pipeline_key_func (pipeline , n_input_blocks , arg ):
534
533
if pipeline is None :
535
534
return (arg ,)
536
535
if n_input_blocks == 1 :
537
536
assert isinstance (arg , tuple )
538
- return pipeline .config .block_function (arg )
537
+ return pipeline .config .key_function (arg )
539
538
else :
540
539
# more than one input block is being read from arg
541
540
assert isinstance (arg , (list , Iterator ))
542
541
if isinstance (arg , list ):
543
542
return tuple (
544
543
list (item )
545
- for item in zip (* (pipeline .config .block_function (a ) for a in arg ))
544
+ for item in zip (* (pipeline .config .key_function (a ) for a in arg ))
546
545
)
547
546
else :
548
547
# Return iterators to avoid materializing all array blocks at
549
548
# once.
550
549
return tuple (
551
550
iter (list (item ))
552
- for item in zip (* (pipeline .config .block_function (a ) for a in arg ))
551
+ for item in zip (* (pipeline .config .key_function (a ) for a in arg ))
553
552
)
554
553
555
- def fused_blockwise_func (out_key ):
554
+ def fused_key_func (out_key ):
556
555
# this will change when multiple outputs are supported
557
- args = pipeline .config .block_function (out_key )
556
+ args = pipeline .config .key_function (out_key )
558
557
# split all args to the fused function into groups, one for each predecessor function
559
558
func_args = tuple (
560
559
item
561
560
for i , (p , a ) in enumerate (zip (predecessor_pipelines , args ))
562
- for item in apply_pipeline_block_func (
561
+ for item in apply_pipeline_key_func (
563
562
p , pipeline .config .num_input_blocks [i ], a
564
563
)
565
564
)
@@ -602,7 +601,7 @@ def fused_func(*args):
602
601
read_proxies .update (p .config .reads_map )
603
602
write_proxy = pipeline .config .write
604
603
spec = BlockwiseSpec (
605
- fused_blockwise_func ,
604
+ fused_key_func ,
606
605
fused_func ,
607
606
fused_function_nargs ,
608
607
fused_num_input_blocks ,
@@ -643,10 +642,10 @@ def fused_func(*args):
643
642
)
644
643
645
644
646
- # blockwise functions
645
+ # blockwise key functions
647
646
648
647
649
- def make_blockwise_function (
648
+ def make_blockwise_key_function (
650
649
func : Callable [..., Any ],
651
650
output : str ,
652
651
out_indices : Sequence [Union [str , int ]],
@@ -675,7 +674,7 @@ def make_blockwise_function(
675
674
False ,
676
675
)
677
676
678
- def blockwise_fn (out_key ):
677
+ def key_function (out_key ):
679
678
out_coords = out_key [1 :]
680
679
681
680
# from Dask make_blockwise_graph
@@ -701,27 +700,27 @@ def blockwise_fn(out_key):
701
700
702
701
return val
703
702
704
- return blockwise_fn
703
+ return key_function
705
704
706
705
707
- def make_blockwise_function_flattened (
706
+ def make_blockwise_key_function_flattened (
708
707
func : Callable [..., Any ],
709
708
output : str ,
710
709
out_indices : Sequence [Union [str , int ]],
711
710
* arrind_pairs : Any ,
712
711
numblocks : Optional [Dict [str , Tuple [int , ...]]] = None ,
713
712
new_axes : Optional [Dict [int , int ]] = None ,
714
713
) -> Callable [[List [int ]], Any ]:
715
- # TODO: make this a part of make_blockwise_function ?
716
- blockwise_fn = make_blockwise_function (
714
+ # TODO: make this a part of make_blockwise_key_function ?
715
+ key_function = make_blockwise_key_function (
717
716
func , output , out_indices , * arrind_pairs , numblocks = numblocks , new_axes = new_axes
718
717
)
719
718
720
719
def blockwise_fn_flattened (out_key ):
721
- name_chunk_inds = blockwise_fn (out_key )[1 :] # drop function in position 0
720
+ in_keys = key_function (out_key )[1 :] # drop function in position 0
722
721
# flatten (nested) lists indicating contraction
723
- if isinstance (name_chunk_inds [0 ], list ):
724
- name_chunk_inds = list (flatten (name_chunk_inds ))
725
- return name_chunk_inds
722
+ if isinstance (in_keys [0 ], list ):
723
+ in_keys = list (flatten (in_keys ))
724
+ return in_keys
726
725
727
726
return blockwise_fn_flattened
0 commit comments