MCPcopy
hub / github.com/dask/dask / _concatenate2

Function _concatenate2

dask/array/core.py:377–440  ·  view source on GitHub ↗

Recursively concatenate nested lists of arrays along axes Each entry in axes corresponds to each level of the nested list. The length of axes should correspond to the level of nesting of arrays. If axes is an empty list or tuple, return arrays, or arrays[0] if arrays is a list.

(arrays, axes=None)

Source from the content-addressed store, hash-verified

375
376
377def _concatenate2(arrays, axes=None):
378 """Recursively concatenate nested lists of arrays along axes
379
380 Each entry in axes corresponds to each level of the nested list. The
381 length of axes should correspond to the level of nesting of arrays.
382 If axes is an empty list or tuple, return arrays, or arrays[0] if
383 arrays is a list.
384
385 >>> x = np.array([[1, 2], [3, 4]])
386 >>> _concatenate2([x, x], axes=[0])
387 array([[1, 2],
388 [3, 4],
389 [1, 2],
390 [3, 4]])
391
392 >>> _concatenate2([x, x], axes=[1])
393 array([[1, 2, 1, 2],
394 [3, 4, 3, 4]])
395
396 >>> _concatenate2([[x, x], [x, x]], axes=[0, 1])
397 array([[1, 2, 1, 2],
398 [3, 4, 3, 4],
399 [1, 2, 1, 2],
400 [3, 4, 3, 4]])
401
402 Supports Iterators
403 >>> _concatenate2(iter([x, x]), axes=[1])
404 array([[1, 2, 1, 2],
405 [3, 4, 3, 4]])
406
407 Special Case
408 >>> _concatenate2([x, x], axes=())
409 array([[1, 2],
410 [3, 4]])
411 """
412 if axes is None:
413 axes = []
414
415 if axes == ():
416 if isinstance(arrays, list):
417 return arrays[0]
418 else:
419 return arrays
420
421 if isinstance(arrays, Iterator):
422 arrays = list(arrays)
423 if not isinstance(arrays, (list, tuple)):
424 return arrays
425 if len(axes) > 1:
426 arrays = [_concatenate2(a, axes=axes[1:]) for a in arrays]
427 concatenate = concatenate_lookup.dispatch(
428 type(max(arrays, key=lambda x: getattr(x, "__array_priority__", 0)))
429 )
430 if isinstance(arrays[0], dict):
431 # Handle concatenation of `dict`s, used as a replacement for structured
432 # arrays when that's not supported by the array library (e.g., CuPy).
433 keys = list(arrays[0].keys())
434 assert all(list(a.keys()) == keys for a in arrays)

Callers 5

mean_combineFunction · 0.90
mean_aggFunction · 0.90
moment_combineFunction · 0.90
moment_aggFunction · 0.90
concatenate3Function · 0.85

Calls 5

maxFunction · 0.90
allFunction · 0.90
concatenateFunction · 0.70
dispatchMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…