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: Set diagonal or off-diagonal elements of the array.
  
  Args:
      values (ndarray): New values of the diagonal elements. Values may
          have any length. If the diagonal is longer than values, then
          the remaining diagonal entries will not be set. If values are
          longer than the diagonal, then the remaining values are
          ignored. If a scalar value is given, all of the diagonal is set
          to it.
      k (int, optional): Which off-diagonal to set, corresponding to
          elements a[i,i+k]. Default: 0 (the main diagonal).
docstr_tok: ["Set","diagonal","or","off-diagonal","elements","of","the","array",".","Args",":","values","(","ndarray",")",":","New","values","of","the","diagonal","elements",".","Values","may","have","any","length",".","If","the","diagonal","is","longer","than","values",",","then","the","remaining","diagonal","entries","will","not","be","set",".","If","values","are","longer","than","the","diagonal",",","then","the","remaining","values","are","ignored",".","If","a","scalar","value","is","given",",","all","of","the","diagonal","is","set","to","it",".","k","(","int",",","optional",")",":","Which","off-diagonal","to","set",",","corresponding","to","elements","a","[","i",",","i+k","]",".","Default",":","0","(","the","main","diagonal",")","."]
code: def setdiag(self, values, k=0):
      """Set diagonal or off-diagonal elements of the array.
  
      Args:
          values (ndarray): New values of the diagonal elements. Values may
              have any length. If the diagonal is longer than values, then
              the remaining diagonal entries will not be set. If values are
              longer than the diagonal, then the remaining values are
              ignored. If a scalar value is given, all of the diagonal is set
              to it.
          k (int, optional): Which off-diagonal to set, corresponding to
              elements a[i,i+k]. Default: 0 (the main diagonal).
  
      """
      M, N = self.shape
      if (k > 0 and k >= N) or (k < 0 and -k >= M):
          raise ValueError("k exceeds matrix dimensions")
      if values.ndim and not len(values):
          return
      idx_dtype = self.row.dtype
  
      # Determine which triples to keep and where to put the new ones.
      full_keep = self.col - self.row != k
      if k < 0:
          max_index = min(M + k, N)
          if values.ndim:
              max_index = min(max_index, len(values))
          keep = cupy.logical_or(full_keep, self.col >= max_index)
          new_row = cupy.arange(-k, -k + max_index, dtype=idx_dtype)
          new_col = cupy.arange(max_index, dtype=idx_dtype)
      else:
          max_index = min(M, N - k)
          if values.ndim:
              max_index = min(max_index, len(values))
          keep = cupy.logical_or(full_keep, self.row >= max_index)
          new_row = cupy.arange(max_index, dtype=idx_dtype)
          new_col = cupy.arange(k, k + max_index, dtype=idx_dtype)
  
      # Define the array of data consisting of the entries to be added.
      if values.ndim:
          new_data = values[:max_index]
      else:
          new_data = cupy.full(max_index, values, dtype=self.dtype)
  
      # Update the internal structure.
      self.row = cupy.concatenate((self.row[keep], new_row))
      self.col = cupy.concatenate((self.col[keep], new_col))
      self.data = cupy.concatenate((self.data[keep], new_data))
      self.has_canonical_format = False
  
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 4 for calling the coo_matrix obj's underlying member method code with example usage: obj.setdiag(values, k) without return types