def get_graph(input_graphs, index, name="get_graph"):
  """Indexes into a graph.

  Given a `graphs.graphsTuple` containing `Tensor`s and an index (either
  an `int` or a `slice`), index into the nodes, edges and globals to extract the
  graphs specified by the slice, and returns them into an another instance of a
  `graphs.graphsTuple` containing `Tensor`s.

  Args:
    input_graphs: A `graphs.GraphsTuple` containing `Tensor`s.
    index: An `int`, a `slice`, a tensor `int` or a tensor `slice`, to index
      into `graph`. `index` should be compatible with the number of graphs in
      `graphs`. The `step` parameter of the `slice` objects must be None.
    name: (string, optional) A name for the operation.

  Returns:
    A `graphs.GraphsTuple` containing `Tensor`s, made of the extracted
      graph(s).

  Raises:
    TypeError: if `index` is not an `int`, a `slice`, or corresponding tensor
      types.
    ValueError: if `index` is a slice and `index.step` if not None.
  """

  def safe_slice_none(value, slice_):
    if value is None:
      return value
    return value[slice_]

  if isinstance(index, (int, tf.Tensor)):
    _check_valid_index(index, "index")
    graph_slice = slice(index, index + 1)
  elif (isinstance(index, slice) and
        _check_valid_index(index.stop, "index.stop") and
        (index.start is None or _check_valid_index(
            index.start, "index.start"))):
    if index.step is not None:
      raise ValueError("slices with step/stride are not supported, got {}"
                       .format(index))
    graph_slice = index
  else:
    raise TypeError(
        "unsupported index type got {} with type {}. Index must be a valid "
        "scalar integer (tensor or int) or a slice of such values."
        .format(index, type(index)))

  start_slice = slice(0, graph_slice.start)

  with tf.name_scope(name):
    start_node_index = tf.reduce_sum(
        input_graphs.n_node[start_slice], name="start_node_index")
    start_edge_index = tf.reduce_sum(
        input_graphs.n_edge[start_slice], name="start_edge_index")
    end_node_index = start_node_index + tf.reduce_sum(
        input_graphs.n_node[graph_slice], name="end_node_index")
    end_edge_index = start_edge_index + tf.reduce_sum(
        input_graphs.n_edge[graph_slice], name="end_edge_index")
    nodes_slice = slice(start_node_index, end_node_index)
    edges_slice = slice(start_edge_index, end_edge_index)

    sliced_graphs_dict = {}

    for field in set(GRAPH_NUMBER_FIELDS) | {"globals"}:
      sliced_graphs_dict[field] = safe_slice_none(
          getattr(input_graphs, field), graph_slice)

    field = "nodes"
    sliced_graphs_dict[field] = safe_slice_none(
        getattr(input_graphs, field), nodes_slice)

    for field in {"edges", "senders", "receivers"}:
      sliced_graphs_dict[field] = safe_slice_none(
          getattr(input_graphs, field), edges_slice)
      if (field in {"senders", "receivers"} and
          sliced_graphs_dict[field] is not None):
        sliced_graphs_dict[field] = sliced_graphs_dict[field] - start_node_index

    return graphs.GraphsTuple(**sliced_graphs_dict)
Indexes into a graph.

  Given a `graphs.graphsTuple` containing `Tensor`s and an index (either
  an `int` or a `slice`), index into the nodes, edges and globals to extract the
  graphs specified by the slice, and returns them into an another instance of a
  `graphs.graphsTuple` containing `Tensor`s.

  Args:
    input_graphs: A `graphs.GraphsTuple` containing `Tensor`s.
    index: An `int`, a `slice`, a tensor `int` or a tensor `slice`, to index
      into `graph`. `index` should be compatible with the number of graphs in
      `graphs`. The `step` parameter of the `slice` objects must be None.
    name: (string, optional) A name for the operation.

  Returns:
    A `graphs.GraphsTuple` containing `Tensor`s, made of the extracted
      graph(s).

  Raises:
    TypeError: if `index` is not an `int`, a `slice`, or corresponding tensor
      types.
    ValueError: if `index` is a slice and `index.step` if not None.
  
graph_nets/utils_tf.py