docstr: Helper function for replace_uses_of_var_after_op
docstr_tok: ["Helper","function","for","replace_uses_of_var_after_op"]
code: def _replace_var(
      self,
      old_var,
      new_var,
      start=0,
      end_id=-1,
      no_check_var_visibility=False,
      no_check_var_types=False,
  ):
      """Helper function for replace_uses_of_var_after_op"""
      num_ops_affected = 0
  
      if end_id == -1:
          op_list = self.operations[start:]
      else:
          op_list = self.operations[start : end_id + 1]
  
      for op in op_list:
          new_inputs = {
              "no_check_var_visibility": no_check_var_visibility,
              "no_check_var_types": no_check_var_types,
          }
          affected = False
          for k, v in op.inputs.items():
              if isinstance(v, (list, tuple)) and old_var in v:
                  new_inputs[k] = tuple(
                      new_var if vv == old_var else vv for vv in v
                  )
                  affected = True
              elif v == old_var:
                  new_inputs[k] = new_var
                  affected = True
              else:
                  new_inputs[k] = v
          if affected:
              num_ops_affected += 1
              op.set_inputs(**new_inputs)
  
          # Replace recursively.
          for b in op.blocks:
              num_ops_affected += b._replace_var(old_var, new_var)
  
      if end_id != -1 and old_var.op not in op_list:
          return num_ops_affected
  
      # If old_var is block's output, replace as well.
      if old_var in self._outputs:
          idx = self._outputs.index(old_var)
          self._outputs[idx] = new_var
          new_var.consuming_blocks.append(self)
  
          # This block no longer uses `old_var` as its outputs
          old_var.consuming_blocks.remove(self)
  
          # if rename_new_var_if_fn_output:
          # Ensure output name is consistent
          if isinstance(self, Function):
              new_var.name = old_var.name
      return num_ops_affected
  
imports: from collections import Counter, OrderedDict
  import copy
  import logging
  import numpy
  from six import string_types
  from .None import SPACES, types
  from .var import Var, InternalVar, ListVar
  from .visitors.dot_visitor import DotVisitor
  from .types.symbolic import k_used_symbols, k_num_internal_syms, any_symbolic, is_symbolic
  from .input_type import TupleInputType
label_desc: Use image node_id 15 for calling the Block obj's underlying member method code with example usage: obj._replace_var(old_var, new_var, start, end_id, no_check_var_visibility, no_check_var_types) and returns: num_ops_affected, num_ops_affected