Skip to content
fn

imag

→Tensor
imag(input: Tensor)

Implementing kernel

C++ engine symbols that back this Python API.

Imaginary part of a complex tensor.

Returns the imaginary component of a complex input 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.

Parameters

inputTensor
Complex input tensor.

Returns

Tensor

A view with the same shape as input.

Raises

NotImplementedError
input is not complex: a real tensor has no imaginary part to view (a RuntimeError too, as the reference raises).

Notes

Mathematical definition:

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

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

Examples

>>> import lucid
>>> z = lucid.tensor([1 + 2j, 3 - 1j])
>>> lucid.imag(z)
tensor([2., -1.])