Create a Blockwise symbolic mutable mapping Applies a function, ``func``, across blocks from many different input collections. We arrange the pattern with which those blocks interact with sets of matching indices. E.g.:: blockwise(func, 'z', 'i', 'x', 'i', 'y', 'i') yiel
(
func,
output,
output_indices,
*arrind_pairs,
numblocks,
concatenate=None,
new_axes=None,
dependencies=(),
_data_producer=False,
**kwargs,
)
| 225 | |
| 226 | |
| 227 | def blockwise( |
| 228 | func, |
| 229 | output, |
| 230 | output_indices, |
| 231 | *arrind_pairs, |
| 232 | numblocks, |
| 233 | concatenate=None, |
| 234 | new_axes=None, |
| 235 | dependencies=(), |
| 236 | _data_producer=False, |
| 237 | **kwargs, |
| 238 | ): |
| 239 | """Create a Blockwise symbolic mutable mapping |
| 240 | |
| 241 | Applies a function, ``func``, across blocks from many different input |
| 242 | collections. We arrange the pattern with which those blocks interact with |
| 243 | sets of matching indices. E.g.:: |
| 244 | |
| 245 | blockwise(func, 'z', 'i', 'x', 'i', 'y', 'i') |
| 246 | |
| 247 | yield an embarrassingly parallel communication pattern and is read as |
| 248 | |
| 249 | $$ z_i = func(x_i, y_i) $$ |
| 250 | |
| 251 | More complex patterns may emerge, including multiple indices:: |
| 252 | |
| 253 | blockwise(func, 'z', 'ij', 'x', 'ij', 'y', 'ji') |
| 254 | |
| 255 | $$ z_{ij} = func(x_{ij}, y_{ji}) $$ |
| 256 | |
| 257 | Indices missing in the output but present in the inputs results in many |
| 258 | inputs being sent to one function (see examples). |
| 259 | |
| 260 | Examples |
| 261 | -------- |
| 262 | Simple embarrassing map operation |
| 263 | |
| 264 | >>> def inc(x): |
| 265 | ... return x + 1 |
| 266 | >>> dict( |
| 267 | ... blockwise( |
| 268 | ... inc, |
| 269 | ... 'z', 'ij', |
| 270 | ... 'x', 'ij', |
| 271 | ... numblocks={'x': (2, 2)} |
| 272 | ... ) |
| 273 | ... ) # doctest: +NORMALIZE_WHITESPACE |
| 274 | {('z', 0, 0): <Task ('z', 0, 0) inc(TaskRef(('x', 0, 0)))>, |
| 275 | ('z', 0, 1): <Task ('z', 0, 1) inc(TaskRef(('x', 0, 1)))>, |
| 276 | ('z', 1, 0): <Task ('z', 1, 0) inc(TaskRef(('x', 1, 0)))>, |
| 277 | ('z', 1, 1): <Task ('z', 1, 1) inc(TaskRef(('x', 1, 1)))>} |
| 278 | |
| 279 | Simple operation on two datasets x and y |
| 280 | |
| 281 | >>> def add(x, y): |
| 282 | ... return x + y |
| 283 | >>> dict( |
| 284 | ... blockwise( |
no test coverage detected
searching dependent graphs…