default_dtype#

ivy.default_dtype(*, dtype=None, item=None, as_native=False)[source]#
Parameters:
  • item (Optional[Union[Array, NativeArray]], default: None) – Number or array for inferring the dtype.

  • dtype (Optional[Union[Dtype, str]], default: None) – The dtype to be returned.

  • as_native (bool, default: False) – Whether to return the dtype as native dtype.

Return type:

Union[Dtype, NativeDtype, str]

Returns:

Return dtype as native or ivy dtype if provided, else if item is given, return its dtype, otherwise return the global default dtype.

Examples

>>> ivy.default_dtype()
'float32'
>>> ivy.set_default_dtype(ivy.bool)
>>> ivy.default_dtype()
'bool'
>>> ivy.set_default_dtype(ivy.int16)
>>> ivy.default_dtype()
'int16'
>>> ivy.set_default_dtype(ivy.float64)
>>> ivy.default_dtype()
'float64'
>>> ivy.default_dtype(dtype="int32")
'int32'
>>> ivy.default_dtype(dtype=ivy.float16)
'float16'
>>> ivy.default_dtype(item=53.234)
'float64'
>>> ivy.default_dtype(item=[1, 2, 3])
'int32'
>>> x = ivy.array([5.2, 9.7], dtype="complex128")
>>> ivy.default_dtype(item=x)
'complex128'