MCPcopy
hub / github.com/dask/dask / graph_from_arraylike

Function graph_from_arraylike

dask/array/core.py:267–352  ·  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

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…