<commit_before>import chainerx
from chainerx import _docs


def set_docs():
    ndarray = chainerx.ndarray

    _docs.set_doc(
        ndarray,
        """ndarray(shape, dtype, device=None)
Multi-dimensional array, the central data structure of ChainerX.

This class, along with other APIs in the :mod:`chainerx` module, provides a
subset of NumPy APIs. This class works similar to :class:`numpy.ndarray`,
except for some differences including the following noticeable points:

- :class:`chainerx.ndarray` has a :attr:`device` attribute. It indicates on
  which device the array is allocated.
- :class:`chainerx.ndarray` supports :ref:`Define-by-Run <define_by_run>`
  backpropagation. Once you call :meth:`require_grad`, the array starts
  recording the operations applied to it recursively. Gradient of the result
  with respect to the original array can be computed then with the
  :meth:`backward` method or the :func:`chainerx.backward` function.

Args:
    shape (tuple of ints): Shape of the new array.
    dtype: Data type.
    device (~chainerx.Device): Device on which the array is allocated.
        If omitted, :ref:`the default device <chainerx_device>` is chosen.

.. seealso:: :class:`numpy.ndarray`
""")

    _docs.set_doc(
        ndarray.data_ptr,
        """int: Address of the underlying memory allocation.

The meaning of the address is device-dependent.
""")

    _docs.set_doc(
        ndarray.data_size,
        "int: Total size of the underlying memory allocation.")

    _docs.set_doc(
        ndarray.device, "~chainerx.Device: Device on which the data exists.")

    _docs.set_doc(ndarray.dtype, "Data type of the array.")

    # TODO(beam2d): Write about backprop id.
    _docs.set_doc(
        ndarray.grad,
        """~chainerx.ndarray: Gradient with respect to the array.

It is ``None`` if the gradient is not available.
Setter of this property overwrites the gradient.
""")

    _docs.set_doc(
        ndarray.is_contiguous,
        "bool: ``True`` iff the array is stored in the C-contiguous order.")

    _docs.set_doc(ndarray.itemsize, "int: Size of each element in bytes.")

    _docs.set_doc(
        ndarray.nbytes,
        """int: Size of whole elements in bytes.

It does not count skips between elements.""")

    _docs.set_doc(ndarray.ndim, "int: Number of dimensions.")

    _docs.set_doc(
        ndarray.offset,
        "int: Offset of the first element from the memory allocation in bytes."
    )

    _docs.set_doc(
        ndarray.shape,
        """tuple of int: Lengths of axes.

Currently, this property does not support setter.""")

    _docs.set_doc(ndarray.size, "int: Number of elements in the array.")

    _docs.set_doc(ndarray.strides, "tuple of int: Strides of axes in bytes.")

    _docs.set_doc(
        ndarray.T,
        """~chainerx.ndarray: Shape-reversed view of the array.

New array is created at every access to this property.
``x.T`` is just a shorthand of ``x.transpose()``.
""")

    def unary_op(name, s):
        _docs.set_doc(getattr(ndarray, name), "{}()\n{}".format(name, s))

    unary_op("__bool__", "Casts a size-one array into a :class:`bool` value.")
    unary_op("__float__",
             "Casts a size-one array into a :class:`float` value.")
    unary_op("__int__", "Casts a size-one array into :class:`int` value.")
    unary_op("__len__", "Returns the length of the first axis.")
    unary_op("__neg__", "Computes ``-x`` elementwise.")

    def binary_op(name, s):
        _docs.set_doc(getattr(ndarray, name), "{}(other)\n{}".format(name, s))

    binary_op("__eq__", "Computes ``x == y`` elementwise.")
    binary_op("__ne__", "Computes ``x != y`` elementwise.")
    binary_op("__lt__", "Computes ``x < y`` elementwise.")
    binary_op("__le__", "Computes ``x <= y`` elementwise.")
    binary_op("__ge__", "Computes ``x >= y`` elementwise.")
    binary_op("__gt__", "Computes ``x > y`` elementwise.")

    binary_op("__iadd__", "Computes ``x += y`` elementwise.")
    binary_op("__isub__", "Computes ``x -= y`` elementwise.")
    binary_op("__imul__", "Computes ``x *= y`` elementwise.")
    binary_op("__itruediv__", "Computes ``x /= y`` elementwise.")

    binary_op("__add__", "Computes ``x + y`` elementwise.")
    binary_op("__sub__", "Computes ``x - y`` elementwise.")
    binary_op("__mul__", "Computes ``x * y`` elementwise.")
    binary_op("__truediv__", "Computes ``x / y`` elementwise.")

    binary_op("__radd__", "Computes ``y + x`` elementwise.")
    binary_op("__rsub__", "Computes ``y - x`` elementwise.")
    binary_op("__rmul__", "Computes ``y * x`` elementwise.")

    _docs.set_doc(
        ndarray.__getitem__,
        """__getitem__(slices)
Creates a view into a slice of the array.

The following values are currently supported for indexing.

- Integers
- :class:`slice` objects
- ``None`` (or ``numpy.newaxis``)

Combination of these values can be specified at once for indexing over multiple
axes.
""")

    # TODO(beam2d): Write about as_grad_stopped(backprop_ids, copy) overload.
    _docs.set_doc(
        ndarray.as_grad_stopped,
        """as_grad_stopped(copy=False)
Creates a view or a copy of the array with stopping gradient propagation.

This method behaves similar to :meth:`view` and :meth:`copy`, except that
the gradient is not propagated through this operation.

Args:
    copy (bool): If ``True``, it copies the array. Otherwise, it returns a view
        of the original array.
<commit_msg>Remove __getitem__ documentation from _docs/array.py<commit_after>import chainerx
from chainerx import _docs


def set_docs():
    ndarray = chainerx.ndarray

    _docs.set_doc(
        ndarray,
        """ndarray(shape, dtype, device=None)
Multi-dimensional array, the central data structure of ChainerX.

This class, along with other APIs in the :mod:`chainerx` module, provides a
subset of NumPy APIs. This class works similar to :class:`numpy.ndarray`,
except for some differences including the following noticeable points:

- :class:`chainerx.ndarray` has a :attr:`device` attribute. It indicates on
  which device the array is allocated.
- :class:`chainerx.ndarray` supports :ref:`Define-by-Run <define_by_run>`
  backpropagation. Once you call :meth:`require_grad`, the array starts
  recording the operations applied to it recursively. Gradient of the result
  with respect to the original array can be computed then with the
  :meth:`backward` method or the :func:`chainerx.backward` function.

Args:
    shape (tuple of ints): Shape of the new array.
    dtype: Data type.
    device (~chainerx.Device): Device on which the array is allocated.
        If omitted, :ref:`the default device <chainerx_device>` is chosen.

.. seealso:: :class:`numpy.ndarray`
""")

    _docs.set_doc(
        ndarray.data_ptr,
        """int: Address of the underlying memory allocation.

The meaning of the address is device-dependent.
""")

    _docs.set_doc(
        ndarray.data_size,
        "int: Total size of the underlying memory allocation.")

    _docs.set_doc(
        ndarray.device, "~chainerx.Device: Device on which the data exists.")

    _docs.set_doc(ndarray.dtype, "Data type of the array.")

    # TODO(beam2d): Write about backprop id.
    _docs.set_doc(
        ndarray.grad,
        """~chainerx.ndarray: Gradient with respect to the array.

It is ``None`` if the gradient is not available.
Setter of this property overwrites the gradient.
""")

    _docs.set_doc(
        ndarray.is_contiguous,
        "bool: ``True`` iff the array is stored in the C-contiguous order.")

    _docs.set_doc(ndarray.itemsize, "int: Size of each element in bytes.")

    _docs.set_doc(
        ndarray.nbytes,
        """int: Size of whole elements in bytes.

It does not count skips between elements.""")

    _docs.set_doc(ndarray.ndim, "int: Number of dimensions.")

    _docs.set_doc(
        ndarray.offset,
        "int: Offset of the first element from the memory allocation in bytes."
    )

    _docs.set_doc(
        ndarray.shape,
        """tuple of int: Lengths of axes.

Currently, this property does not support setter.""")

    _docs.set_doc(ndarray.size, "int: Number of elements in the array.")

    _docs.set_doc(ndarray.strides, "tuple of int: Strides of axes in bytes.")

    _docs.set_doc(
        ndarray.T,
        """~chainerx.ndarray: Shape-reversed view of the array.

New array is created at every access to this property.
``x.T`` is just a shorthand of ``x.transpose()``.
""")

    def unary_op(name, s):
        _docs.set_doc(getattr(ndarray, name), "{}()\n{}".format(name, s))

    unary_op("__bool__", "Casts a size-one array into a :class:`bool` value.")
    unary_op("__float__",
             "Casts a size-one array into a :class:`float` value.")
    unary_op("__int__", "Casts a size-one array into :class:`int` value.")
    unary_op("__len__", "Returns the length of the first axis.")
    unary_op("__neg__", "Computes ``-x`` elementwise.")

    def binary_op(name, s):
        _docs.set_doc(getattr(ndarray, name), "{}(other)\n{}".format(name, s))

    binary_op("__eq__", "Computes ``x == y`` elementwise.")
    binary_op("__ne__", "Computes ``x != y`` elementwise.")
    binary_op("__lt__", "Computes ``x < y`` elementwise.")
    binary_op("__le__", "Computes ``x <= y`` elementwise.")
    binary_op("__ge__", "Computes ``x >= y`` elementwise.")
    binary_op("__gt__", "Computes ``x > y`` elementwise.")

    binary_op("__iadd__", "Computes ``x += y`` elementwise.")
    binary_op("__isub__", "Computes ``x -= y`` elementwise.")
    binary_op("__imul__", "Computes ``x *= y`` elementwise.")
    binary_op("__itruediv__", "Computes ``x /= y`` elementwise.")

    binary_op("__add__", "Computes ``x + y`` elementwise.")
    binary_op("__sub__", "Computes ``x - y`` elementwise.")
    binary_op("__mul__", "Computes ``x * y`` elementwise.")
    binary_op("__truediv__", "Computes ``x / y`` elementwise.")

    binary_op("__radd__", "Computes ``y + x`` elementwise.")
    binary_op("__rsub__", "Computes ``y - x`` elementwise.")
    binary_op("__rmul__", "Computes ``y * x`` elementwise.")

    # TODO(beam2d): Write about as_grad_stopped(backprop_ids, copy) overload.
    _docs.set_doc(
        ndarray.as_grad_stopped,
        """as_grad_stopped(copy=False)
Creates a view or a copy of the array with stopping gradient propagation.

This method behaves similar to :meth:`view` and :meth:`copy`, except that
the gradient is not propagated through this operation.

Args:
    copy (bool): If ``True``, it copies the array. Otherwise, it returns a view
        of the original array.

{'fraction_non_alphanumeric': 0.132093376352249, 'fraction_numerical': 0.0003795786676788764, 'mean_word_length': 3.507698887938409, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4517409', 'n_tokens_mistral': 3443, 'n_tokens_neox': 3337, 'n_words': 1084}