code: def graphdata2tensors(data, idtype=None, bipartite=False, **kwargs):
      """Function to convert various types of data to edge tensors and infer
      the number of nodes.
  
      Parameters
      ----------
      data : graph data
          Various kinds of graph data.  Possible data types are:
  
          - ``(row, col)``
          - ``('coo', (row, col))``
          - ``('csr', (indptr, indices, edge_ids))``
          - ``('csc', (indptr, indices, edge_ids))``
          - SciPy sparse matrix
          - NetworkX graph
      idtype : int32, int64, optional
          Integer ID type. If None, try infer from the data and if fail use
          int64.
      bipartite : bool, optional
          Whether infer number of nodes of a bipartite graph --
          num_src and num_dst can be different.
      kwargs
  
          - edge_id_attr_name : The name (str) of the edge attribute that stores the edge
            IDs in the NetworkX graph.
          - top_map : The dictionary mapping the original IDs of the source nodes to the
            new ones.
          - bottom_map : The dictionary mapping the original IDs of the destination nodes
            to the new ones.
  
      Returns
      -------
      data : SparseAdjTuple
          A tuple with the sparse matrix format and the adjacency matrix tensors.
      num_src : int
          Number of source nodes.
      num_dst : int
          Number of destination nodes.
      """
      # Convert tuple to SparseAdjTuple
      if isinstance(data, tuple):
          if not isinstance(data[0], str):
              # (row, col) format, convert to ('coo', (row, col))
              data = ("coo", data)
          data = SparseAdjTuple(*data)
  
      if idtype is None and not (
          isinstance(data, SparseAdjTuple)
          and F.is_tensor(data.arrays[0])
      ):
          # preferred default idtype is int64
          # if data is tensor and idtype is None, infer the idtype from tensor
          idtype = F.int64
      checks.check_valid_idtype(idtype)
  
      if isinstance(data, SparseAdjTuple) and (
          not all(F.is_tensor(a) for a in data.arrays)
      ):
          # (Iterable, Iterable) type data, convert it to (Tensor, Tensor)
          if len(data.arrays[0]) == 0:
              # force idtype for empty list
              data = SparseAdjTuple(
                  data.format,
                  tuple(F.tensor(a, idtype) for a in data.arrays),
              )
          else:
              # convert the iterable to tensor and keep its native data type so we can check
              # its validity later
              data = SparseAdjTuple(
                  data.format, tuple(F.tensor(a) for a in data.arrays)
              )
  
      if isinstance(data, SparseAdjTuple):
          if idtype is not None:
              data = SparseAdjTuple(
                  data.format,
                  tuple(F.astype(a, idtype) for a in data.arrays),
              )
          num_src, num_dst = infer_num_nodes(data, bipartite=bipartite)
      elif isinstance(data, list):
          src, dst = elist2tensor(data, idtype)
          data = SparseAdjTuple("coo", (src, dst))
          num_src, num_dst = infer_num_nodes(data, bipartite=bipartite)
      elif isinstance(data, sp.sparse.spmatrix):
          # We can get scipy matrix's number of rows and columns easily.
          num_src, num_dst = infer_num_nodes(data, bipartite=bipartite)
          data = scipy2tensor(data, idtype)
      elif isinstance(data, nx.Graph):
          # We can get networkx graph's number of sources and destinations easily.
          num_src, num_dst = infer_num_nodes(data, bipartite=bipartite)
          edge_id_attr_name = kwargs.get("edge_id_attr_name", None)
          if bipartite:
              top_map = kwargs.get("top_map")
              bottom_map = kwargs.get("bottom_map")
              src, dst = networkxbipartite2tensors(
                  data,
                  idtype,
                  top_map=top_map,
                  bottom_map=bottom_map,
                  edge_id_attr_name=edge_id_attr_name,
              )
          else:
              src, dst = networkx2tensor(
                  data, idtype, edge_id_attr_name=edge_id_attr_name
              )
          data = SparseAdjTuple("coo", (src, dst))
      else:
          raise DGLError("Unsupported graph data type:", type(data))
  
      return data, num_src, num_dst
  
file_path: dgl/python/dgl/utils/data.py
imports: from collections import namedtuple
  import networkx
  import scipy
  from ..None import backend
  from ..base import DGLError
  from .None import checks
label_desc: Use image node_id 4 for calling a global function with example usage: graphdata2tensors(data, idtype, bipartite) and returns: data,  num_src,  num_dst