Data type#
- class ivy.data_classes.container.data_type._ContainerWithDataTypes(dict_in=None, queues=None, queue_load_sizes=None, container_combine_method='list_join', queue_timeout=None, print_limit=10, key_length_limit=None, print_indent=4, print_line_spacing=0, ivyh=None, default_key_color='green', keyword_color_dict=None, rebuild_child_containers=False, types_to_iteratively_nest=None, alphabetical_keys=True, dynamic_backend=None, build_callable=False, **kwargs)[source]#
Bases:
ContainerBase
- _abc_impl = <_abc._abc_data object>#
- static _static_astype(x, dtype, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, copy=True, out=None)[source]#
Copy an array to a specified data type irrespective of type- promotion rules.
Casting floating-point
NaN
andinfinity
values to integral data types is not specified and is implementation-dependent.When casting a boolean input array to a numeric data type, a value of
True
must cast to a numeric value equal to1
, and a value ofFalse
must cast to a numeric value equal to0
.When casting a numeric input array to
bool
, a value of0
must cast toFalse
, and a non-zero value must cast toTrue
.- Parameters:
x (
Container
) – array to cast.dtype (
Union
[Dtype
,Container
]) – desired data type.copy (
Union
[bool
,Container
], default:True
) – specifies whether to copy an array when the specifieddtype
matches the data type of the input arrayx
. IfTrue
, a newly allocated array must always be returned. IfFalse
and the specifieddtype
matches the data type of the input array, the input array must be returned; otherwise, a newly allocated must be returned. Default:True
.out (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – an array having the specified data type. The returned array must have the same shape as
x
.
Examples
>>> c = ivy.Container(a=ivy.array([False,True,True]), ... b=ivy.array([3.14, 2.718, 1.618])) >>> ivy.Container.static_astype(c, ivy.int32) { a: ivy.array([0, 1, 1]), b: ivy.array([3, 2, 1]) }
- static _static_broadcast_arrays(*arrays, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container static method variant of ivy.broadcast_arrays. This method simply wraps the function, and so the docstring for ivy.broadcast_arrays also applies to this method with minimal changes.
- Parameters:
arrays (
Union
[Container
,Array
,NativeArray
]) – an arbitrary number of arrays to-be broadcasted. Each array must have the same shape. And Each array must have the same dtype as its corresponding input array.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.
- Return type:
Container
- Returns:
ret – A list of containers containing broadcasted arrays
Examples
With
ivy.Container
inputs:>>> x1 = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([3, 4])) >>> x2 = ivy.Container(a=ivy.array([-1.2, 0.4]), b=ivy.array([0, 1])) >>> y = ivy.Container.static_broadcast_arrays(x1, x2) >>> print(y) [{ a: ivy.array([1, 2]), b: ivy.array([3, 4]) }, { a: ivy.array([-1.2, 0.4]), b: ivy.array([0, 1]) }]
With mixed
ivy.Container
andivy.Array
inputs:>>> x1 = ivy.Container(a=ivy.array([4, 5]), b=ivy.array([2, -1])) >>> x2 = ivy.array([0.2, 3.]) >>> y = ivy.Container.static_broadcast_arrays(x1, x2) >>> print(y) [{ a: ivy.array([4, 5]), b: ivy.array([2, -1]) }, { a: ivy.array([0.2, 3.]), b: ivy.array([0.2, 3.]) }]
- static _static_broadcast_to(x, /, shape, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container static method variant of ivy.broadcast_to. This method simply wraps the function, and so the docstring for ivy.broadcast_to also applies to this method with minimal changes.
- Parameters:
x (
Container
) – input array to be broadcasted.shape (
Union
[Tuple
[int
,...
],Container
]) – desired shape to be broadcasted to.out (
Optional
[Container
], default:None
) – Optional array to store the broadcasted array.
- Return type:
Container
- Returns:
ret – Returns the broadcasted array of shape ‘shape’
Examples
With
ivy.Container
static method:>>> x = ivy.Container(a=ivy.array([1]), ... b=ivy.array([2])) >>> y = ivy.Container.static_broadcast_to(x,(3, 1)) >>> print(y) { a: ivy.array([1], [1], [1]), b: ivy.array([2], [2], [2]) }
- static _static_can_cast(from_, to, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container static method variant of ivy.can_cast. This method simply wraps the function, and so the docstring for ivy.can_cast also applies to this method with minimal changes.
- Parameters:
from – input container from which to cast.
to (
Union
[Dtype
,Container
]) – desired data type.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.
- Return type:
Container
- Returns:
ret –
True
if the cast can occur according to type-promotion rules; otherwise,False
.
Examples
>>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3, 4, 5])) >>> print(x.a.dtype, x.b.dtype) float32 int32
>>> print(ivy.Container.static_can_cast(x, 'int64')) { a: false, b: true }
- static _static_default_complex_dtype(*, input=None, complex_dtype=None, as_native=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
- Return type:
Container
- static _static_default_float_dtype(*, input=None, float_dtype=None, as_native=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
- Return type:
Container
- static _static_dtype(x, *, as_native=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
- Return type:
Container
- static _static_finfo(type, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container static method variant of ivy.finfo.
- Parameters:
type (
Container
) – input container with leaves to inquire information about.- Return type:
Container
- Returns:
ret – container of the same structure as self, with each element as a finfo object for the corresponding dtype of leave in`self`.
Examples
>>> c = ivy.Container(x=ivy.array([-9.5,1.8,-8.9], dtype=ivy.float16), ... y=ivy.array([7.6,8.1,1.6], dtype=ivy.float64)) >>> y = ivy.Container.static_finfo(c) >>> print(y) { x: finfo(resolution=0.001, min=-6.55040e+04, max=6.55040e+04, dtype=float16), y: finfo(resolution=1e-15, min=-1.7976931348623157e+308, max=1.7976931348623157e+308, dtype=float64) }
- static _static_function_supported_dtypes(fn, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
- Return type:
Container
- static _static_function_unsupported_dtypes(fn, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
- Return type:
Container
- static _static_iinfo(type, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container static method variant of ivy.iinfo. This method simply wraps the function, and so the docstring for ivy.iinfo also applies to this method with minimal changes.
- Parameters:
type (
Container
) – input container with leaves to inquire information about.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – Boolean indicating whether to apply the method to the key-chains. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Boolean indicating whether to prune the key-chains that were not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Boolean indicating whether to map method to sequences (list, tuple). Default isFalse
.
- Return type:
Container
- Returns:
ret – container of the same structure as type, with each element as an iinfo object for the corresponding dtype of leave in`type`.
Examples
>>> c = ivy.Container(x=ivy.array([12,-1800,1084], dtype=ivy.int16), ... y=ivy.array([-40000,99,1], dtype=ivy.int32)) >>> y = ivy.Container.static_iinfo(c) >>> print(y) { x: iinfo(min=-32768, max=32767, dtype=int16), y: iinfo(min=-2147483648, max=2147483647, dtype=int32) }
- static _static_is_bool_dtype(dtype_in, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
- Return type:
Container
- static _static_is_complex_dtype(dtype_in, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container static method variant of is_complex_dtype. This method simply wraps this function, so the docstring of is_complex_dtype roughly applies to this method.
- Parameters:
dtype_in (ivy.Container) – The input to check for complex dtype.
key_chains (Optional[Union[List[str], Dict[str, str]]]) – The key chains to use when mapping over the input.
to_apply (bool) – Whether to apply the mapping over the input.
prune_unapplied (bool) – Whether to prune the keys that were not applied.
map_sequences (bool) – Boolean indicating whether to map method to sequences (list, tuple). Default is
False
.
- Return type:
Container
- Returns:
ret (bool) – Boolean indicating whether the input has float dtype.
Examples
>>> x = ivy.Container.static_is_complex_dtype(ivy.complex64) >>> print(x) True
>>> x = ivy.Container.static_is_complex_dtype(ivy.int64) >>> print(x) False
>>> x = ivy.Container.static_is_complex_dtype(ivy.float32) >>> print(x) False
- static _static_is_float_dtype(dtype_in, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container static method variant of is_float_dtype. This method simply wraps this function, so the docstring of is_float_dtype roughly applies to this method.
- Parameters:
dtype_in (ivy.Container) – The input to check for float dtype.
key_chains (Optional[Union[List[str], Dict[str, str]]]) – The key chains to use when mapping over the input.
to_apply (bool) – Whether to apply the mapping over the input.
prune_unapplied (bool) – Whether to prune the keys that were not applied.
map_sequences (bool) – Boolean indicating whether to map method to sequences (list, tuple). Default is
False
.
- Return type:
Container
- Returns:
ret (bool) – Boolean indicating whether the input has float dtype.
Examples
>>> x = ivy.static_is_float_dtype(ivy.float32) >>> print(x) True
>>> x = ivy.static_is_float_dtype(ivy.int64) >>> print(x) False
>>> x = ivy.static_is_float_dtype(ivy.int32) >>> print(x) False
>>> x = ivy.static_is_float_dtype(ivy.bool) >>> print(x) False
>>> arr = ivy.array([1.2, 3.2, 4.3], dtype=ivy.float32) >>> print(arr.is_float_dtype()) True
>>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3, 4, 5])) >>> print(x.a.dtype, x.b.dtype) float32 int32
- static _static_is_int_dtype(dtype_in, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
- Return type:
Container
- static _static_is_uint_dtype(dtype_in, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
- Return type:
Container
- static _static_result_type(*arrays_and_dtypes, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container static 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:
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 isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.
- Return type:
Container
- Returns:
ret – the dtype resulting from an operation involving the input arrays and dtypes.
Examples
>>> x = ivy.Container(a = ivy.array([0, 1, 2]), ... b = ivy.array([3., 4., 5.])) >>> print(x.a.dtype, x.b.dtype) int32 float32
>>> print(ivy.Container.static_result_type(x, ivy.float64)) { a: float64, b: float32 }
- astype(dtype, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, copy=True, out=None)[source]#
Copy an array to a specified data type irrespective of type- promotion rules.
Casting floating-point
NaN
andinfinity
values to integral data types is not specified and is implementation-dependent.When casting a boolean input array to a numeric data type, a value of
True
must cast to a numeric value equal to1
, and a value ofFalse
must cast to a numeric value equal to0
.When casting a numeric input array to
bool
, a value of0
must cast toFalse
, and a non-zero value must cast toTrue
.- Parameters:
self (
Container
) – array to cast.dtype (
Union
[Dtype
,Container
]) – desired data type.copy (
Union
[bool
,Container
], default:True
) – specifies whether to copy an array when the specifieddtype
matches the data type of the input arrayx
. IfTrue
, a newly allocated array must always be returned. IfFalse
and the specifieddtype
matches the data type of the input array, the input array must be returned; otherwise, a newly allocated must be returned. Default:True
.out (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – an array having the specified data type. The returned array must have the same shape as
x
.
Examples
Using
ivy.Container
instance method:>>> x = ivy.Container(a=ivy.array([False,True,True]), ... b=ivy.array([3.14, 2.718, 1.618])) >>> print(x.astype(ivy.int32)) { a: ivy.array([0, 1, 1]), b: ivy.array([3, 2, 1]) }
- broadcast_arrays(*arrays, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container instance method variant of ivy.broadcast_arrays. This method simply wraps the function, and so the docstring for ivy.broadcast_arrays also applies to this method with minimal changes.
- Parameters:
self (
Container
) – A container to be broadcatsed against other input arrays.arrays (
Union
[Container
,Array
,NativeArray
]) – an arbitrary number of containers having arrays to-be broadcasted. Each array must have the same shape. Each array must have the same dtype as its corresponding input array.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.
- Return type:
Container
Examples
With
ivy.Container
inputs:>>> x1 = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([3, 4])) >>> x2 = ivy.Container(a=ivy.array([-1.2, 0.4]), b=ivy.array([0, 1])) >>> y = x1.broadcast_arrays(x2) >>> print(y) [{ a: ivy.array([1, 2]), b: ivy.array([3, 4]) }, { a: ivy.array([-1.2, 0.4]), b: ivy.array([0, 1]) }]
With mixed
ivy.Container
andivy.Array
inputs:>>> x1 = ivy.Container(a=ivy.array([4, 5]), b=ivy.array([2, -1])) >>> x2 = ivy.zeros(2) >>> y = x1.broadcast_arrays(x2) >>> print(y) [{ a: ivy.array([4, 5]), b: ivy.array([2, -1]) }, { a: ivy.array([0., 0.]), b: ivy.array([0., 0.]) }]
- broadcast_to(shape, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of ivy.broadcast_to. This method simply wraps the function, and so the docstring for ivy.broadcast_to also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input array to be broadcasted.shape (
Union
[Tuple
[int
,...
],Container
]) – desired shape to be broadcasted to.out (
Optional
[Container
], default:None
) – Optional array to store the broadcasted array.
- Return type:
Container
- Returns:
ret – Returns the broadcasted array of shape ‘shape’
Examples
With
ivy.Container
instance method:>>> x = ivy.Container(a=ivy.array([0, 0.5]), ... b=ivy.array([4, 5])) >>> y = x.broadcast_to((3,2)) >>> print(y) { a: ivy.array([[0., 0.5], [0., 0.5], [0., 0.5]]), b: ivy.array([[4, 5], [4, 5], [4, 5]]) }
- can_cast(to, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container instance method variant of ivy.can_cast. This method simply wraps the function, and so the docstring for ivy.can_cast also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input container from which to cast.to (
Union
[Dtype
,Container
]) – desired data type.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.
- Return type:
Container
- Returns:
ret –
True
if the cast can occur according to type-promotion rules; otherwise,False
.
Examples
>>> x = ivy.Container(a=ivy.array([0., 1., 2.]), ... b=ivy.array([3, 4, 5])) >>> print(x.a.dtype, x.b.dtype) float32 int32
>>> print(x.can_cast('int64')) { a: False, b: True }
- dtype(*, as_native=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
- Return type:
Container
Examples
>>> x = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([2, 3, 4])) >>> y = x.dtype() >>> print(y) { a: int32, b: int32 }
- finfo(*, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container instance method variant of ivy.finfo.
- Parameters:
self (
Container
) – input container with leaves to inquire information about.- Return type:
Container
- Returns:
ret – container of the same structure as self, with each element as a finfo object for the corresponding dtype of leave in`self`.
Examples
>>> c = ivy.Container(x=ivy.array([-9.5,1.8,-8.9], dtype=ivy.float16), ... y=ivy.array([7.6,8.1,1.6], dtype=ivy.float64)) >>> print(c.finfo()) { x: finfo(resolution=0.001, min=-6.55040e+04, max=6.55040e+04, dtype=float16), y: finfo(resolution=1e-15, min=-1.7976931348623157e+308, max=1.7976931348623157e+308, dtype=float64) }
- iinfo(key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container instance method variant of ivy.iinfo. This method simply wraps the function, and so the docstring for ivy.iinfo also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input container with leaves to inquire information about.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – Boolean indicating whether to apply the method to the key-chains. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Boolean indicating whether to prune the key-chains that were not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Boolean indicating whether to map method to sequences (list, tuple). Default isFalse
.
- Return type:
Container
- Returns:
ret – container of the same structure as self, with each element as an iinfo object for the corresponding dtype of leave in`self`.
Examples
>>> c = ivy.Container(x=ivy.array([-9,1800,89], dtype=ivy.int16), ... y=ivy.array([76,-81,16], dtype=ivy.int32)) >>> c.iinfo() { x: iinfo(min=-32768, max=32767, dtype=int16), y: iinfo(min=-2147483648, max=2147483647, dtype=int32) }
>>> c = ivy.Container(x=ivy.array([-12,123,4], dtype=ivy.int8), ... y=ivy.array([76,-81,16], dtype=ivy.int16)) >>> c.iinfo() { x: iinfo(min=-128, max=127, dtype=int8), y: iinfo(min=-32768, max=32767, dtype=int16) }
- is_bool_dtype(key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
- Return type:
Container
- is_complex_dtype(key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container instance method variant of ivy.is_complex_dtype. This method simply wraps the function, and so the docstring for ivy.is_complex_dtype also applies to this method with minimal changes.
- Parameters:
self (ivy.Container) – The ivy.Container instance to call ivy.is_complex_dtype on.
key_chains (Union[List[str], Dict[str, str]]) – The key-chains to apply or not apply the method to. Default is
None
.to_apply (bool) – Boolean indicating whether to apply the method to the key-chains. Default is
False
.prune_unapplied (bool) – Boolean indicating whether to prune the key-chains that were not applied. Default is
False
.map_sequences (bool) – Boolean indicating whether to map method to sequences (list, tuple). Default is
False
.
- Return type:
Container
- Returns:
ret (bool) – Boolean of whether the input is of a complex dtype.
Examples
>>> x = ivy.is_complex_dtype(ivy.complex64) >>> print(x) True
>>> x = ivy.is_complex_dtype(ivy.int64) >>> print(x) False
>>> x = ivy.is_complex_dtype(ivy.float32) >>> print(x) False
- is_float_dtype(key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container instance method variant of ivy.is_float_dtype. This method simply wraps the function, and so the docstring for ivy.is_float_dtype also applies to this method with minimal changes.
- Parameters:
self (ivy.Container) – The ivy.Container instance to call ivy.is_float_dtype on.
key_chains (Union[List[str], Dict[str, str]]) – The key-chains to apply or not apply the method to. Default is
None
.to_apply (bool) – Boolean indicating whether to apply the method to the key-chains. Default is
False
.prune_unapplied (bool) – Boolean indicating whether to prune the key-chains that were not applied. Default is
False
.map_sequences (bool) – Boolean indicating whether to map method to sequences (list, tuple). Default is
False
.
- Return type:
Container
- Returns:
ret (bool) – Boolean of whether the input is of a float dtype.
Examples
>>> x = ivy.is_float_dtype(ivy.float32) >>> print(x) True
>>> x = ivy.is_float_dtype(ivy.int64) >>> print(x) False
>>> x = ivy.is_float_dtype(ivy.int32) >>> print(x) False
>>> x = ivy.is_float_dtype(ivy.bool) >>> print(x) False
>>> arr = ivy.array([1.2, 3.2, 4.3], dtype=ivy.float32) >>> print(arr.is_float_dtype()) True
>>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3, 4, 5])) >>> print(x.a.dtype, x.b.dtype) float32 int32
- is_int_dtype(key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
- Return type:
Container
- is_uint_dtype(key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
- Return type:
Container
- result_type(*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 isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.
- 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 } }
This should have hopefully given you an overview of the data_type submodule, if you have any questions, please feel free to reach out on our discord!