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

Function _concatenate2

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

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