fn

view_as_complex

Tensor
view_as_complex(input: Tensor)
source

Reinterpret a real tensor with a trailing pair axis as a complex tensor.

Inverse of view_as_real. Given an F32 input of shape (,2)(\dots, 2), returns a complex64 tensor of shape ()(\dots) whose last axis is consumed.

Parameters

inputTensor
Real F32 tensor whose final dimension has size 2; the two components are interpreted as (real, imag).

Returns

Tensor

complex64 tensor of shape input.shape[:-1].

Raises

ValueError
If input.ndim < 1 or the last axis does not have size 2.

Notes

Conceptually:

(ai,bi)    zi=ai+ibi.(a_i, b_i) \;\mapsto\; z_i = a_i + i\,b_i.

Same copy / aliasing caveat as view_as_real — implemented as a materialised gather, not a zero-copy reinterpret.

Examples

>>> import lucid
>>> r = lucid.tensor([[1.0, 2.0], [3.0, 4.0]])
>>> lucid.view_as_complex(r)
Tensor([1.+2.j, 3.+4.j])