real_dtype

odl.util.utility.real_dtype(dtype, default=None)[source]

Return the real counterpart of dtype if existing.

Parameters
dtype :

Real or complex floating point data type. It can be given in any way the numpy.dtype constructor understands.

default :

Object to be returned if no real counterpart is found for dtype, except for None, in which case an error is raised.

Returns
real_dtypenumpy.dtype

The real counterpart of dtype.

Raises
ValueError

if there is no real counterpart to the given data type and default == None.

See also

complex_dtype

Examples

Convert scalar dtypes:

>>> real_dtype(complex)
dtype('float64')
>>> real_dtype('complex64')
dtype('float32')
>>> real_dtype(float)
dtype('float64')

Dtypes with shape are also supported:

>>> real_dtype(np.dtype((complex, (3,))))
dtype(('<f8', (3,)))
>>> real_dtype(('complex64', (3,)))
dtype(('<f4', (3,)))