MCPcopy Create free account
hub / github.com/dask/dask / graph_from_arraylike

Function graph_from_arraylike

dask/array/core.py:268–353  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

266
267
268def 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,

Callers 9

test_chunked_dot_productFunction · 0.90
test_ArrayFunction · 0.90
test_stackFunction · 0.90
test_concatenateFunction · 0.90
_layerMethod · 0.90
from_arrayFunction · 0.85

Calls 8

has_keywordFunction · 0.90
ArraySliceDepClass · 0.90
MaterializedLayerClass · 0.90
TaskRefClass · 0.90
HighLevelGraphClass · 0.90
normalize_chunksFunction · 0.85
setClass · 0.85
from_collectionsMethod · 0.80

Tested by 7

test_chunked_dot_productFunction · 0.72
test_ArrayFunction · 0.72
test_stackFunction · 0.72
test_concatenateFunction · 0.72