Skip to content
fn

unflatten_op

→TensorImplPtr
int unflatten_op(const int & a, int dim, const int & sizes)

Python wrappers

Public Python APIs implemented by this engine symbol.

Inverse of flatten — split dim into sizes.

Composite over reshape_op. The product of sizes must equal a.shape[dim]; the surrounding axes are preserved verbatim. Pure view operation when the input is contiguous; gradient flows through ReshapeBackward.

Math

Let a have shape (s0,…,sd−1,sd,sd+1,…)(s_0, \ldots, s_{d-1}, s_d, s_{d+1}, \ldots) and sizes =(m0,…,mk−1)= (m_0, \ldots, m_{k-1}) with ∏imi=sd\prod_i m_i = s_d. Then the output has shape

(s0,…,sd−1,m0,…,mk−1,sd+1,…) (s_0, \ldots, s_{d-1}, m_0, \ldots, m_{k-1}, s_{d+1}, \ldots)

See Also

reshape_op — the underlying primitive operates on the full shape.

Parameters

aTensorImplPtr
Source tensor of rank ≥1\ge 1.
dimint
Axis to expand. Negative values wrap modulo a.ndim.
sizesShape
Replacement extents. Their product must equal a.shape[dim].

Returns

TensorImplPtr

Reshaped tensor whose total numel matches a.

Raises

Failure
If a is null or ∏sizes≠a.shape[dim]\prod \mathrm{sizes} \ne \mathrm{a.shape}[\mathrm{dim}].
IndexError
If dim is out of range.