Device#

class ivy.data_classes.container.device._ContainerWithDevice(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, **kwargs)[source]#

Bases: ContainerBase

_abc_impl = <_abc_data object>#
static _static_dev(x, /, *, as_native=False)[source]#

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

Examples

>>> x = ivy.Container(a=ivy.array([[2, 3], [3, 5]]),
...                   b=ivy.native_array([1, 2, 4, 5, 7]))
>>> as_native = ivy.Container(a=True, b=False)
>>> y = ivy.Container.static_dev(x, as_native=as_native)
>>> print(y)
{
    a: device(type=cpu),
    b: cpu
}
Return type:

Container

static _static_to_device(x, device, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, stream=None, out=None)[source]#

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

Parameters:
  • x (Union[Container, Array, NativeArray]) – input array to be moved to the desired device

  • device (Union[Device, NativeDevice]) – device to move the input array x to

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

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

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

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

  • stream (Optional[Union[int, Any]]) – stream object to use during copy. In addition to the types supported (default: None) in array.__dlpack__(), implementations may choose to support any library-specific stream object with the caveat that any code using such an object would not be portable.

  • out (Optional[Container]) – optional output array, for writing the result to. It must have a (default: None) shape that the inputs broadcast to.

Return type:

Container

Returns:

ret – input array x placed on the desired device

Examples

>>> x = ivy.Container(a=ivy.array([[2, 3, 1], [3, 5, 3]]),
...                   b=ivy.native_array([[1, 2], [4, 5]]))
>>> y = ivy.Container.static_to_device(x, 'cpu')
>>> print(y.a.device, y.b.device)
cpu cpu
dev(as_native=False)[source]#

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

Parameters:
  • self (Container) – contaioner of arrays for which to get the device handle.

  • as_native (bool) – Whether or not to return the dev in native format. Default is False. (default: False)

Examples

>>> x = ivy.Container(a=ivy.array([[2, 3, 1], [3, 5, 3]]),
...                   b=ivy.native_array([[1, 2], [4, 5]]))
>>> as_native = ivy.Container(a=False, b=True)
>>> y = x.dev(as_native=as_native)
>>> print(y)
{
    a:cpu,
    b:cpu
}
Return type:

Container

to_device(device, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, stream=None, out=None)[source]#

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

Parameters:
  • x – input array to be moved to the desired device

  • device (Union[Device, NativeDevice]) – device to move the input array x to

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

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

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

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

  • stream (Optional[Union[int, Any]]) – stream object to use during copy. In addition to the types supported (default: None) in array.__dlpack__(), implementations may choose to support any library-specific stream object with the caveat that any code using such an object would not be portable.

  • out (Optional[Container]) – optional output array, for writing the result to. It must have a (default: None) shape that the inputs broadcast to.

Return type:

Container

Returns:

ret – input array x placed on the desired device

Examples

>>> x = ivy.Container(a=ivy.array([[2, 3, 1], [3, 5, 3]]),
...                   b=ivy.native_array([[1, 2], [4, 5]]))
>>> y = x.to_device('cpu')
>>> print(y.a.device, y.b.device)
cpu cpu