code: def ifelse(condition, then_branch, else_branch, name=None):
      """
      This function corresponds to an if statement, returning (and evaluating)
      inputs in the ``then_branch`` if ``condition`` evaluates to True or
      inputs in the ``else_branch`` if ``condition`` evalutates to False.
  
      :type condition: scalar like
      :param condition:
          ``condition`` should be a tensor scalar representing the condition.
          If it evaluates to 0 it corresponds to False, anything else stands
          for True.
  
      :type then_branch: list of theano expressions/ theano expression
      :param then_branch:
          A single theano variable or a list of theano variables that the
          function should return as the output if ``condition`` evaluates to
          true. The number of variables should match those in the
          ``else_branch``, and there should be a one to one correspondance
          (type wise) with the tensors provided in the else branch
  
      :type else_branch: list of theano expressions/ theano expressions
      :param else_branch:
          A single theano variable or a list of theano variables that the
          function should return as the output if ``condition`` evaluates to
          false. The number of variables should match those in the then branch,
          and there should be a one to one correspondace (type wise) with the
          tensors provided in the then branch.
  
      :return:
          A list of theano variables or a single variable (depending on the
          nature of the ``then_branch`` and ``else_branch``). More exactly if
          ``then_branch`` and ``else_branch`` is a tensor, then
          the return variable will be just a single variable, otherwise a
          list. The value returns correspond either to the values in the
          ``then_branch`` or in the ``else_branch`` depending on the value of
          ``cond``.
      """
  
      rval_type = None
      if type(then_branch) is list:
          rval_type = list
      elif type(then_branch) is tuple:
          rval_type = tuple
  
      if type(then_branch) not in (list, tuple):
          then_branch = [then_branch]
      if type(else_branch) not in (list, tuple):
          else_branch = [else_branch]
  
      # Some of the elements might be converted into another type,
      # we will store them in these new_... lists.
      new_then_branch = []
      new_else_branch = []
      for then_branch_elem, else_branch_elem in izip(
          then_branch, else_branch
      ):
          if not isinstance(then_branch_elem, theano.Variable):
              then_branch_elem = theano.tensor.as_tensor_variable(
                  then_branch_elem
              )
          if not isinstance(else_branch_elem, theano.Variable):
              else_branch_elem = theano.tensor.as_tensor_variable(
                  else_branch_elem
              )
  
          if then_branch_elem.type != else_branch_elem.type:
              # If one of them is a TensorType, and the other one can be
              # converted into one, then we try to do that.
              # This case happens when one of the elements has a GPU type,
              # for instance a shared variable that was silently moved to GPU.
              if isinstance(
                  then_branch_elem.type, TensorType
              ) and not isinstance(else_branch_elem.type, TensorType):
                  else_branch_elem = (
                      then_branch_elem.type.filter_variable(
                          else_branch_elem
                      )
                  )
  
              elif isinstance(
                  else_branch_elem.type, TensorType
              ) and not isinstance(then_branch_elem.type, TensorType):
                  then_branch_elem = (
                      else_branch_elem.type.filter_variable(
                          then_branch_elem
                      )
                  )
  
              if then_branch_elem.type != else_branch_elem.type:
                  # If the types still don't match, there is a problem.
                  raise TypeError(
                      "The two branches should have identical types, but "
                      "they are %s and %s respectively. This error could be "
                      "raised if for example you provided a one element "
                      "list on the `then` branch but a tensor on the `else` "
                      "branch."
                      % (then_branch_elem.type, else_branch_elem.type)
                  )
  
          new_then_branch.append(then_branch_elem)
          new_else_branch.append(else_branch_elem)
  
      if len(then_branch) != len(else_branch):
          raise ValueError(
              (
                  "The number of values on the `then` branch"
                  " should have the same number of variables as "
                  "the `else` branch : (variables on `then` "
                  "%d" % len(then_branch) + ", variables on `else` "
                  "%d" % len(else_branch) + ")"
              )
          )
  
      new_ifelse = IfElse(
          n_outs=len(then_branch), as_view=False, gpu=False, name=name
      )
  
      ins = [condition] + list(new_then_branch) + list(new_else_branch)
      rval = new_ifelse(*ins, **dict(return_list=True))
  
      if rval_type is None:
          return rval[0]
      elif rval_type is list:
          return list(rval)
      else:
          return tuple(rval)
  
imports: from __future__ import absolute_import, print_function, division
  from copy import deepcopy
  from theano.compat import izip
  import logging
  import numpy
  import theano.tensor
  from theano.tensor import TensorType
  from theano import gof
  from theano.gof import Op, Apply
  from six import iteritems
  from six.moves import xrange
  from theano.compile import optdb
  from theano.tensor import opt
  from theano.scan_module.scan_utils import clone
label_desc: Use image node_id 1 for calling a global function with example usage: ifelse(condition, then_branch, else_branch, name) and returns: rval, list, tuple