2017-02-01 06:57:02 +00:00
|
|
|
|
using DataFlow.Interpreter
|
2016-11-15 20:01:56 +00:00
|
|
|
|
|
2016-11-17 11:27:17 +00:00
|
|
|
|
function astuple(xs::Vertex)
|
2016-11-15 20:01:56 +00:00
|
|
|
|
isconstant(xs) && isa(value(xs).value, Tuple) ? value(xs).value :
|
2016-11-15 21:09:58 +00:00
|
|
|
|
isa(xs, 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-01-25 10:03:58 +00:00
|
|
|
|
# TODO: batching should be secondary
|
|
|
|
|
|
2017-01-24 11:53:42 +00:00
|
|
|
|
function interpmodel(m, args::Batch...)
|
|
|
|
|
rebatch(interpret(reifyparams(graph(m)), map(rawbatch, args)...))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
interpmodel(m, args...) = unbatchone(interpmodel(m, batchone(args)...))
|