@gof.local_optimizer([T.Elemwise])
def local_fill_cut(node):
    """
    f(fill(a,b), c) -> f(b, c)
    If c.type == a.type.
    """

    # this optimization is essentially for getting broadcasting to
    # replace fill.  This is always possible when using a Compound
    # Elemwise operation, but it is not always possible without one
    # (consider filling a large matrix with a scalar, and then adding
    # another scalar.  The only numbers that count are the two
    # scalars, but we can't ignore the large matrix because it gives
    # the shape of the result.

    if node.op != T.Elemwise:
        return False

    output = node.outputs[0]
    try:
        # reference is some input with the same type as the output but
        # that is not produced by a fill
        reference = [input
                     for input in node.inputs
                     if input.type == output.type and
                     (not input.owner or input.owner.op != T.fill)][0]
    except __HOLE__:
        return False

    new_inputs = []
    new = False
    for input in node.inputs:
        if input.owner and input.owner.op == T.fill:
            model, filling = input.owner.inputs
            if encompasses_broadcastable(reference.type.broadcastable,
                                         filling.type.broadcastable):
                new_inputs.append(filling)
                new = True
                continue
        new_inputs.append(input)

    if not new:
        return False

    rval = node.op(*new_inputs)
    if isinstance(rval, gof.Variable):
        return rval.owner.outputs
    else:
        return rval[0].owner.outputs
dataset/ETHPy150Open rizar/attention-lvcsr/libs/Theano/theano/tensor/opt.py/local_fill_cut