code: def _incidence_matrix_single(triangular_adjacency, *, num_edges):
      """
      Creates the corresponding incidence matrix for a graph with a particular
      adjacency matrix.
  
      :param triangular_adjacency: The binary adjacency matrix. Should have shape
          (n_nodes, n_nodes), and be triangular.
      :param num_edges: The number of edges to use in the output. Should be large
          enough to accommodate all the edges in the adjacency matrix.
  
      :return: The computed incidence matrix. It will have a shape of
          (n_nodes, n_edges).
      """
      # The adjacency matrix should be sparse, so get the indices of the edges.
      connected_node_indices = tf.where(triangular_adjacency)
  
      # Match each edge with one of the nodes connected by that edge. We refer
      # to the two nodes connected by each edge as "right" and "left",
      # for convenience.
      edge_indices = tf.range(
          connected_node_indices.shape[0], dtype=tf.int64
      )
      edges_with_left_nodes = tf.stack(
          [connected_node_indices[:, 0], edge_indices], axis=1
      )
      edges_with_right_nodes = tf.stack(
          [connected_node_indices[:, 1], edge_indices], axis=1
      )
  
      # We now have all the points that should go in the sparse binary
      # transformation matrix.
      edge_indicators = tf.ones_like(edge_indices, dtype=tf.float32)
      num_nodes = tf.cast(tf.shape(triangular_adjacency)[0], tf.int64)
      output_shape = tf.stack([num_nodes, num_edges])
      left_sparse = tf.SparseTensor(
          indices=edges_with_left_nodes,
          values=edge_indicators,
          dense_shape=output_shape,
      )
      left_sparse = tf.sparse.reorder(left_sparse)
      right_sparse = tf.SparseTensor(
          indices=edges_with_right_nodes,
          values=edge_indicators,
          dense_shape=output_shape,
      )
      right_sparse = tf.sparse.reorder(right_sparse)
      # Combine the matrices for the left and right nodes.
      combined_sparse = tf.sparse.maximum(left_sparse, right_sparse)
  
      return tf.sparse.to_dense(combined_sparse)
  
imports: import copy
  import warnings
  from functools import partial
  import numpy
  import tensorflow
  from scipy import linalg
  from scipy import sparse
  from scipy.sparse.linalg import ArpackNoConvergence
label_desc: Use image node_id 9 for calling a global function with example usage: _incidence_matrix_single(triangular_adjacency) and returns: tf