Implementing kernel
C++ engine symbols that back this Python API.Collapse a contiguous range of dimensions into a single dim.
All dimensions from start_dim to end_dim (inclusive) are
merged into one, preserving row-major order of the original elements.
Often used to feed a feature map into a fully-connected head.
Parameters
inputTensorSource tensor.
start_dimint= 0First dimension to flatten.
end_dimint= -1Last dimension to flatten (inclusive).
Returns
TensorTensor whose rank is reduced by end_dim - start_dim.
Notes
The merged dim has size
. The
result is a view of input on the CPU — an in-place write to
either reaches the other — and a copy on metal.
Examples
>>> import lucid
>>> x = lucid.zeros(2, 3, 4)
>>> lucid.flatten(x).shape
(24,)
>>> lucid.flatten(x, 1, 2).shape
(2, 12)