code: def compress_outs(op, not_required, inputs):
      """
      Helpful function that gets a Scan op, a list of indices indicating
      which outputs are not required anymore and should be removed, and
      a list of inputs to the apply node corresponding to the scan op and
      produces the list of inputs and outputs and the info dictionary where
      the indicated outputs are eliminated. Note that eliminating an output
      means removing its inputs from the inner function and from the
      node inputs, and changing the dictionary.
  
      """
      info = OrderedDict()
      info["tap_array"] = []
      info["n_seqs"] = op.info["n_seqs"]
      info["n_mit_mot"] = 0
      info["n_mit_mot_outs"] = 0
      info["mit_mot_out_slices"] = []
      info["n_mit_sot"] = 0
      info["n_sit_sot"] = 0
      info["n_shared_outs"] = 0
      info["n_nit_sot"] = 0
      info["truncate_gradient"] = op.info["truncate_gradient"]
      info["name"] = op.info["name"]
      info["gpua"] = op.info["gpua"]
      info["mode"] = op.info["mode"]
      info["as_while"] = op.info["as_while"]
      info["profile"] = op.info["profile"]
      info["allow_gc"] = op.info["allow_gc"]
  
      op_inputs = op.inputs[: op.n_seqs]
      op_outputs = []
      node_inputs = inputs[: op.n_seqs + 1]
      map_old_new = OrderedDict()
  
      offset = 0
      ni_offset = op.n_seqs + 1
      i_offset = op.n_seqs
      o_offset = 0
      curr_pos = 0
      for idx in xrange(op.info["n_mit_mot"]):
          if offset + idx not in not_required:
              map_old_new[offset + idx] = curr_pos
              curr_pos += 1
              info["n_mit_mot"] += 1
              info["tap_array"] += [op.tap_array[offset + idx]]
              info["mit_mot_out_slices"] += [
                  op.mit_mot_out_slices[offset + idx]
              ]
              # input taps
              for jdx in op.tap_array[offset + idx]:
                  op_inputs += [op.inputs[i_offset]]
                  i_offset += 1
              # output taps
              for jdx in op.mit_mot_out_slices[offset + idx]:
                  op_outputs += [op.outputs[o_offset]]
                  o_offset += 1
              # node inputs
              node_inputs += [inputs[ni_offset + idx]]
          else:
              o_offset += len(op.mit_mot_out_slices[offset + idx])
              i_offset += len(op.tap_array[offset + idx])
      info["n_mit_mot_outs"] = len(op_outputs)
      offset += op.n_mit_mot
      ni_offset += op.n_mit_mot
  
      for idx in xrange(op.info["n_mit_sot"]):
          if offset + idx not in not_required:
              map_old_new[offset + idx] = curr_pos
              curr_pos += 1
              info["n_mit_sot"] += 1
              info["tap_array"] += [op.tap_array[offset + idx]]
              # input taps
              for jdx in op.tap_array[offset + idx]:
                  op_inputs += [op.inputs[i_offset]]
                  i_offset += 1
              # output taps
              op_outputs += [op.outputs[o_offset]]
              o_offset += 1
              # node inputs
              node_inputs += [inputs[ni_offset + idx]]
          else:
              o_offset += 1
              i_offset += len(op.tap_array[offset + idx])
  
      offset += op.n_mit_sot
      ni_offset += op.n_mit_sot
      for idx in xrange(op.info["n_sit_sot"]):
          if offset + idx not in not_required:
              map_old_new[offset + idx] = curr_pos
              curr_pos += 1
              info["n_sit_sot"] += 1
              info["tap_array"] += [op.tap_array[offset + idx]]
              # input taps
              op_inputs += [op.inputs[i_offset]]
              i_offset += 1
              # output taps
              op_outputs += [op.outputs[o_offset]]
              o_offset += 1
              # node inputs
              node_inputs += [inputs[ni_offset + idx]]
          else:
              o_offset += 1
              i_offset += 1
  
      offset += op.n_sit_sot
      ni_offset += op.n_sit_sot
      nit_sot_ins = []
      for idx in xrange(op.info["n_nit_sot"]):
          if offset + idx not in not_required:
              map_old_new[offset + idx] = curr_pos
              curr_pos += 1
              info["n_nit_sot"] += 1
              op_outputs += [op.outputs[o_offset]]
              o_offset += 1
              nit_sot_ins += [
                  inputs[ni_offset + idx + op.n_shared_outs]
              ]
          else:
              o_offset += 1
  
      offset += op.n_nit_sot
      shared_ins = []
      for idx in xrange(op.info["n_shared_outs"]):
          if offset + idx not in not_required:
              map_old_new[offset + idx] = curr_pos
              curr_pos += 1
              info["n_shared_outs"] += 1
              op_outputs += [op.outputs[o_offset]]
              o_offset += 1
              op_inputs += [op.inputs[i_offset]]
              i_offset += 1
              shared_ins += [inputs[ni_offset + idx]]
          else:
              o_offset += 1
              i_offset += 1
      node_inputs += shared_ins
      node_inputs += nit_sot_ins
      # other stuff
      op_inputs += op.inputs[i_offset:]
      node_inputs += inputs[
          ni_offset + op.n_shared_outs + op.n_nit_sot :
      ]
      if op.as_while:
          op_outputs += [op.outputs[o_offset]]
          map_old_new[o_offset] = len(op_outputs) - 1
          # map_old_new[len(op_outputs)-1] = o_offset
  
      return (op_inputs, op_outputs, info, node_inputs, map_old_new)
  
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 13 for calling a global function with example usage: compress_outs(op, not_required, inputs) and returns: op_inputs,  op_outputs,  info,  node_inputs,  map_old_new