ttnn.is_real

ttnn.is_real(input_tensor: ComplexTensor, *, memory_config: ttnn.MemoryConfig = None) ttnn.Tensor

Returns boolean tensor if value of input_tensor is real.

Parameters:

input_tensor (ComplexTensor) – the input tensor.

Keyword Arguments:

memory_config (ttnn.MemoryConfig, optional) – Memory configuration for the operation. Defaults to None.

Returns:

ttnn.Tensor – the output tensor.

Example

# Create a complex tensor with only real part
real_part = torch.rand([1, 1, 32, 32], dtype=torch.bfloat16)
imag_part = torch.zeros([1, 1, 32, 32], dtype=torch.bfloat16)
tensor = ttnn.complex_tensor(
    ttnn.Tensor(real_part, ttnn.bfloat16).to(ttnn.TILE_LAYOUT).to(device),
    ttnn.Tensor(imag_part, ttnn.bfloat16).to(ttnn.TILE_LAYOUT).to(device),
)

# Check if tensor values are purely real
output = ttnn.is_real(tensor, memory_config=ttnn.DRAM_MEMORY_CONFIG)
logger.info(f"Is real: {output}")