Flux.jl/src/compiler/interp.jl

30 lines
684 B
Julia
Raw Normal View History

2016-11-17 11:27:17 +00:00
function astuple(xs::Vertex)
2017-03-14 15:21:18 +00:00
isconstant(xs) && value(xs).value isa Tuple ? value(xs).value :
xs isa Vertex && value(xs) == tuple ? inputs(xs) :
2016-11-15 20:01:56 +00:00
nothing
end
2016-11-17 11:27:17 +00:00
astuple(xs::Tuple) = xs
astuple(xs) = nothing
2016-11-15 20:01:56 +00:00
function astuples(xs)
xs = [astuple(x) for x in xs]
all(x->!(x==nothing), xs) ? xs : nothing
end
2017-02-01 11:26:53 +00:00
function interp(ctx, f, xs...)
2017-02-01 11:36:42 +00:00
g = graph(f)
2017-02-21 08:56:05 +00:00
@icatch(ctx, g nothing ?
2017-02-01 11:36:42 +00:00
interpret(ctx, reifyparams(g), xs...) :
f(xs...))
2017-02-01 11:26:53 +00:00
end
2017-05-04 16:01:10 +00:00
interp(ctx::Context, c::Constant{<:Param}) = c.value.x
interp(ctx::Context, c::Constant) = c.value
2017-04-18 20:04:21 +00:00
function interpmodel(m, args...)
2017-05-04 16:01:10 +00:00
ctx = Context(mux(iline, ilambda, iargs, ituple, interp))
2017-04-18 20:04:21 +00:00
@ithrow interp(ctx, m, args...)
2017-01-24 11:53:42 +00:00
end