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

Function _concatenate2

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

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