Skip to content
fn

stack_op

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

Python wrappers

Public Python APIs implemented by this engine symbol.

Stack a list of same-shape tensors along a new axis.

Inserts a fresh size-len(xs) dimension at position axis of the output, increasing the rank by one. All inputs must have identical shape, dtype, and device.

Shape

Inputs of shape (D_0, ..., D_{ndim-1}) stacked along axis = k yield output shape (D_0, ..., D_{k-1}, len(xs), D_k, ..., D_{ndim-1}).

See Also

concatenate_op, unbind_op.

Parameters

xsvector<TensorImplPtr>
Non-empty list of tensors with identical shape, dtype, and device.
axisint
Insertion position for the new dimension. Supports negative indexing against the output rank ndim + 1 (so axis = -1 appends).

Returns

TensorImplPtr

Output tensor with rank ndim + 1 and a new dimension of size len(xs) inserted at axis.

Raises

ShapeMismatch, DtypeMismatch, DeviceMismatch
On any disagreement between inputs.

Notes

Backward slices each size-1 hyperplane along the new axis and squeezes it to recover the gradient for the corresponding input. Schema name "stack", AmpPolicy::KeepInput.