Skip to content
fn

real

→Tensor
real(input: Tensor)

Implementing kernel

C++ engine symbols that back this Python API.

Real part of a complex tensor.

For a complex input, returns its real component as a real tensor of the matching precision that is a view of the input's storage — writing into it changes the input, on Metal as on the CPU. A real input is its own real part and is returned itself: lucid.real(x) is x.

Parameters

inputTensor
Input tensor, complex or real.

Returns

Tensor

A view with the same shape as input, or input itself.

Notes

Mathematical definition:

outi=Re(inputi)\text{out}_i = \mathrm{Re}(\text{input}_i)

Gradient flows back as the real part of the upstream cotangent.

Examples

>>> import lucid
>>> z = lucid.tensor([1 + 2j, 3 - 1j])
>>> lucid.real(z)
tensor([1., 3.])
>>> x = lucid.tensor([1.0, 2.0])
>>> lucid.real(x) is x
True