fn

view

Tensor
view(input: Tensor, shape: int | Sequence[int] = ())
source

Return a view of input with a different shape.

The total number of elements must be preserved. Unlike reshape, view requires the input to be contiguous over the affected dims and never copies — if a view is not possible a runtime error is raised.

Parameters

inputTensor
Source tensor. Must be contiguous w.r.t. the requested layout.
shapeint or sequence of int= ()
Target shape. Exactly one entry may be -1 (auto-inferred).

Returns

Tensor

Tensor sharing storage with input.

Notes

Use view when zero-copy is part of the contract; use reshape when correctness should take precedence over layout assumptions.

Examples

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