We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add chainerx.ndarray.item
Background: #5797, #6007.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `chainerx/_docs/array.py`
Content:
```
1 import chainerx
2 from chainerx import _docs
3 
4 
5 def set_docs():
6     ndarray = chainerx.ndarray
7 
8     _docs.set_doc(
9         ndarray,
10         """ndarray(shape, dtype, device=None)
11 Multi-dimensional array, the central data structure of ChainerX.
12 
13 This class, along with other APIs in the :mod:`chainerx` module, provides a
14 subset of NumPy APIs. This class works similar to :class:`numpy.ndarray`,
15 except for some differences including the following noticeable points:
16 
17 - :class:`chainerx.ndarray` has a :attr:`device` attribute. It indicates on
18   which device the array is allocated.
19 - :class:`chainerx.ndarray` supports :ref:`Define-by-Run <define_by_run>`
20   backpropagation. Once you call :meth:`require_grad`, the array starts
21   recording the operations applied to it recursively. Gradient of the result
22   with respect to the original array can be computed then with the
23   :meth:`backward` method or the :func:`chainerx.backward` function.
24 
25 Args:
26     shape (tuple of ints): Shape of the new array.
27     dtype: Data type.
28     device (~chainerx.Device): Device on which the array is allocated.
29         If omitted, :ref:`the default device <chainerx_device>` is chosen.
30 
31 .. seealso:: :class:`numpy.ndarray`
32 """)
33 
34     _docs.set_doc(
35         ndarray.data_ptr,
36         """int: Address of the underlying memory allocation.
37 
38 The meaning of the address is device-dependent.
39 """)
40 
41     _docs.set_doc(
42         ndarray.data_size,
43         "int: Total size of the underlying memory allocation.")
44 
45     _docs.set_doc(
46         ndarray.device, "~chainerx.Device: Device on which the data exists.")
47 
48     _docs.set_doc(ndarray.dtype, "Data type of the array.")
49 
50     # TODO(beam2d): Write about backprop id.
51     _docs.set_doc(
52         ndarray.grad,
53         """~chainerx.ndarray: Gradient held by the array.
54 
55 It is ``None`` if the gradient is not available.
56 Setter of this property overwrites the gradient.
57 """)
58 
59     _docs.set_doc(
60         ndarray.is_contiguous,
61         "bool: ``True`` iff the array is stored in the C-contiguous order.")
62 
63     _docs.set_doc(ndarray.itemsize, "int: Size of each element in bytes.")
64 
65     _docs.set_doc(
66         ndarray.nbytes,
67         """int: Total size of all elements in bytes.
68 
69 It does not count skips between elements.""")
70 
71     _docs.set_doc(ndarray.ndim, "int: Number of dimensions.")
72 
73     _docs.set_doc(
74         ndarray.offset,
75         "int: Offset of the first element from the memory allocation in bytes."
76     )
77 
78     _docs.set_doc(
79         ndarray.shape,
80         """tuple of int: Lengths of axes.
81 
82 .. note::
83     Currently, this property does not support setter.""")
84 
85     _docs.set_doc(ndarray.size, "int: Number of elements in the array.")
86 
87     _docs.set_doc(ndarray.strides, "tuple of int: Strides of axes in bytes.")
88 
89     _docs.set_doc(
90         ndarray.T,
91         """~chainerx.ndarray: Shape-reversed view of the array.
92 
93 New array is created at every access to this property.
94 ``x.T`` is just a shorthand of ``x.transpose()``.
95 """)
96 
97     _docs.set_doc(
98         ndarray.__getitem__,
99         """___getitem__(self, key)
100 Returns self[key].
101 
102 .. note::
103     Currently, only basic indexing is supported not advanced indexing.
104 """)
105 
106     def unary_op(name, s):
107         _docs.set_doc(getattr(ndarray, name), "{}()\n{}".format(name, s))
108 
109     unary_op("__bool__", "Casts a size-one array into a :class:`bool` value.")
110     unary_op("__float__",
111              "Casts a size-one array into a :class:`float` value.")
112     unary_op("__int__", "Casts a size-one array into :class:`int` value.")
113     unary_op("__len__", "Returns the length of the first axis.")
114     unary_op("__neg__", "Computes ``-x`` elementwise.")
115 
116     def binary_op(name, s):
117         _docs.set_doc(getattr(ndarray, name), "{}(other)\n{}".format(name, s))
118 
119     binary_op("__eq__", "Computes ``x == y`` elementwise.")
120     binary_op("__ne__", "Computes ``x != y`` elementwise.")
121     binary_op("__lt__", "Computes ``x < y`` elementwise.")
122     binary_op("__le__", "Computes ``x <= y`` elementwise.")
123     binary_op("__ge__", "Computes ``x >= y`` elementwise.")
124     binary_op("__gt__", "Computes ``x > y`` elementwise.")
125 
126     binary_op("__iadd__", "Computes ``x += y`` elementwise.")
127     binary_op("__isub__", "Computes ``x -= y`` elementwise.")
128     binary_op("__imul__", "Computes ``x *= y`` elementwise.")
129     binary_op("__itruediv__", "Computes ``x /= y`` elementwise.")
130 
131     binary_op("__add__", "Computes ``x + y`` elementwise.")
132     binary_op("__sub__", "Computes ``x - y`` elementwise.")
133     binary_op("__mul__", "Computes ``x * y`` elementwise.")
134     binary_op("__truediv__", "Computes ``x / y`` elementwise.")
135 
136     binary_op("__radd__", "Computes ``y + x`` elementwise.")
137     binary_op("__rsub__", "Computes ``y - x`` elementwise.")
138     binary_op("__rmul__", "Computes ``y * x`` elementwise.")
139 
140     # TODO(beam2d): Write about as_grad_stopped(backprop_ids, copy) overload.
141     _docs.set_doc(
142         ndarray.as_grad_stopped,
143         """as_grad_stopped(copy=False)
144 Creates a view or a copy of the array that stops gradient propagation.
145 
146 This method behaves similar to :meth:`view` and :meth:`copy`, except that
147 the gradient is not propagated through this operation (internally, this
148 method creates a copy or view of the array without connecting the computational
149 graph for backprop).
150 
151 Args:
152     copy (bool): If ``True``, it copies the array. Otherwise, it returns a view
153         of the original array.
154 
155 Returns:
156     ~chainerx.ndarray:
157         A view or a copy of the array without propagating the  gradient on
158         backprop.
159 """)
160 
161     _docs.set_doc(
162         ndarray.argmax,
163         """argmax(axis=None)
164 Returns the indices of the maximum elements along a given axis.
165 
166 See :func:`chainerx.argmax` for the full documentation.
167 """)
168 
169     _docs.set_doc(
170         ndarray.astype,
171         """astype(dtype, copy=True)
172 Casts each element to the specified data type.
173 
174 Args:
175     dtype: Data type of the new array.
176     copy (bool): If ``True``, this method always copies the data. Otherwise,
177         it creates a view of the array if possible.
178 
179 Returns:
180     ~chainerx.ndarray: An array with the specified dtype.
181 """)
182 
183     _docs.set_doc(
184         ndarray.backward,
185         """backward(backprop_id=None, enable_double_backprop=False)
186 Performs backpropagation starting from this array.
187 
188 This method is equivalent to ``chainerx.backward([self], *args)``.
189 See :func:`chainerx.backward` for the full documentation.
190 """)
191 
192     # TODO(beam2d): Write about backprop id.
193     _docs.set_doc(
194         ndarray.cleargrad,
195         """cleargrad()
196 Clears the gradient held by this array.
197 """)
198 
199     _docs.set_doc(
200         ndarray.copy,
201         """copy()
202 Creates an array and copies all the elements to it.
203 
204 The copied array is allocated on the same device as ``self``.
205 
206 .. seealso:: :func:`chainerx.copy`
207 """)
208 
209     _docs.set_doc(
210         ndarray.dot,
211         """dot(b)
212 Returns the dot product with a given array.
213 
214 See :func:`chainerx.dot` for the full documentation.
215 """)
216 
217     _docs.set_doc(
218         ndarray.fill,
219         """fill(value)
220 Fills the array with a scalar value in place.
221 
222 Args:
223     value: Scalar value with which the array will be filled.
224 """)
225 
226     # TODO(beam2d): Write about backprop_id argument.
227     _docs.set_doc(
228         ndarray.get_grad,
229         """get_grad()
230 Returns the gradient held by the array.
231 
232 If the gradient is not available, it returns ``None``.
233 """)
234 
235     # TODO(beam2d): Write about backprop_id argument.
236     _docs.set_doc(
237         ndarray.is_backprop_required,
238         """is_backprop_required()
239 Returns ``True`` if gradient propagates through this array on backprop.
240 
241 See the note on :meth:`require_grad` for details.
242 """)
243 
244     # TODO(beam2d): Write about backprop_id argument.
245     _docs.set_doc(
246         ndarray.is_grad_required,
247         """is_grad_required()
248 Returns ``True`` if the gradient will be set after backprop.
249 
250 See the note on :meth:`require_grad` for details.
251 """)
252 
253     _docs.set_doc(
254         ndarray.max,
255         """max(axis=None, keepdims=False)
256 Returns the maximum along a given axis.
257 
258 See :func:`chainerx.amax` for the full documentation.
259 """)
260 
261     # TODO(beam2d): Write about backprop_id argument.
262     _docs.set_doc(
263         ndarray.require_grad,
264         """require_grad()
265 Declares that a gradient for this array will be made available after backprop.
266 
267 Once calling this method, any operations applied to this array are recorded for
268 later backprop. After backprop, the :attr:`grad` attribute holds the gradient
269 array.
270 
271 .. note::
272     ChainerX distinguishes *gradient requirements* and *backprop requirements*
273     strictly. They are strongly related, but different concepts as follows.
274 
275     - *Gradient requirement* indicates that the gradient array should be made
276       available after backprop. This attribute **is not propagated** through
277       any operations. It implicates the backprop requirement.
278     - *Backprop requirement* indicates that the gradient should be propagated
279       through the array during backprop. This attribute **is propagated**
280       through differentiable operations.
281 
282     :meth:`require_grad` sets the gradient requirement flag. If you need to
283     extract the gradient after backprop, you have to call :meth:`require_grad`
284     on the array even if the array is an intermediate result of differentiable
285     computations.
286 
287 Returns:
288     ~chainerx.ndarray: ``self``
289 """)
290 
291     _docs.set_doc(
292         ndarray.reshape,
293         """reshape(newshape)
294 Creates an array with a new shape and the same data.
295 
296 See :func:`chainerx.reshape` for the full documentation.
297 """)
298 
299     _docs.set_doc(
300         ndarray.set_grad,
301         """set_grad(grad)
302 Sets a gradient to the array.
303 
304 This method overwrites the gradient with a given array.
305 
306 Args:
307     grad (~chainerx.ndarray): New gradient array.
308 """)
309 
310     _docs.set_doc(
311         ndarray.squeeze,
312         """squeeze(axis=None)
313 Removes size-one axes from an array.
314 
315 See :func:`chainerx.squeeze` for the full documentation.
316 """)
317 
318     _docs.set_doc(
319         ndarray.sum,
320         """sum(axis=None, keepdims=False)
321 Returns the sum of an array along given axes.
322 
323 See :func:`chainerx.sum` for the full documentation.
324 """)
325 
326     _docs.set_doc(
327         ndarray.take,
328         """take(indices, axis)
329 Takes elements from the array along an axis.
330 
331 See :func:`chainerx.take` for the full documentation.
332 """)
333 
334     _docs.set_doc(
335         ndarray.to_device,
336         """to_device(device, index=None)
337 Transfers the array to the specified device.
338 
339 Args:
340     device (~chainerx.Device or str): Device to which the array is transferred,
341         or a backend name. If it is a backend name, ``index`` should also be
342         specified.
343     index (int): Index of the device for the backend specified by ``device``.
344 
345 Returns:
346     ~chainerx.ndarray:
347         An array on the target device.
348         If the original array is already on the device, it is a view of that.
349         Otherwise, it is a copy of the array on the target device.
350 """)
351 
352     _docs.set_doc(
353         ndarray.transpose,
354         """transpose(axes=None)
355 Creates a view of an array with permutated axes.
356 
357 See :func:`chainerx.transpose` for the full documentation.
358 """)
359 
360     _docs.set_doc(
361         ndarray.view,
362         """view()
363 Returns a view of the array.
364 
365 The returned array shares the underlying buffer, though it has a different
366 identity as a Python object.
367 """)
368
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/chainerx/_docs/array.py b/chainerx/_docs/array.py
--- a/chainerx/_docs/array.py
+++ b/chainerx/_docs/array.py
@@ -248,6 +248,19 @@
 Returns ``True`` if the gradient will be set after backprop.
 
 See the note on :meth:`require_grad` for details.
+""")
+
+    _docs.set_doc(
+        ndarray.item,
+        """item()
+Copies an element of an array to a standard Python scalar and returns it.
+
+Returns:
+    z:
+        A copy of the specified element of the array as a suitable Python
+        scalar.
+
+.. seealso:: :func:`numpy.item`
 """)
 
     _docs.set_doc(

{"golden_diff": "diff --git a/chainerx/_docs/array.py b/chainerx/_docs/array.py\n--- a/chainerx/_docs/array.py\n+++ b/chainerx/_docs/array.py\n@@ -248,6 +248,19 @@\n Returns ``True`` if the gradient will be set after backprop.\n \n See the note on :meth:`require_grad` for details.\n+\"\"\")\n+\n+    _docs.set_doc(\n+        ndarray.item,\n+        \"\"\"item()\n+Copies an element of an array to a standard Python scalar and returns it.\n+\n+Returns:\n+    z:\n+        A copy of the specified element of the array as a suitable Python\n+        scalar.\n+\n+.. seealso:: :func:`numpy.item`\n \"\"\")\n \n     _docs.set_doc(\n", "issue": "Add chainerx.ndarray.item\nBackground: #5797, #6007.\n", "before_files": [{"content": "import chainerx\nfrom chainerx import _docs\n\n\ndef set_docs():\n    ndarray = chainerx.ndarray\n\n    _docs.set_doc(\n        ndarray,\n        \"\"\"ndarray(shape, dtype, device=None)\nMulti-dimensional array, the central data structure of ChainerX.\n\nThis class, along with other APIs in the :mod:`chainerx` module, provides a\nsubset of NumPy APIs. This class works similar to :class:`numpy.ndarray`,\nexcept for some differences including the following noticeable points:\n\n- :class:`chainerx.ndarray` has a :attr:`device` attribute. It indicates on\n  which device the array is allocated.\n- :class:`chainerx.ndarray` supports :ref:`Define-by-Run <define_by_run>`\n  backpropagation. Once you call :meth:`require_grad`, the array starts\n  recording the operations applied to it recursively. Gradient of the result\n  with respect to the original array can be computed then with the\n  :meth:`backward` method or the :func:`chainerx.backward` function.\n\nArgs:\n    shape (tuple of ints): Shape of the new array.\n    dtype: Data type.\n    device (~chainerx.Device): Device on which the array is allocated.\n        If omitted, :ref:`the default device <chainerx_device>` is chosen.\n\n.. seealso:: :class:`numpy.ndarray`\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.data_ptr,\n        \"\"\"int: Address of the underlying memory allocation.\n\nThe meaning of the address is device-dependent.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.data_size,\n        \"int: Total size of the underlying memory allocation.\")\n\n    _docs.set_doc(\n        ndarray.device, \"~chainerx.Device: Device on which the data exists.\")\n\n    _docs.set_doc(ndarray.dtype, \"Data type of the array.\")\n\n    # TODO(beam2d): Write about backprop id.\n    _docs.set_doc(\n        ndarray.grad,\n        \"\"\"~chainerx.ndarray: Gradient held by the array.\n\nIt is ``None`` if the gradient is not available.\nSetter of this property overwrites the gradient.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.is_contiguous,\n        \"bool: ``True`` iff the array is stored in the C-contiguous order.\")\n\n    _docs.set_doc(ndarray.itemsize, \"int: Size of each element in bytes.\")\n\n    _docs.set_doc(\n        ndarray.nbytes,\n        \"\"\"int: Total size of all elements in bytes.\n\nIt does not count skips between elements.\"\"\")\n\n    _docs.set_doc(ndarray.ndim, \"int: Number of dimensions.\")\n\n    _docs.set_doc(\n        ndarray.offset,\n        \"int: Offset of the first element from the memory allocation in bytes.\"\n    )\n\n    _docs.set_doc(\n        ndarray.shape,\n        \"\"\"tuple of int: Lengths of axes.\n\n.. note::\n    Currently, this property does not support setter.\"\"\")\n\n    _docs.set_doc(ndarray.size, \"int: Number of elements in the array.\")\n\n    _docs.set_doc(ndarray.strides, \"tuple of int: Strides of axes in bytes.\")\n\n    _docs.set_doc(\n        ndarray.T,\n        \"\"\"~chainerx.ndarray: Shape-reversed view of the array.\n\nNew array is created at every access to this property.\n``x.T`` is just a shorthand of ``x.transpose()``.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.__getitem__,\n        \"\"\"___getitem__(self, key)\nReturns self[key].\n\n.. note::\n    Currently, only basic indexing is supported not advanced indexing.\n\"\"\")\n\n    def unary_op(name, s):\n        _docs.set_doc(getattr(ndarray, name), \"{}()\\n{}\".format(name, s))\n\n    unary_op(\"__bool__\", \"Casts a size-one array into a :class:`bool` value.\")\n    unary_op(\"__float__\",\n             \"Casts a size-one array into a :class:`float` value.\")\n    unary_op(\"__int__\", \"Casts a size-one array into :class:`int` value.\")\n    unary_op(\"__len__\", \"Returns the length of the first axis.\")\n    unary_op(\"__neg__\", \"Computes ``-x`` elementwise.\")\n\n    def binary_op(name, s):\n        _docs.set_doc(getattr(ndarray, name), \"{}(other)\\n{}\".format(name, s))\n\n    binary_op(\"__eq__\", \"Computes ``x == y`` elementwise.\")\n    binary_op(\"__ne__\", \"Computes ``x != y`` elementwise.\")\n    binary_op(\"__lt__\", \"Computes ``x < y`` elementwise.\")\n    binary_op(\"__le__\", \"Computes ``x <= y`` elementwise.\")\n    binary_op(\"__ge__\", \"Computes ``x >= y`` elementwise.\")\n    binary_op(\"__gt__\", \"Computes ``x > y`` elementwise.\")\n\n    binary_op(\"__iadd__\", \"Computes ``x += y`` elementwise.\")\n    binary_op(\"__isub__\", \"Computes ``x -= y`` elementwise.\")\n    binary_op(\"__imul__\", \"Computes ``x *= y`` elementwise.\")\n    binary_op(\"__itruediv__\", \"Computes ``x /= y`` elementwise.\")\n\n    binary_op(\"__add__\", \"Computes ``x + y`` elementwise.\")\n    binary_op(\"__sub__\", \"Computes ``x - y`` elementwise.\")\n    binary_op(\"__mul__\", \"Computes ``x * y`` elementwise.\")\n    binary_op(\"__truediv__\", \"Computes ``x / y`` elementwise.\")\n\n    binary_op(\"__radd__\", \"Computes ``y + x`` elementwise.\")\n    binary_op(\"__rsub__\", \"Computes ``y - x`` elementwise.\")\n    binary_op(\"__rmul__\", \"Computes ``y * x`` elementwise.\")\n\n    # TODO(beam2d): Write about as_grad_stopped(backprop_ids, copy) overload.\n    _docs.set_doc(\n        ndarray.as_grad_stopped,\n        \"\"\"as_grad_stopped(copy=False)\nCreates a view or a copy of the array that stops gradient propagation.\n\nThis method behaves similar to :meth:`view` and :meth:`copy`, except that\nthe gradient is not propagated through this operation (internally, this\nmethod creates a copy or view of the array without connecting the computational\ngraph for backprop).\n\nArgs:\n    copy (bool): If ``True``, it copies the array. Otherwise, it returns a view\n        of the original array.\n\nReturns:\n    ~chainerx.ndarray:\n        A view or a copy of the array without propagating the  gradient on\n        backprop.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.argmax,\n        \"\"\"argmax(axis=None)\nReturns the indices of the maximum elements along a given axis.\n\nSee :func:`chainerx.argmax` for the full documentation.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.astype,\n        \"\"\"astype(dtype, copy=True)\nCasts each element to the specified data type.\n\nArgs:\n    dtype: Data type of the new array.\n    copy (bool): If ``True``, this method always copies the data. Otherwise,\n        it creates a view of the array if possible.\n\nReturns:\n    ~chainerx.ndarray: An array with the specified dtype.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.backward,\n        \"\"\"backward(backprop_id=None, enable_double_backprop=False)\nPerforms backpropagation starting from this array.\n\nThis method is equivalent to ``chainerx.backward([self], *args)``.\nSee :func:`chainerx.backward` for the full documentation.\n\"\"\")\n\n    # TODO(beam2d): Write about backprop id.\n    _docs.set_doc(\n        ndarray.cleargrad,\n        \"\"\"cleargrad()\nClears the gradient held by this array.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.copy,\n        \"\"\"copy()\nCreates an array and copies all the elements to it.\n\nThe copied array is allocated on the same device as ``self``.\n\n.. seealso:: :func:`chainerx.copy`\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.dot,\n        \"\"\"dot(b)\nReturns the dot product with a given array.\n\nSee :func:`chainerx.dot` for the full documentation.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.fill,\n        \"\"\"fill(value)\nFills the array with a scalar value in place.\n\nArgs:\n    value: Scalar value with which the array will be filled.\n\"\"\")\n\n    # TODO(beam2d): Write about backprop_id argument.\n    _docs.set_doc(\n        ndarray.get_grad,\n        \"\"\"get_grad()\nReturns the gradient held by the array.\n\nIf the gradient is not available, it returns ``None``.\n\"\"\")\n\n    # TODO(beam2d): Write about backprop_id argument.\n    _docs.set_doc(\n        ndarray.is_backprop_required,\n        \"\"\"is_backprop_required()\nReturns ``True`` if gradient propagates through this array on backprop.\n\nSee the note on :meth:`require_grad` for details.\n\"\"\")\n\n    # TODO(beam2d): Write about backprop_id argument.\n    _docs.set_doc(\n        ndarray.is_grad_required,\n        \"\"\"is_grad_required()\nReturns ``True`` if the gradient will be set after backprop.\n\nSee the note on :meth:`require_grad` for details.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.max,\n        \"\"\"max(axis=None, keepdims=False)\nReturns the maximum along a given axis.\n\nSee :func:`chainerx.amax` for the full documentation.\n\"\"\")\n\n    # TODO(beam2d): Write about backprop_id argument.\n    _docs.set_doc(\n        ndarray.require_grad,\n        \"\"\"require_grad()\nDeclares that a gradient for this array will be made available after backprop.\n\nOnce calling this method, any operations applied to this array are recorded for\nlater backprop. After backprop, the :attr:`grad` attribute holds the gradient\narray.\n\n.. note::\n    ChainerX distinguishes *gradient requirements* and *backprop requirements*\n    strictly. They are strongly related, but different concepts as follows.\n\n    - *Gradient requirement* indicates that the gradient array should be made\n      available after backprop. This attribute **is not propagated** through\n      any operations. It implicates the backprop requirement.\n    - *Backprop requirement* indicates that the gradient should be propagated\n      through the array during backprop. This attribute **is propagated**\n      through differentiable operations.\n\n    :meth:`require_grad` sets the gradient requirement flag. If you need to\n    extract the gradient after backprop, you have to call :meth:`require_grad`\n    on the array even if the array is an intermediate result of differentiable\n    computations.\n\nReturns:\n    ~chainerx.ndarray: ``self``\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.reshape,\n        \"\"\"reshape(newshape)\nCreates an array with a new shape and the same data.\n\nSee :func:`chainerx.reshape` for the full documentation.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.set_grad,\n        \"\"\"set_grad(grad)\nSets a gradient to the array.\n\nThis method overwrites the gradient with a given array.\n\nArgs:\n    grad (~chainerx.ndarray): New gradient array.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.squeeze,\n        \"\"\"squeeze(axis=None)\nRemoves size-one axes from an array.\n\nSee :func:`chainerx.squeeze` for the full documentation.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.sum,\n        \"\"\"sum(axis=None, keepdims=False)\nReturns the sum of an array along given axes.\n\nSee :func:`chainerx.sum` for the full documentation.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.take,\n        \"\"\"take(indices, axis)\nTakes elements from the array along an axis.\n\nSee :func:`chainerx.take` for the full documentation.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.to_device,\n        \"\"\"to_device(device, index=None)\nTransfers the array to the specified device.\n\nArgs:\n    device (~chainerx.Device or str): Device to which the array is transferred,\n        or a backend name. If it is a backend name, ``index`` should also be\n        specified.\n    index (int): Index of the device for the backend specified by ``device``.\n\nReturns:\n    ~chainerx.ndarray:\n        An array on the target device.\n        If the original array is already on the device, it is a view of that.\n        Otherwise, it is a copy of the array on the target device.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.transpose,\n        \"\"\"transpose(axes=None)\nCreates a view of an array with permutated axes.\n\nSee :func:`chainerx.transpose` for the full documentation.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.view,\n        \"\"\"view()\nReturns a view of the array.\n\nThe returned array shares the underlying buffer, though it has a different\nidentity as a Python object.\n\"\"\")\n", "path": "chainerx/_docs/array.py"}], "after_files": [{"content": "import chainerx\nfrom chainerx import _docs\n\n\ndef set_docs():\n    ndarray = chainerx.ndarray\n\n    _docs.set_doc(\n        ndarray,\n        \"\"\"ndarray(shape, dtype, device=None)\nMulti-dimensional array, the central data structure of ChainerX.\n\nThis class, along with other APIs in the :mod:`chainerx` module, provides a\nsubset of NumPy APIs. This class works similar to :class:`numpy.ndarray`,\nexcept for some differences including the following noticeable points:\n\n- :class:`chainerx.ndarray` has a :attr:`device` attribute. It indicates on\n  which device the array is allocated.\n- :class:`chainerx.ndarray` supports :ref:`Define-by-Run <define_by_run>`\n  backpropagation. Once you call :meth:`require_grad`, the array starts\n  recording the operations applied to it recursively. Gradient of the result\n  with respect to the original array can be computed then with the\n  :meth:`backward` method or the :func:`chainerx.backward` function.\n\nArgs:\n    shape (tuple of ints): Shape of the new array.\n    dtype: Data type.\n    device (~chainerx.Device): Device on which the array is allocated.\n        If omitted, :ref:`the default device <chainerx_device>` is chosen.\n\n.. seealso:: :class:`numpy.ndarray`\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.data_ptr,\n        \"\"\"int: Address of the underlying memory allocation.\n\nThe meaning of the address is device-dependent.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.data_size,\n        \"int: Total size of the underlying memory allocation.\")\n\n    _docs.set_doc(\n        ndarray.device, \"~chainerx.Device: Device on which the data exists.\")\n\n    _docs.set_doc(ndarray.dtype, \"Data type of the array.\")\n\n    # TODO(beam2d): Write about backprop id.\n    _docs.set_doc(\n        ndarray.grad,\n        \"\"\"~chainerx.ndarray: Gradient held by the array.\n\nIt is ``None`` if the gradient is not available.\nSetter of this property overwrites the gradient.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.is_contiguous,\n        \"bool: ``True`` iff the array is stored in the C-contiguous order.\")\n\n    _docs.set_doc(ndarray.itemsize, \"int: Size of each element in bytes.\")\n\n    _docs.set_doc(\n        ndarray.nbytes,\n        \"\"\"int: Total size of all elements in bytes.\n\nIt does not count skips between elements.\"\"\")\n\n    _docs.set_doc(ndarray.ndim, \"int: Number of dimensions.\")\n\n    _docs.set_doc(\n        ndarray.offset,\n        \"int: Offset of the first element from the memory allocation in bytes.\"\n    )\n\n    _docs.set_doc(\n        ndarray.shape,\n        \"\"\"tuple of int: Lengths of axes.\n\n.. note::\n    Currently, this property does not support setter.\"\"\")\n\n    _docs.set_doc(ndarray.size, \"int: Number of elements in the array.\")\n\n    _docs.set_doc(ndarray.strides, \"tuple of int: Strides of axes in bytes.\")\n\n    _docs.set_doc(\n        ndarray.T,\n        \"\"\"~chainerx.ndarray: Shape-reversed view of the array.\n\nNew array is created at every access to this property.\n``x.T`` is just a shorthand of ``x.transpose()``.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.__getitem__,\n        \"\"\"___getitem__(self, key)\nReturns self[key].\n\n.. note::\n    Currently, only basic indexing is supported not advanced indexing.\n\"\"\")\n\n    def unary_op(name, s):\n        _docs.set_doc(getattr(ndarray, name), \"{}()\\n{}\".format(name, s))\n\n    unary_op(\"__bool__\", \"Casts a size-one array into a :class:`bool` value.\")\n    unary_op(\"__float__\",\n             \"Casts a size-one array into a :class:`float` value.\")\n    unary_op(\"__int__\", \"Casts a size-one array into :class:`int` value.\")\n    unary_op(\"__len__\", \"Returns the length of the first axis.\")\n    unary_op(\"__neg__\", \"Computes ``-x`` elementwise.\")\n\n    def binary_op(name, s):\n        _docs.set_doc(getattr(ndarray, name), \"{}(other)\\n{}\".format(name, s))\n\n    binary_op(\"__eq__\", \"Computes ``x == y`` elementwise.\")\n    binary_op(\"__ne__\", \"Computes ``x != y`` elementwise.\")\n    binary_op(\"__lt__\", \"Computes ``x < y`` elementwise.\")\n    binary_op(\"__le__\", \"Computes ``x <= y`` elementwise.\")\n    binary_op(\"__ge__\", \"Computes ``x >= y`` elementwise.\")\n    binary_op(\"__gt__\", \"Computes ``x > y`` elementwise.\")\n\n    binary_op(\"__iadd__\", \"Computes ``x += y`` elementwise.\")\n    binary_op(\"__isub__\", \"Computes ``x -= y`` elementwise.\")\n    binary_op(\"__imul__\", \"Computes ``x *= y`` elementwise.\")\n    binary_op(\"__itruediv__\", \"Computes ``x /= y`` elementwise.\")\n\n    binary_op(\"__add__\", \"Computes ``x + y`` elementwise.\")\n    binary_op(\"__sub__\", \"Computes ``x - y`` elementwise.\")\n    binary_op(\"__mul__\", \"Computes ``x * y`` elementwise.\")\n    binary_op(\"__truediv__\", \"Computes ``x / y`` elementwise.\")\n\n    binary_op(\"__radd__\", \"Computes ``y + x`` elementwise.\")\n    binary_op(\"__rsub__\", \"Computes ``y - x`` elementwise.\")\n    binary_op(\"__rmul__\", \"Computes ``y * x`` elementwise.\")\n\n    # TODO(beam2d): Write about as_grad_stopped(backprop_ids, copy) overload.\n    _docs.set_doc(\n        ndarray.as_grad_stopped,\n        \"\"\"as_grad_stopped(copy=False)\nCreates a view or a copy of the array that stops gradient propagation.\n\nThis method behaves similar to :meth:`view` and :meth:`copy`, except that\nthe gradient is not propagated through this operation (internally, this\nmethod creates a copy or view of the array without connecting the computational\ngraph for backprop).\n\nArgs:\n    copy (bool): If ``True``, it copies the array. Otherwise, it returns a view\n        of the original array.\n\nReturns:\n    ~chainerx.ndarray:\n        A view or a copy of the array without propagating the  gradient on\n        backprop.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.argmax,\n        \"\"\"argmax(axis=None)\nReturns the indices of the maximum elements along a given axis.\n\nSee :func:`chainerx.argmax` for the full documentation.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.astype,\n        \"\"\"astype(dtype, copy=True)\nCasts each element to the specified data type.\n\nArgs:\n    dtype: Data type of the new array.\n    copy (bool): If ``True``, this method always copies the data. Otherwise,\n        it creates a view of the array if possible.\n\nReturns:\n    ~chainerx.ndarray: An array with the specified dtype.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.backward,\n        \"\"\"backward(backprop_id=None, enable_double_backprop=False)\nPerforms backpropagation starting from this array.\n\nThis method is equivalent to ``chainerx.backward([self], *args)``.\nSee :func:`chainerx.backward` for the full documentation.\n\"\"\")\n\n    # TODO(beam2d): Write about backprop id.\n    _docs.set_doc(\n        ndarray.cleargrad,\n        \"\"\"cleargrad()\nClears the gradient held by this array.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.copy,\n        \"\"\"copy()\nCreates an array and copies all the elements to it.\n\nThe copied array is allocated on the same device as ``self``.\n\n.. seealso:: :func:`chainerx.copy`\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.dot,\n        \"\"\"dot(b)\nReturns the dot product with a given array.\n\nSee :func:`chainerx.dot` for the full documentation.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.fill,\n        \"\"\"fill(value)\nFills the array with a scalar value in place.\n\nArgs:\n    value: Scalar value with which the array will be filled.\n\"\"\")\n\n    # TODO(beam2d): Write about backprop_id argument.\n    _docs.set_doc(\n        ndarray.get_grad,\n        \"\"\"get_grad()\nReturns the gradient held by the array.\n\nIf the gradient is not available, it returns ``None``.\n\"\"\")\n\n    # TODO(beam2d): Write about backprop_id argument.\n    _docs.set_doc(\n        ndarray.is_backprop_required,\n        \"\"\"is_backprop_required()\nReturns ``True`` if gradient propagates through this array on backprop.\n\nSee the note on :meth:`require_grad` for details.\n\"\"\")\n\n    # TODO(beam2d): Write about backprop_id argument.\n    _docs.set_doc(\n        ndarray.is_grad_required,\n        \"\"\"is_grad_required()\nReturns ``True`` if the gradient will be set after backprop.\n\nSee the note on :meth:`require_grad` for details.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.item,\n        \"\"\"item()\nCopies an element of an array to a standard Python scalar and returns it.\n\nReturns:\n    z:\n        A copy of the specified element of the array as a suitable Python\n        scalar.\n\n.. seealso:: :func:`numpy.item`\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.max,\n        \"\"\"max(axis=None, keepdims=False)\nReturns the maximum along a given axis.\n\nSee :func:`chainerx.amax` for the full documentation.\n\"\"\")\n\n    # TODO(beam2d): Write about backprop_id argument.\n    _docs.set_doc(\n        ndarray.require_grad,\n        \"\"\"require_grad()\nDeclares that a gradient for this array will be made available after backprop.\n\nOnce calling this method, any operations applied to this array are recorded for\nlater backprop. After backprop, the :attr:`grad` attribute holds the gradient\narray.\n\n.. note::\n    ChainerX distinguishes *gradient requirements* and *backprop requirements*\n    strictly. They are strongly related, but different concepts as follows.\n\n    - *Gradient requirement* indicates that the gradient array should be made\n      available after backprop. This attribute **is not propagated** through\n      any operations. It implicates the backprop requirement.\n    - *Backprop requirement* indicates that the gradient should be propagated\n      through the array during backprop. This attribute **is propagated**\n      through differentiable operations.\n\n    :meth:`require_grad` sets the gradient requirement flag. If you need to\n    extract the gradient after backprop, you have to call :meth:`require_grad`\n    on the array even if the array is an intermediate result of differentiable\n    computations.\n\nReturns:\n    ~chainerx.ndarray: ``self``\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.reshape,\n        \"\"\"reshape(newshape)\nCreates an array with a new shape and the same data.\n\nSee :func:`chainerx.reshape` for the full documentation.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.set_grad,\n        \"\"\"set_grad(grad)\nSets a gradient to the array.\n\nThis method overwrites the gradient with a given array.\n\nArgs:\n    grad (~chainerx.ndarray): New gradient array.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.squeeze,\n        \"\"\"squeeze(axis=None)\nRemoves size-one axes from an array.\n\nSee :func:`chainerx.squeeze` for the full documentation.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.sum,\n        \"\"\"sum(axis=None, keepdims=False)\nReturns the sum of an array along given axes.\n\nSee :func:`chainerx.sum` for the full documentation.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.take,\n        \"\"\"take(indices, axis)\nTakes elements from the array along an axis.\n\nSee :func:`chainerx.take` for the full documentation.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.to_device,\n        \"\"\"to_device(device, index=None)\nTransfers the array to the specified device.\n\nArgs:\n    device (~chainerx.Device or str): Device to which the array is transferred,\n        or a backend name. If it is a backend name, ``index`` should also be\n        specified.\n    index (int): Index of the device for the backend specified by ``device``.\n\nReturns:\n    ~chainerx.ndarray:\n        An array on the target device.\n        If the original array is already on the device, it is a view of that.\n        Otherwise, it is a copy of the array on the target device.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.transpose,\n        \"\"\"transpose(axes=None)\nCreates a view of an array with permutated axes.\n\nSee :func:`chainerx.transpose` for the full documentation.\n\"\"\")\n\n    _docs.set_doc(\n        ndarray.view,\n        \"\"\"view()\nReturns a view of the array.\n\nThe returned array shares the underlying buffer, though it has a different\nidentity as a Python object.\n\"\"\")\n", "path": "chainerx/_docs/array.py"}]}