Skip to content
fn

concatenate_op

→TensorImplPtr
int concatenate_op(const int & xs, int axis)

Python wrappers

Public Python APIs implemented by this engine symbol.

Concatenate a sequence of tensors along an existing axis.

All inputs must share dtype, device, and rank; every dimension except axis must agree exactly. The output reuses freshly allocated storage — no input buffer is aliased — and the autograd node saves only per-input shapes so backward can split the gradient back into one slice per input.

Math

y[…, k, …]=x[…, k−∑j<iNj, …](i)y_{[\ldots,\, k,\, \ldots]} = x^{(i)}_{[\ldots,\, k - \sum_{j<i} N_j,\, \ldots]} where ii is the unique input index satisfying ∑j<iNj≤k<∑j≤iNj\sum_{j<i} N_j \le k < \sum_{j \le i} N_j.

Shape

Inputs of shape (D_0, ..., D_{axis-1}, N_i, D_{axis+1}, ..., D_{ndim-1}) produce output of shape (D_0, ..., D_{axis-1}, \sum_i N_i, D_{axis+1}, ..., D_{ndim-1}).

See Also

stack_op, split_op, hstack_op, vstack_op.

Parameters

xsvector<TensorImplPtr>
Non-empty list of input tensors with matching dtype, device, and rank. All dimensions except axis must be identical across inputs.
axisint
Axis along which to concatenate. Supports negative indexing (wrapped to axis + ndim). Must satisfy -ndim <= axis < ndim.

Returns

TensorImplPtr

Output tensor of shape (..., \sum_i N_i, ...) where the axis dimension is the sum of each input's axis dimension.

Raises

DtypeMismatch
If inputs disagree on dtype.
DeviceMismatch
If inputs reside on different devices.
ShapeMismatch
If inputs disagree on any non-concat dimension, or differ in rank.

Notes

Backward slices the incoming gradient back into per-input pieces using the saved size of each input along axis; the schema is "concatenate" with AmpPolicy::KeepInput.