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
|
|
|
|
|
|
2016-12-26 13:42:12 +00:00
|
|
|
|
function imap(cb, ctx, ::typeof(map), f, xs...)
|
|
|
|
|
f, xs = interpv(ctx, (f, xs))
|
|
|
|
|
xs′ = astuples(xs)
|
|
|
|
|
xs′ ≠ nothing ?
|
|
|
|
|
group(map(f, xs′...)...) :
|
|
|
|
|
cb(ctx, map, constant(f), xs...)
|
2016-11-15 20:46:01 +00:00
|
|
|
|
end
|
2016-11-15 20:01:56 +00:00
|
|
|
|
|
2016-12-26 13:42:12 +00:00
|
|
|
|
imap(f, args...) = f(args...)
|
2017-01-24 11:53:42 +00:00
|
|
|
|
|
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-01-25 10:03:58 +00:00
|
|
|
|
# TODO: batching should be secondary
|
|
|
|
|
|
2017-03-09 00:13:26 +00:00
|
|
|
|
function interpmodel_(m, args...)
|
2017-02-01 11:26:53 +00:00
|
|
|
|
ctx = Context(mux(iline, ilambda, iconst, iargs, ituple, interp))
|
2017-03-09 00:13:26 +00:00
|
|
|
|
interp(ctx, m, args...)
|
2017-01-24 11:53:42 +00:00
|
|
|
|
end
|
|
|
|
|
|
2017-03-09 00:13:26 +00:00
|
|
|
|
interpmodel(m, args...) = @ithrow runrawbatched((xs...) -> interpmodel_(m, xs...), args...)
|
2017-03-21 01:32:12 +00:00
|
|
|
|
|
|
|
|
|
runmodel(m::Capacitor, xs...) = @ithrow interpmodel_(m, xs...)
|