Skip to content
fn

view

→Tensor
view(input: Tensor, size: _int | Sequence[_int])

Implementing kernel

C++ engine symbols that back this Python API.

Return input with a different shape.

The total number of elements must be preserved.

On the CPU a dense input is viewed, not copied: the result reads the same buffer, so an in-place write to either reaches the other. On metal the result is a copy.

Parameters

inputTensor
Source tensor.
sizeint or sequence of int
Target shape. Exactly one entry may be -1 (auto-inferred).

Returns

Tensor

input under the new shape — a view on the CPU, a copy on metal.

Notes

view and reshape behave the same, and neither ever refuses a layout: a CPU input that is not contiguous — a transpose, a column slice — is copied, unless the new shape only adds or drops size-1 axes.

Examples

>>> import lucid
>>> x = lucid.arange(12)
>>> lucid.view(x, (3, 4)).shape
(3, 4)