code: def histogram(x, bins=10, range=None, weights=None, density=False):
      """Computes the histogram of a set of data.
  
      Args:
          x (cupy.ndarray): Input array.
          bins (int or cupy.ndarray): If ``bins`` is an int, it represents the
              number of bins. If ``bins`` is an :class:`~cupy.ndarray`, it
              represents a bin edges.
          range (2-tuple of float, optional): The lower and upper range of the
              bins.  If not provided, range is simply ``(x.min(), x.max())``.
              Values outside the range are ignored. The first element of the
              range must be less than or equal to the second. `range` affects the
              automatic bin computation as well. While bin width is computed to
              be optimal based on the actual data within `range`, the bin count
              will fill the entire range including portions containing no data.
          density (bool, optional): If False, the default, returns the number of
              samples in each bin. If True, returns the probability *density*
              function at the bin, ``bin_count / sample_count / bin_volume``.
          weights (cupy.ndarray, optional): An array of weights, of the same
              shape as `x`.  Each value in `x` only contributes its associated
              weight towards the bin count (instead of 1).
      Returns:
          tuple: ``(hist, bin_edges)`` where ``hist`` is a :class:`cupy.ndarray`
          storing the values of the histogram, and ``bin_edges`` is a
          :class:`cupy.ndarray` storing the bin edges.
  
      .. warning::
  
          This function may synchronize the device.
  
      .. seealso:: :func:`numpy.histogram`
      """
  
      if x.dtype.kind == "c":
          # TODO(unno): comparison between complex numbers is not implemented
          raise NotImplementedError("complex number is not supported")
  
      if not isinstance(x, cupy.ndarray):
          raise ValueError("x must be a cupy.ndarray")
  
      x, weights = _ravel_and_check_weights(x, weights)
      bin_edges = _get_bin_edges(x, bins, range)
  
      if weights is None:
          y = cupy.zeros(bin_edges.size - 1, dtype=cupy.int64)
          # TODO(leofang): we temporarily remove CUB histogram support for now,
          # see cupy/cupy#7698. When it's ready, revert the commit that checked
          # in this comment to restore the support.
          _histogram_kernel(x, bin_edges, bin_edges.size, y)
      else:
          simple_weights = cupy.can_cast(
              weights.dtype, cupy.float64
          ) or cupy.can_cast(weights.dtype, cupy.complex128)
          if not simple_weights:
              # object dtype such as Decimal are supported in NumPy, but not here
              raise NotImplementedError(
                  "only weights with dtype that can be cast to float or complex "
                  "are supported"
              )
          if weights.dtype.kind == "c":
              y = cupy.zeros(bin_edges.size - 1, dtype=cupy.complex128)
              _weighted_histogram_kernel(
                  x, bin_edges, bin_edges.size, weights.real, y.real
              )
              _weighted_histogram_kernel(
                  x, bin_edges, bin_edges.size, weights.imag, y.imag
              )
          else:
              if weights.dtype.kind in "bui":
                  y = cupy.zeros(bin_edges.size - 1, dtype=int)
              else:
                  y = cupy.zeros(bin_edges.size - 1, dtype=cupy.float64)
              _weighted_histogram_kernel(
                  x, bin_edges, bin_edges.size, weights, y
              )
  
      if density:
          db = cupy.array(cupy.diff(bin_edges), cupy.float64)
          return y / db / y.sum(), bin_edges
      return y, bin_edges
  
file_path: cupy/cupy/_statistics/histogram.py
imports: import operator
  import warnings
  import numpy
  import cupy
  from cupy import _core
label_desc: Use image node_id 4 for calling a global function with example usage: histogram(x, bins, range, weights, density) and returns: y,  bin_edges, unknown,  bin_edges