Skip to content
fn

flatten_op

→TensorImplPtr
int flatten_op(const int & a, int start_axis, int end_axis)

Python wrappers

Public Python APIs implemented by this engine symbol.

Collapse a contiguous range of axes into a single dimension.

Folds dimensions [start_axis, end_axis] (inclusive on both ends) into one axis whose size is the product of the collapsed dimensions. Delegates to reshape_op after computing the flattened size, so the input must be contiguous along the affected range.

Shape

(D_0, ..., D_{s-1}, D_s, ..., D_e, D_{e+1}, ..., D_{n-1}) becomes (D_0, ..., D_{s-1}, \prod_{d=s}^{e} D_d, D_{e+1}, ..., D_{n-1}) with s = start_axis and e = end_axis.

See Also

reshape_op, squeeze_all_op.

Parameters

aTensorImplPtr
Input tensor.
start_axisint
First axis in the range to collapse. Supports negative indexing.
end_axisint
Last axis in the range (inclusive). Supports negative indexing. Must satisfy start_axis <= end_axis after normalisation.

Returns

TensorImplPtr

Tensor with rank ndim - (end_axis - start_axis) and a flattened dimension of size \prod_{d=start_axis}^{end_axis} a.shape[d] at position start_axis.

Raises

ShapeMismatch
If the collapsed range cannot be reshape-merged because of non-contiguous strides.