code: def from_coo(
      cls,
      N: int,
      src_indices: cp.ndarray[IndexValue],
      dst_indices: cp.ndarray[IndexValue],
      edge_values: dict[AttrKey, cp.ndarray[EdgeValue]] | None = None,
      edge_masks: dict[AttrKey, cp.ndarray[bool]] | None = None,
      node_values: dict[AttrKey, any_ndarray[NodeValue]] | None = None,
      node_masks: dict[AttrKey, any_ndarray[bool]] | None = None,
      *,
      key_to_id: dict[NodeKey, IndexValue] | None = None,
      id_to_key: list[NodeKey] | None = None,
      **attr,
  ) -> Graph:
      new_graph = object.__new__(cls)
      new_graph.src_indices = src_indices
      new_graph.dst_indices = dst_indices
      new_graph.edge_values = (
          {} if edge_values is None else dict(edge_values)
      )
      new_graph.edge_masks = (
          {} if edge_masks is None else dict(edge_masks)
      )
      new_graph.node_values = (
          {} if node_values is None else dict(node_values)
      )
      new_graph.node_masks = (
          {} if node_masks is None else dict(node_masks)
      )
      new_graph.key_to_id = (
          None if key_to_id is None else dict(key_to_id)
      )
      new_graph._id_to_key = (
          None if id_to_key is None else list(id_to_key)
      )
      new_graph._N = op.index(N)  # Ensure N is integral
      new_graph._node_ids = None
      new_graph.graph = new_graph.graph_attr_dict_factory()
      new_graph.graph.update(attr)
      size = new_graph.src_indices.size
      # Easy and fast sanity checks
      if size != new_graph.dst_indices.size:
          raise ValueError
      for attr in ["edge_values", "edge_masks"]:
          if datadict := getattr(new_graph, attr):
              for key, val in datadict.items():
                  if val.shape[0] != size:
                      raise ValueError(key)
      for attr in ["node_values", "node_masks"]:
          if datadict := getattr(new_graph, attr):
              for key, val in datadict.items():
                  if val.shape[0] != N:
                      raise ValueError(key)
      if (
          new_graph.key_to_id is not None
          and len(new_graph.key_to_id) != N
      ):
          raise ValueError
      if (
          new_graph._id_to_key is not None
          and len(new_graph._id_to_key) != N
      ):
          raise ValueError
      if (
          new_graph._id_to_key is not None
          and new_graph.key_to_id is None
      ):
          try:
              new_graph.key_to_id = dict(
                  zip(new_graph._id_to_key, range(N))
              )
          except TypeError as exc:
              raise ValueError("Bad type of a node value") from exc
      if new_graph.src_indices.dtype != index_dtype:
          src_indices = new_graph.src_indices.astype(index_dtype)
          if not (new_graph.src_indices == src_indices).all():
              raise ValueError(
                  f"Unable to convert src_indices to {src_indices.dtype.name} "
                  f"(got {new_graph.src_indices.dtype.name})."
              )
          new_graph.src_indices = src_indices
      if new_graph.dst_indices.dtype != index_dtype:
          dst_indices = new_graph.dst_indices.astype(index_dtype)
          if not (new_graph.dst_indices == dst_indices).all():
              raise ValueError(
                  f"Unable to convert dst_indices to {dst_indices.dtype.name} "
                  f"(got {new_graph.dst_indices.dtype.name})."
              )
          new_graph.dst_indices = dst_indices
  
      # If the graph contains isolates, plc.SGGraph() must be passed a value
      # for vertices_array that contains every vertex ID, since the
      # src/dst_indices arrays will not contain IDs for isolates. Create this
      # only if needed. Like src/dst_indices, the _node_ids array must be
      # maintained for the lifetime of the plc.SGGraph
      isolates = nxcg.algorithms.isolate._isolates(new_graph)
      if len(isolates) > 0:
          new_graph._node_ids = cp.arange(
              new_graph._N, dtype=index_dtype
          )
  
      return new_graph
  
imports: from __future__ import annotations
  import operator
  from copy import deepcopy
  from typing import TYPE_CHECKING
  import cupy
  import networkx
  import numpy
  import pylibcugraph
  import nx_cugraph
  from ..utils import index_dtype
label_desc: Use image node_id 1 for calling the Graph obj's underlying member method code with example usage: obj.from_coo(cls, N, src_indices, dst_indices, edge_values, edge_masks, node_values, node_masks) and returns: new_graph