docstr: Inputs:
  
  end_vs: list[Operation].
  
  Return:
  
  list[Operation] which are subset of self.operations that are ancestors
  of `end_vs`. Also do recursion into nested blocks.
docstr_tok: ["Inputs",":","end_vs",":","list","[","Operation","]",".","Return",":","list","[","Operation","]","which","are","subset","of","self.operations","that","are","ancestors","of","`","end_vs","`",".","Also","do","recursion","into","nested","blocks","."]
code: def operations_for_vars(self, end_vs):
      """
      Inputs:
  
      end_vs: list[Operation].
  
      Return:
  
      list[Operation] which are subset of self.operations that are ancestors
      of `end_vs`. Also do recursion into nested blocks.
      """
      used_vars = set(end_vs)
      used_ops = []
      for op in reversed(self.operations):
          # if none of op's output is used, delete op
          if not set(op.outputs).intersection(used_vars):
              continue
  
          used_ops.append(op)  # append in reverse topological order
  
          # recursively search for nested blocks
          ops_to_check = []
          for b in op.blocks:
              ops_to_check += b.operations_for_vars(b.outputs)
          ops_to_check.append(op)
  
          # mark used vars
          for op_to_check in ops_to_check:
              # mark all op's inputs to used
              for _, input_var in op_to_check.inputs.items():
                  if isinstance(input_var, (tuple, list)):
                      used_vars.update(list(input_var))
                  else:
                      used_vars.add(input_var)
  
      return used_ops[::-1]
  
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 18 for calling the Block obj's underlying member method code with example usage: obj.operations_for_vars(end_vs) and returns: used_ops