MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / concat

Function concat

imperative/python/megengine/functional/tensor.py:564–594  ·  view source on GitHub ↗

r"""Concat some tensors Args: inps: input tensors to concat. axis: over which dimension the tensors are concatenated. Default: 0 device: which device output will be. Default: None Returns: output tensor. Examples: >>> import numpy as np

(inps: Iterable[Tensor], axis: int = 0, device=None)

Source from the content-addressed store, hash-verified

562
563
564def concat(inps: Iterable[Tensor], axis: int = 0, device=None) -> Tensor:
565 r"""Concat some tensors
566
567 Args:
568 inps: input tensors to concat.
569 axis: over which dimension the tensors are concatenated. Default: 0
570 device: which device output will be. Default: None
571
572 Returns:
573 output tensor.
574
575 Examples:
576 >>> import numpy as np
577 >>> data1 = Tensor(np.arange(0, 6, dtype=np.float32).reshape((2, 3)))
578 >>> data2 = Tensor(np.arange(6, 12, dtype=np.float32).reshape((2, 3)))
579 >>> out = F.concat([data1, data2])
580 >>> out.numpy()
581 array([[ 0., 1., 2.],
582 [ 3., 4., 5.],
583 [ 6., 7., 8.],
584 [ 9., 10., 11.]], dtype=float32)
585 """
586 if len(inps) == 1:
587 # if we return inps[0] directly, then the grad manager capture nothing
588 return copy(inps[0], device)
589
590 if device is None:
591 device = get_device(inps)
592 device = as_device(device)
593 (result,) = apply(builtin.Concat(axis=axis, comp_node=device.to_c()), *inps)
594 return result
595
596
597def stack(inps, axis=0, device=None):

Callers 5

_merge_masksFunction · 0.70
get_dsizeFunction · 0.70
interpolateFunction · 0.70
tileFunction · 0.70
rollFunction · 0.70

Calls 6

get_deviceFunction · 0.85
as_deviceFunction · 0.85
ConcatMethod · 0.80
to_cMethod · 0.80
copyFunction · 0.70
applyFunction · 0.50

Tested by

no test coverage detected