class_docstr: COOrdinate format sparse matrix.
  
  This can be instantiated in several ways.
  
  ``coo_matrix(D)``
      ``D`` is a rank-2 :class:`cupy.ndarray`.
  
  ``coo_matrix(S)``
      ``S`` is another sparse matrix. It is equivalent to ``S.tocoo()``.
  
  ``coo_matrix((M, N), [dtype])``
      It constructs an empty matrix whose shape is ``(M, N)``. Default dtype
      is float64.
  
  ``coo_matrix((data, (row, col)))``
      All ``data``, ``row`` and ``col`` are one-dimenaional
      :class:`cupy.ndarray`.
  
  Args:
      arg1: Arguments for the initializer.
      shape (tuple): Shape of a matrix. Its length must be two.
      dtype: Data type. It must be an argument of :class:`numpy.dtype`.
      copy (bool): If ``True``, copies of given data are always used.
  
  .. seealso::
     :class:`scipy.sparse.coo_matrix`
class_docstr_tok: ["COOrdinate","format","sparse","matrix",".","This","can","be","instantiated","in","several","ways",".","``","coo_matrix","(","D",")","``","``","D","``","is","a","rank-2",":","class",":","`","cupy.ndarray","`",".","``","coo_matrix","(","S",")","``","``","S","``","is","another","sparse","matrix",".","It","is","equivalent","to","``","S.tocoo","(",")","``",".","``","coo_matrix","(","(","M",",","N",")",",","[","dtype","]",")","``","It","constructs","an","empty","matrix","whose","shape","is","``","(","M",",","N",")","``",".","Default","dtype","is","float64",".","``","coo_matrix","(","(","data",",","(","row",",","col",")",")",")","``","All","``","data","``",",","``","row","``","and","``","col","``","are","one-dimenaional",":","class",":","`","cupy.ndarray","`",".","Args",":","arg1",":","Arguments","for","the","initializer",".","shape","(","tuple",")",":","Shape","of","a","matrix",".","Its","length","must","be","two",".","dtype",":","Data","type",".","It","must","be","an","argument","of",":","class",":","`","numpy.dtype","`",".","copy","(","bool",")",":","If","``","True","``",",","copies","of","given","data","are","always","used",".","..","seealso",":",":",":","class",":","`","scipy.sparse.coo_matrix","`"]
docstr: Eliminate duplicate matrix entries by adding them together.
  
  .. warning::
      When sorting the indices, CuPy follows the convention of cuSPARSE,
      which is different from that of SciPy. Therefore, the order of the
      output indices may differ:
  
      .. code-block:: python
  
          >>> #     1 0 0
          >>> # A = 1 1 0
          >>> #     1 1 1
          >>> data = cupy.array([1, 1, 1, 1, 1, 1], 'f')
          >>> row = cupy.array([0, 1, 1, 2, 2, 2], 'i')
          >>> col = cupy.array([0, 0, 1, 0, 1, 2], 'i')
          >>> A = cupyx.scipy.sparse.coo_matrix((data, (row, col)),
          ...                                   shape=(3, 3))
          >>> a = A.get()
          >>> A.sum_duplicates()
          >>> a.sum_duplicates()  # a is scipy.sparse.coo_matrix
          >>> A.row
          array([0, 1, 1, 2, 2, 2], dtype=int32)
          >>> a.row
          array([0, 1, 2, 1, 2, 2], dtype=int32)
          >>> A.col
          array([0, 0, 1, 0, 1, 2], dtype=int32)
          >>> a.col
          array([0, 0, 0, 1, 1, 2], dtype=int32)
  
  .. warning::
      Calling this function might synchronize the device.
  
  .. seealso::
     :meth:`scipy.sparse.coo_matrix.sum_duplicates`
docstr_tok: ["Eliminate","duplicate","matrix","entries","by","adding","them","together",".","..","warning",":",":","When","sorting","the","indices",",","CuPy","follows","the","convention","of","cuSPARSE",",","which","is","different","from","that","of","SciPy",".","Therefore",",","the","order","of","the","output","indices","may","differ",":","..","code-block",":",":","python",">",">",">","#","1","0","0",">",">",">","#","A","=","1","1","0",">",">",">","#","1","1","1",">",">",">","data","=","cupy.array","(","[","1",",","1",",","1",",","1",",","1",",","1","]",",","'","f","'",")",">",">",">","row","=","cupy.array","(","[","0",",","1",",","1",",","2",",","2",",","2","]",",","'","i","'",")",">",">",">","col","=","cupy.array","(","[","0",",","0",",","1",",","0",",","1",",","2","]",",","'","i","'",")",">",">",">","A","=","cupyx.scipy.sparse.coo_matrix","(","(","data",",","(","row",",","col",")",")",",","...","shape=","(","3",",","3",")",")",">",">",">","a","=","A.get","(",")",">",">",">","A.sum_duplicates","(",")",">",">",">","a.sum_duplicates","(",")","#","a","is","scipy.sparse.coo_matrix",">",">",">","A.row","array","(","[","0",",","1",",","1",",","2",",","2",",","2","]",",","dtype=int32",")",">",">",">","a.row","array","(","[","0",",","1",",","2",",","1",",","2",",","2","]",",","dtype=int32",")",">",">",">","A.col","array","(","[","0",",","0",",","1",",","0",",","1",",","2","]",",","dtype=int32",")",">",">",">","a.col","array","(","[","0",",","0",",","0",",","1",",","1",",","2","]",",","dtype=int32",")","..","warning",":",":","Calling","this","function","might","synchronize","the","device",".","..","seealso",":",":",":","meth",":","`","scipy.sparse.coo_matrix.sum_duplicates","`"]
code: def sum_duplicates(self):
      """Eliminate duplicate matrix entries by adding them together.
  
      .. warning::
          When sorting the indices, CuPy follows the convention of cuSPARSE,
          which is different from that of SciPy. Therefore, the order of the
          output indices may differ:
  
          .. code-block:: python
  
              >>> #     1 0 0
              >>> # A = 1 1 0
              >>> #     1 1 1
              >>> data = cupy.array([1, 1, 1, 1, 1, 1], 'f')
              >>> row = cupy.array([0, 1, 1, 2, 2, 2], 'i')
              >>> col = cupy.array([0, 0, 1, 0, 1, 2], 'i')
              >>> A = cupyx.scipy.sparse.coo_matrix((data, (row, col)),
              ...                                   shape=(3, 3))
              >>> a = A.get()
              >>> A.sum_duplicates()
              >>> a.sum_duplicates()  # a is scipy.sparse.coo_matrix
              >>> A.row
              array([0, 1, 1, 2, 2, 2], dtype=int32)
              >>> a.row
              array([0, 1, 2, 1, 2, 2], dtype=int32)
              >>> A.col
              array([0, 0, 1, 0, 1, 2], dtype=int32)
              >>> a.col
              array([0, 0, 0, 1, 1, 2], dtype=int32)
  
      .. warning::
          Calling this function might synchronize the device.
  
      .. seealso::
         :meth:`scipy.sparse.coo_matrix.sum_duplicates`
  
      """
      if self.has_canonical_format:
          return
      # Note: The sorting order below follows the cuSPARSE convention (first
      # row then col, so-called row-major) and differs from that of SciPy, as
      # the cuSPARSE functions such as cusparseSpMV() assume this sorting
      # order.
      # See https://docs.nvidia.com/cuda/cusparse/index.html#coo-format
      keys = cupy.stack([self.col, self.row])
      order = cupy.lexsort(keys)
      src_data = self.data[order]
      src_row = self.row[order]
      src_col = self.col[order]
      diff = self._sum_duplicates_diff(
          src_row, src_col, size=self.row.size
      )
  
      if diff[1:].all():
          # All elements have different indices.
          data = src_data
          row = src_row
          col = src_col
      else:
          # TODO(leofang): move the kernels outside this method
          index = cupy.cumsum(diff, dtype="i")
          size = int(index[-1]) + 1
          data = cupy.zeros(size, dtype=self.data.dtype)
          row = cupy.empty(size, dtype="i")
          col = cupy.empty(size, dtype="i")
          if self.data.dtype.kind == "b":
              cupy.ElementwiseKernel(
                  "T src_data, int32 src_row, int32 src_col, int32 index",
                  "raw T data, raw int32 row, raw int32 col",
                  """
                      if (src_data) data[index] = true;
                      row[index] = src_row;
                      col[index] = src_col;
                      """,
                  "cupyx_scipy_sparse_coo_sum_duplicates_assign",
              )(src_data, src_row, src_col, index, data, row, col)
          elif self.data.dtype.kind == "f":
              cupy.ElementwiseKernel(
                  "T src_data, int32 src_row, int32 src_col, int32 index",
                  "raw T data, raw int32 row, raw int32 col",
                  """
                      atomicAdd(&data[index], src_data);
                      row[index] = src_row;
                      col[index] = src_col;
                      """,
                  "cupyx_scipy_sparse_coo_sum_duplicates_assign",
              )(src_data, src_row, src_col, index, data, row, col)
          elif self.data.dtype.kind == "c":
              cupy.ElementwiseKernel(
                  "T src_real, T src_imag, int32 src_row, int32 src_col, "
                  "int32 index",
                  "raw T real, raw T imag, raw int32 row, raw int32 col",
                  """
                      atomicAdd(&real[index], src_real);
                      atomicAdd(&imag[index], src_imag);
                      row[index] = src_row;
                      col[index] = src_col;
                      """,
                  "cupyx_scipy_sparse_coo_sum_duplicates_assign_complex",
              )(
                  src_data.real,
                  src_data.imag,
                  src_row,
                  src_col,
                  index,
                  data.real,
                  data.imag,
                  row,
                  col,
              )
  
      self.data = data
      self.row = row
      self.col = col
      self.has_canonical_format = True
  
imports: import numpy
  import cupy
  from cupy import _core
  from cupyx.scipy.sparse import _base
  from cupyx.scipy.sparse import _csc
  from cupyx.scipy.sparse import _csr
  from cupyx.scipy.sparse import _data
  from cupyx.scipy.sparse import _util
  from cupyx.scipy.sparse import _sputils
label_desc: Use image node_id 10 for calling the coo_matrix obj's underlying member method code with example usage: obj.sum_duplicates() without return types