def build_expression(arrays, expr):
    """Build a theano function based on ``arrays`` and ``expr``."""
    import theano

    in_vars = [to_theano(array) for array in arrays]
    out_var = expr._contract(in_vars, backend="theano")

    # don't supply constants to graph
    graph_ins = [x for x in in_vars if not isinstance(x, theano.tensor.TensorConstant)]
    graph = theano.function(graph_ins, out_var)

    def theano_contract(*arrays):
        return graph(*[x for x in arrays if not isinstance(x, theano.tensor.TensorConstant)])

    return theano_contract
Build a theano function based on ``arrays`` and ``expr``.
opt_einsum/backends/theano.py