code: def scan_can_remove_outs(op, out_idxs):
      """
      Looks at all outputs defined by indices ``out_idxs`` and see whom can be
      removed from the scan op without affecting the rest. Return two lists,
      the first one with the indices of outs that can be removed, the second
      with the outputs that can not be removed.
  
      """
      non_removable = [
          o for i, o in enumerate(op.outputs) if i not in out_idxs
      ]
      required_inputs = gof.graph.inputs(non_removable)
  
      out_ins = []
      offset = op.n_seqs
      lim = op.n_mit_mot + op.n_mit_sot + op.n_sit_sot
      for idx in range(lim):
          n_ins = len(op.info["tap_array"][idx])
          out_ins += [op.inputs[offset : offset + n_ins]]
          offset += n_ins
      out_ins += [[] for k in xrange(op.n_nit_sot)]
      out_ins += [
          [op.inputs[offset + k]] for k in xrange(op.n_shared_outs)
      ]
  
      added = True
      out_idxs_mask = [1 for idx in out_idxs]
      while added:
          added = False
          for pos, idx in enumerate(out_idxs):
              if out_idxs_mask[pos] and any(
                  [x in required_inputs for x in out_ins[idx]]
              ):
                  # This output is required ..
                  out_idxs_mask[pos] = 0
                  required_inputs += gof.graph.inputs([op.outputs[idx]])
                  added = True
  
      required_outs = [
          x for i, x in enumerate(out_idxs) if out_idxs_mask[i] == 0
      ]
      not_required = [
          x for i, x in enumerate(out_idxs) if out_idxs_mask[i] == 1
      ]
      return (required_outs, not_required)
  
imports: from __future__ import absolute_import, print_function, division
  import copy
  import logging
  import warnings
  from collections import OrderedDict
  import numpy
  import theano
  from theano.compat import izip
  from six import string_types, iteritems
  from six.moves import xrange
  from theano.compile.pfunc import rebuild_collect_shared
  from theano import gof, compat
  from theano import tensor, scalar
  from theano.tensor.basic import get_scalar_constant_value
label_desc: Use image node_id 12 for calling a global function with example usage: scan_can_remove_outs(op, out_idxs) and returns: required_outs,  not_required