HighLevelGraph for slicing chunks from an array-like according to a chunk pattern. If ``inline_array`` is True, this make a Blockwise layer of slicing tasks where the array-like is embedded into every task., If ``inline_array`` is False, this inserts the array-like as a standalone
(
arr, # Any array-like which supports slicing
chunks,
shape,
name,
getitem=getter,
lock=False,
asarray=True,
dtype=None,
inline_array=False,
)
| 266 | |
| 267 | |
| 268 | def graph_from_arraylike( |
| 269 | arr, # Any array-like which supports slicing |
| 270 | chunks, |
| 271 | shape, |
| 272 | name, |
| 273 | getitem=getter, |
| 274 | lock=False, |
| 275 | asarray=True, |
| 276 | dtype=None, |
| 277 | inline_array=False, |
| 278 | ) -> HighLevelGraph: |
| 279 | """ |
| 280 | HighLevelGraph for slicing chunks from an array-like according to a chunk pattern. |
| 281 | |
| 282 | If ``inline_array`` is True, this make a Blockwise layer of slicing tasks where the |
| 283 | array-like is embedded into every task., |
| 284 | |
| 285 | If ``inline_array`` is False, this inserts the array-like as a standalone value in |
| 286 | a MaterializedLayer, then generates a Blockwise layer of slicing tasks that refer |
| 287 | to it. |
| 288 | |
| 289 | >>> dict(graph_from_arraylike(arr, chunks=(2, 3), shape=(4, 6), name="X", inline_array=True)) # doctest: +SKIP |
| 290 | {(arr, 0, 0): (getter, arr, (slice(0, 2), slice(0, 3))), |
| 291 | (arr, 1, 0): (getter, arr, (slice(2, 4), slice(0, 3))), |
| 292 | (arr, 1, 1): (getter, arr, (slice(2, 4), slice(3, 6))), |
| 293 | (arr, 0, 1): (getter, arr, (slice(0, 2), slice(3, 6)))} |
| 294 | |
| 295 | >>> dict( # doctest: +SKIP |
| 296 | graph_from_arraylike(arr, chunks=((2, 2), (3, 3)), shape=(4,6), name="X", inline_array=False) |
| 297 | ) |
| 298 | {"original-X": arr, |
| 299 | ('X', 0, 0): (getter, 'original-X', (slice(0, 2), slice(0, 3))), |
| 300 | ('X', 1, 0): (getter, 'original-X', (slice(2, 4), slice(0, 3))), |
| 301 | ('X', 1, 1): (getter, 'original-X', (slice(2, 4), slice(3, 6))), |
| 302 | ('X', 0, 1): (getter, 'original-X', (slice(0, 2), slice(3, 6)))} |
| 303 | """ |
| 304 | chunks = normalize_chunks(chunks, shape, dtype=dtype) |
| 305 | out_ind = tuple(range(len(shape))) |
| 306 | |
| 307 | if ( |
| 308 | has_keyword(getitem, "asarray") |
| 309 | and has_keyword(getitem, "lock") |
| 310 | and (not asarray or lock) |
| 311 | ): |
| 312 | kwargs = {"asarray": asarray, "lock": lock} |
| 313 | else: |
| 314 | # Common case, drop extra parameters |
| 315 | kwargs = {} |
| 316 | |
| 317 | if inline_array: |
| 318 | layer = core_blockwise( |
| 319 | getitem, |
| 320 | name, |
| 321 | out_ind, |
| 322 | arr, |
| 323 | None, |
| 324 | ArraySliceDep(chunks), |
| 325 | out_ind, |