colour.utilities.set_default_float_dtype#

colour.utilities.set_default_float_dtype(dtype: typing.Type[<sphinx.util.inspect.TypeAliasForwardRef object at 0x7fa3184c2850>] = DEFAULT_FLOAT_DTYPE) None[source]#

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

Parameters

dtype (Type[<sphinx.util.inspect.TypeAliasForwardRef object at 0x7fa31969ab10>]) – numpy.dtype to set colour.constant.DEFAULT_FLOAT_DTYPE 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')