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","`"]
code: def __init__(self, arg1, shape=None, dtype=None, copy=False):
      if shape is not None and len(shape) != 2:
          raise ValueError(
              "Only two-dimensional sparse arrays are supported."
          )
  
      if _base.issparse(arg1):
          x = arg1.asformat(self.format)
          data = x.data
          row = x.row
          col = x.col
  
          if arg1.format != self.format:
              # When formats are differnent, all arrays are already copied
              copy = False
  
          if shape is None:
              shape = arg1.shape
  
          self.has_canonical_format = x.has_canonical_format
  
      elif _util.isshape(arg1):
          m, n = arg1
          m, n = int(m), int(n)
          data = cupy.zeros(0, dtype if dtype else "d")
          row = cupy.zeros(0, dtype="i")
          col = cupy.zeros(0, dtype="i")
          # shape and copy argument is ignored
          shape = (m, n)
          copy = False
  
          self.has_canonical_format = True
  
      elif _scipy_available and scipy.sparse.issparse(arg1):
          # Convert scipy.sparse to cupyx.scipy.sparse
          x = arg1.tocoo()
          data = cupy.array(x.data)
          row = cupy.array(x.row, dtype="i")
          col = cupy.array(x.col, dtype="i")
          copy = False
          if shape is None:
              shape = arg1.shape
  
          self.has_canonical_format = x.has_canonical_format
  
      elif isinstance(arg1, tuple) and len(arg1) == 2:
          try:
              data, (row, col) = arg1
          except (TypeError, ValueError):
              raise TypeError("invalid input format")
  
          if not (
              _base.isdense(data)
              and data.ndim == 1
              and _base.isdense(row)
              and row.ndim == 1
              and _base.isdense(col)
              and col.ndim == 1
          ):
              raise ValueError(
                  "row, column, and data arrays must be 1-D"
              )
          if not (len(data) == len(row) == len(col)):
              raise ValueError(
                  "row, column, and data array must all be the same length"
              )
  
          self.has_canonical_format = False
  
      elif _base.isdense(arg1):
          if arg1.ndim > 2:
              raise TypeError("expected dimension <= 2 array or matrix")
          dense = cupy.atleast_2d(arg1)
          row, col = dense.nonzero()
          data = dense[row, col]
          shape = dense.shape
  
          self.has_canonical_format = True
  
      else:
          raise TypeError("invalid input format")
  
      if dtype is None:
          dtype = data.dtype
      else:
          dtype = numpy.dtype(dtype)
  
      if dtype not in (
          numpy.bool_,
          numpy.float32,
          numpy.float64,
          numpy.complex64,
          numpy.complex128,
      ):
          raise ValueError(
              "Only bool, float32, float64, complex64 and complex128"
              " are supported"
          )
  
      data = data.astype(dtype, copy=copy)
      row = row.astype("i", copy=copy)
      col = col.astype("i", copy=copy)
  
      if shape is None:
          if len(row) == 0 or len(col) == 0:
              raise ValueError(
                  "cannot infer dimensions from zero sized index arrays"
              )
          shape = (int(row.max()) + 1, int(col.max()) + 1)
  
      if len(data) > 0:
          if row.max() >= shape[0]:
              raise ValueError("row index exceeds matrix dimensions")
          if col.max() >= shape[1]:
              raise ValueError("column index exceeds matrix dimensions")
          if row.min() < 0:
              raise ValueError("negative row index found")
          if col.min() < 0:
              raise ValueError("negative column index found")
  
      sparse_data._data_matrix.__init__(self, data)
      self.row = row
      self.col = col
      if not _util.isshape(shape):
          raise ValueError("invalid shape (must be a 2-tuple of int)")
      self._shape = int(shape[0]), int(shape[1])
  
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 1 to create a new coo_matrix object from inherited base classes: sparse_data with example: obj = coo_matrix(arg1, shape, dtype, copy)