initial abstract interpretation
This commit is contained in:
parent
806febdd37
commit
27554494b7
|
@ -4,7 +4,7 @@ using MacroTools, Lazy, DataFlow, Juno
|
|||
using DataFlow: graphm, syntax, prewalk!, postwalk!, prewalk, postwalk,
|
||||
iscyclic, Constant, constant, isconstant, Group, group, Split, splitnode,
|
||||
detuple, value, inputs, thread!, value, inputs, Split, splitnode, inputnode,
|
||||
spliceinputs, bumpinputs, interpret
|
||||
spliceinputs, bumpinputs
|
||||
using Juno: Tree, Row
|
||||
|
||||
# Zero Flux Given
|
||||
|
@ -16,6 +16,7 @@ include("data.jl")
|
|||
include("compiler/diff.jl")
|
||||
include("compiler/code.jl")
|
||||
include("compiler/loops.jl")
|
||||
include("compiler/interp.jl")
|
||||
|
||||
include("layers/affine.jl")
|
||||
include("layers/recurrent.jl")
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
using DataFlow: interpret, interpret, interptuple, interplambda, interpconst, Context
|
||||
|
||||
function astuple(xs)
|
||||
isconstant(xs) && isa(value(xs).value, Tuple) ? value(xs).value :
|
||||
isa(xs, Vertex) && isa(value(xs), Group) ? inputs(xs) :
|
||||
nothing
|
||||
end
|
||||
|
||||
function astuples(xs)
|
||||
xs = [astuple(x) for x in xs]
|
||||
all(x->!(x==nothing), xs) ? xs : nothing
|
||||
end
|
||||
|
||||
# function interp(ctx, ::typeof(map), f, xs...)
|
||||
# f = interpret(ctx, f)
|
||||
# xs = interpret(ctx, xs)
|
||||
# xs′ = astuples(xs)
|
||||
# xs′ == nothing ? constant(:MAPFAIL) : @show map(f, xs...)
|
||||
# end
|
||||
|
||||
function interp(ctx, model, xs...)
|
||||
@show model
|
||||
g = graph(model)
|
||||
g == nothing && return vertex(model, map(constant, interpret(ctx, xs))...)
|
||||
interpret(ctx, g, xs...)
|
||||
end
|
||||
|
||||
expand(graph, xs...) =
|
||||
interp(Context(interplambda(interpconst(interptuple(interp)))), graph, xs...)
|
Loading…
Reference in New Issue