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

Function graph_from_arraylike

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

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