code: def disjoint_adjacency_to_batch(A, I):
      """
      Converts a disjoint adjacency matrix to batch node by zero-padding.
  
      :param A: Tensor, binary adjacency matrix of shape `(n_nodes, n_nodes)`;
      :param I: Tensor, graph IDs of shape `(n_nodes, )`;
      :return: Tensor, batched adjacency matrix of shape `(batch, N_max, N_max)`;
      """
      I = tf.cast(I, tf.int64)
      indices = A.indices
      values = A.values
      i_nodes, j_nodes = indices[:, 0], indices[:, 1]
  
      graph_sizes = tf.math.segment_sum(tf.ones_like(I), I)
      max_n_nodes = tf.reduce_max(graph_sizes)
      n_graphs = tf.shape(graph_sizes)[0]
  
      offset = tf.gather(I, i_nodes)
      offset = tf.gather(tf.cumsum(graph_sizes, exclusive=True), offset)
  
      relative_j_nodes = j_nodes - offset
      relative_i_nodes = i_nodes - offset
  
      spaced_i_nodes = (
          tf.gather(I, i_nodes) * max_n_nodes + relative_i_nodes
      )
      new_indices = tf.transpose(
          tf.stack([spaced_i_nodes, relative_j_nodes])
      )
  
      n_graphs = tf.cast(n_graphs, new_indices.dtype)
      max_n_nodes = tf.cast(max_n_nodes, new_indices.dtype)
  
      dense_adjacency = tf.scatter_nd(
          new_indices, values, (n_graphs * max_n_nodes, max_n_nodes)
      )
      batch = tf.reshape(
          dense_adjacency, (n_graphs, max_n_nodes, max_n_nodes)
      )
  
      return batch
  
imports: import tensorflow
  from tensorflow.keras import backend
label_desc: Use image node_id 2 for calling a global function with example usage: disjoint_adjacency_to_batch(A, I) and returns: batch