qml.math.is_real_obj_or_close

is_real_obj_or_close(obj)[source]

Convert an array to its real part if it is close to being real-valued, and afterwards return whether the resulting data type is real.

Parameters:

obj (array) – Array to check for being (close to) real.

Returns:

Whether the array obj, after potentially converting it to a real matrix, has a real data type. This is obtained by checking whether the data type name starts with "complex" and returning the negated result of this.

Return type:

bool

>>> x = jnp.array(0.4)
>>> qml.math.is_real_obj_or_close(x)
True
>>> x = tf.Variable(0.4+0.2j)
>>> qml.math.is_real_obj_or_close(x)
False
>>> x = torch.tensor(0.4+1e-13j)
>>> qml.math.is_real_obj_or_close(x)
True

Default absolute and relative tolerances of qml.math.allclose are used to determine whether the input is close to real-valued.