def ifelse(condition, then_branch, else_branch, name=None):

    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)
This function corresponds to an if statement, returning (and evaluating)
dataset/ETHPy150Open rizar/attention-lvcsr/libs/Theano/theano/ifelse.py/ifelse