result_type#

ivy.result_type(*arrays_and_dtypes)[source]#

Return the dtype that results from applying the type promotion rules (see type-promotion) to the arguments.

If provided mixed dtypes (e.g., integer and floating-point), the returned dtype will be implementation-specific.

Parameters:

arrays_and_dtypes (Union[Array, NativeArray, Dtype]) – an arbitrary number of input arrays and/or dtypes.

Return type:

Dtype

Returns:

ret – the dtype resulting from an operation involving the input arrays and dtypes.

This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.

Examples

With ivy.Array input:

>>> x = ivy.array([3, 4, 5])
>>> y = ivy.array([3., 4., 5.])
>>> d = ivy.result_type(x, y)
>>> print(d)
float32

With ivy.Dtype input:

>>> d = ivy.result_type(ivy.uint8, ivy.uint64)
>>> print(d)
uint64

With ivy.Container input:

>>> x = ivy.Container(a = ivy.array([3, 4, 5]))
>>> d = x.a.dtype
>>> print(d)
int32
>>> x = ivy.Container(a = ivy.array([3, 4, 5]))
>>> d = ivy.result_type(x, ivy.float64)
>>> print(d)
{
    a: float64
}
Array.result_type(self, *arrays_and_dtypes)[source]#

ivy.Array instance method variant of ivy.result_type. This method simply wraps the function, and so the docstring for ivy.result_type also applies to this method with minimal changes.

Parameters:
  • self (Array) – input array from which to cast.

  • arrays_and_dtypes (Union[Array, NativeArray, Dtype]) – an arbitrary number of input arrays and/or dtypes.

Return type:

Dtype

Returns:

ret – the dtype resulting from an operation involving the input arrays and dtypes.

Examples

>>> x = ivy.array([0, 1, 2])
>>> print(x.dtype)
int32
>>> x.result_type(ivy.float64)
<dtype:'float64'>
Container.result_type(self, *arrays_and_dtypes, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#

ivy.Container instance method variant of ivy.result_type. This method simply wraps the function, and so the docstring for ivy.result_type also applies to this method with minimal changes.

Parameters:
  • self (Container) – input container from which to cast.

  • arrays_and_dtypes (Container) – an arbitrary number of input arrays and/or dtypes.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

Return type:

Container

Returns:

ret – the dtype resulting from an operation involving the input arrays and dtypes.

Examples

>>> x = ivy.Container(a = ivy.array([3, 3, 3]))
>>> print(x.a.dtype)
int32
>>> y = ivy.Container(b = ivy.float64)
>>> print(x.result_type(y))
{
    a: {
        b: float64
    }
}