Improve docs of copy
@@ -5,7 +5,7 @@ from chainer.utils import type_check
class Copy(function.Function):
- """Copy an input :class:`cupy.ndarray` onto another device."""
+ """Copies the input variable onto the specified device."""
def __init__(self, out_device):
self.out_device = out_device
@@ -53,15 +53,30 @@ def copy(x, dst):
This function copies the array of input variable onto the device specified
by ``dst``. When ``dst == -1``, it copies the array onto the host memory.
- This function supports copies from host to device, from device to device
- and from device to host.
+ This function supports copies from host to host, from host to device,
+ from device to device and from device to host.
Args:
- x (~chainer.Variable): Variable to be copied.
- dst: Target device specifier.
+ x (:class:`~chainer.Variable` or :class:`numpy.ndarray` or \
+ :class:`cupy.ndarray`):
+ Variable to be copied.
+ dst (int): Target device specifier.
Returns:
~chainer.Variable: Output variable.
+ .. admonition:: Example
+
+ >>> import chainer.cuda as cuda
+ >>> x = np.random.uniform(-1, 1, (5, 10))
+ >>> cuda.get_device_from_array(x).id
+ -1
+ >>> y = F.copy(x, 0) # from host to device0
+ >>> cuda.get_device_from_array(y.data).id
+ 0
+ >>> z = F.copy(y, -1) # from device0 to host
+ >>> cuda.get_device_from_array(z.data).id
+ -1
+
"""
return Copy(dst)(x)
