to_device#
- ivy.to_device(x, device, /, *, stream=None, out=None)[source]#
Move the input array x to the desired device, specified by device string.
- Parameters:
x (
Union
[Array
,NativeArray
]) – input array to be moved to the desired devicedevice (
Union
[Device
,NativeDevice
]) – device to move the input array x tostream (
Optional
[Union
[int
,Any
]], default:None
) – stream object to use during copy. In addition to the types supported 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
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
- Returns:
ret – input array x placed on the desired device
Examples
>>> x = ivy.array([1., 2., 3.]) >>> x = ivy.to_device(x, 'cpu') >>> print(x.device) cpu
- Array.to_device(self, device, *, stream=None, out=None)[source]#
ivy.Array 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:
self (
Array
) – input array to be moved to the desired devicedevice (
Union
[Device
,NativeDevice
]) – device to move the input array x tostream (
Optional
[Union
[int
,Any
]], default:None
) – stream object to use during copy. In addition to the types supported 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
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Array
Examples
>>> x = ivy.array([2, 5, 4, 1]) >>> y = x.to_device('cpu') >>> print(y.device) cpu
- Container.to_device(self, 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
,Container
]) – device to move the input array x tokey_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
.stream (
Optional
[Union
[int
,Any
,Container
]], default:None
) – stream object to use during copy. In addition to the types supported 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
], 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 – 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