chainer.functions.copy

chainer.functions.copy(x, dst)[source]

Copies the input variable onto the specified device.

If the input x already resides on the device specified by dst, no copy will actually take place and the returned variable will hold a view of the input. In other cases, the input will be copied to dst. When dst == -1, the array is copied to the host memory. This function supports copies from host to host, from host to device, from device to device and from device to host.

Parameters
Returns

Output variable.

Return type

Variable

Example

>>> import chainer.backends.cuda as cuda
>>> x_arr = np.random.uniform(-1, 1, (5, 10))
>>> x = chainer.Variable(x_arr)
>>> x.device
<CpuDevice (numpy)>
>>> y = F.copy(x, '@cupy:0') # from CPU (NumPy) to GPU 0 (CuPy)
>>> y.device
<GpuDevice (cupy):0>

Note

Copies between non-ChainerX devices and ChainerX devices are not supported.