colour.utilities.set_default_float_dtype#

colour.utilities.set_default_float_dtype(dtype: Type[DTypeFloat] = DTYPE_FLOAT_DEFAULT) None[source]#

Set Colour default numpy.floating precision by setting colour.constant.DTYPE_FLOAT_DEFAULT attribute with given numpy.dtype wherever the attribute is imported.

Parameters:

dtype (Type[DTypeFloat]) – numpy.dtype to set colour.constant.DTYPE_FLOAT_DEFAULT with.

Return type:

None

Warning

Changing float precision might result in various Colour functionality breaking entirely: numpy/numpy#6860. With great power comes great responsibility.

Notes

  • It is possible to define the float precision at import time by setting the COLOUR_SCIENCE__DEFAULT_FLOAT_DTYPE environment variable, for example set COLOUR_SCIENCE__DEFAULT_FLOAT_DTYPE=float32.

  • Some definition returning a single-scalar ndarray might not honour the given float precision: numpy/numpy#16353

Examples

>>> as_float_array(np.ones(3)).dtype
dtype('float64')
>>> set_default_float_dtype(np.float16)  
>>> as_float_array(np.ones(3)).dtype  
dtype('float16')
>>> set_default_float_dtype(np.float64)
>>> as_float_array(np.ones(3)).dtype
dtype('float64')