@gof.local_optimizer(None)
def constant_folding(node):
    for input in node.inputs:
        if not isinstance(input, Constant):
            return False
    # condition:  all inputs are constant
    if not node.op.do_constant_folding(node):
        # The op asks not to be constant folded.
        return False

    storage_map = dict([(i, [i.data]) for i in node.inputs])
    compute_map = dict([(i, [True]) for i in node.inputs])
    for o in node.outputs:
        storage_map[o] = [None]
        compute_map[o] = [False]
    if (hasattr(node.op, 'python_constant_folding') and
            node.op.python_constant_folding(node)):
        old_value = getattr(node.op, '_op_use_c_code', False)
        try:
            node.op._op_use_c_code = False
            thunk = node.op.make_thunk(node,
                                       storage_map,
                                       compute_map,
                                       [])
        finally:
            node.op._op_use_c_code = old_value
    else:
        thunk = node.op.make_thunk(node, storage_map, compute_map,
                                   no_recycling=[])

    required = thunk()
    assert not required  # a node whose inputs are all provided should always
    # return successfully

    rval = []
    for output in node.outputs:
        assert compute_map[output][0], (output, storage_map[output][0])
        try:
            constant = output.type.Constant
        except __HOLE__:
            constant = Constant

        v = constant(output.type, storage_map[output][0])
        copy_stack_trace(output, v)

        rval.append(v)
    return rval
dataset/ETHPy150Open rizar/attention-lvcsr/libs/Theano/theano/tensor/opt.py/constant_folding