class_docstr: An approximation method to deal with intractably
  large size of graph tuning problem.
  
  This graph coloring algorithm mainly comes from:
  
  Lang Hames and Bernhard Scholz.
  Nearly optimal register allocation with pbqp.JMLC 2006.
  LNCS, vol.4228,pp. 346-361, 2016
class_docstr_tok: ["An","approximation","method","to","deal","with","intractably","large","size","of","graph","tuning","problem",".","This","graph","coloring","algorithm","mainly","comes","from",":","Lang","Hames","and","Bernhard","Scholz",".","Nearly","optimal","register","allocation","with","pbqp.JMLC","2006",".","LNCS",",","vol.4228",",","pp",".","346-361",",","2016"]
docstr: Reduce nodes with degree 2.
docstr_tok: ["Reduce","nodes","with","degree","2","."]
code: def _RII_reduction(self, node_idx):
      """Reduce nodes with degree 2."""
      adj_node_x, adj_node_y = self._adj_dict[node_idx]
      ltf_matrix_x = self._layout_transform_interlayer_cost[
          (adj_node_x, node_idx)
      ]
      ltf_matrix_y = self._layout_transform_interlayer_cost[
          (adj_node_y, node_idx)
      ]
      delta_matrix = [[] for _ in range(len(ltf_matrix_x))]
      for i, cost_vec_x in enumerate(ltf_matrix_x):
          for j, cost_vec_y in enumerate(ltf_matrix_y):
              min_cost = INVALID_LAYOUT_TIME
              for k in range(len(self._record_cost_dict[node_idx])):
                  min_cost = min(
                      min_cost,
                      cost_vec_x[k]
                      + cost_vec_y[k]
                      + self._record_cost_dict[node_idx][k],
                  )
              delta_matrix[i].append(min_cost)
  
      if adj_node_x == adj_node_y:
          for i, delta_row in enumerate(delta_matrix):
              self._record_cost_dict[adj_node_x][i] += delta_row[i]
      elif adj_node_x in self._adj_dict[adj_node_y]:
          for i, _ in enumerate(delta_matrix):
              for j, delta in enumerate(delta_matrix[i]):
                  self._layout_transform_interlayer_cost[
                      (adj_node_x, adj_node_y)
                  ][i][j] += delta
                  self._layout_transform_interlayer_cost[
                      (adj_node_y, adj_node_x)
                  ][j][i] += delta
      else:
          self._insert_edge(adj_node_x, adj_node_y, delta_matrix)
  
      self._remove_node(node_idx)
      self._reorder_adj_nodes(node_idx)
      self._stack.append(node_idx)
  
file_path: tvm/python/tvm/autotvm/graph_tuner/pbqp_tuner.py
imports: from ._base import INVALID_LAYOUT_TIME
  from .base_graph_tuner import BaseGraphTuner
  from .utils import is_boundary_node, has_multiple_inputs
label_desc: Use image node_id 8 for calling the PBQPTuner obj's underlying member method code with example usage: obj._RII_reduction(node_idx) without return types