isa syntax
This commit is contained in:
parent
76d80668b4
commit
fa56f78781
|
@ -106,7 +106,7 @@ macro mxerr(stk, ex)
|
|||
@q try
|
||||
$(esc(ex))
|
||||
catch e
|
||||
(isa(e, mx.MXError) && (node = errnode(e)) != nothing) || rethrow()
|
||||
(e isa mx.MXError && (node = errnode(e)) != nothing) || rethrow()
|
||||
stk = $(esc(stk))
|
||||
haskey(stk, node) || rethrow()
|
||||
throw(Exception(striptrace(e), totrace(stk[node])))
|
||||
|
|
|
@ -39,7 +39,7 @@ graph(op::Op, xs...) = op.f(xs...)
|
|||
|
||||
function graph(ctx::Context, model, args...)
|
||||
node = graph(model, interpv(ctx, args)...)
|
||||
isa(node, Tensor) && (ctx[:stacks][node.op.name] = stack(ctx))
|
||||
node isa Tensor && (ctx[:stacks][node.op.name] = stack(ctx))
|
||||
return node
|
||||
end
|
||||
|
||||
|
|
|
@ -13,12 +13,12 @@ end
|
|||
function makegraph(graph, args)
|
||||
@assert length(args) == 1
|
||||
graph = prewalk(graph) do v
|
||||
isa(value(v), Constant) && value(v).value == args[1] ?
|
||||
value(v) isa Constant && value(v).value == args[1] ?
|
||||
inputnode(1) :
|
||||
v
|
||||
end
|
||||
graph = map(graph) do x
|
||||
isa(x, Offset) ?
|
||||
x isa Offset ?
|
||||
:(Flux.Offset($(Expr(:quote, x.name)), $(x.n), self.$(x.name))) :
|
||||
x
|
||||
end
|
||||
|
@ -44,7 +44,7 @@ runmodel(f, xs...) = f(xs...)
|
|||
|
||||
function deref_params(v)
|
||||
v = map(v) do x
|
||||
isa(x, Constant) && @capture(x.value, self.p_) ? Constant(:(Flux.state(self.$p))) : x
|
||||
x isa Constant && @capture(x.value, self.p_) ? Constant(:(Flux.state(self.$p))) : x
|
||||
end
|
||||
prewalk(v) do v
|
||||
@capture(value(v), self.p_) ? vertex(:(Flux.runmodel), constant(:(self.$p)), inputs(v)...) : v
|
||||
|
@ -58,7 +58,7 @@ end
|
|||
|
||||
import Lazy: groupby
|
||||
|
||||
reifyparams(v::IVertex) = mapconst(x -> isa(x, Param) ? x.x : x, v)
|
||||
reifyparams(v::IVertex) = mapconst(x -> x isa Param ? x.x : x, v)
|
||||
|
||||
# TODO: type hints for parameters
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using DataFlow.Interpreter
|
||||
|
||||
function astuple(xs::Vertex)
|
||||
isconstant(xs) && isa(value(xs).value, Tuple) ? value(xs).value :
|
||||
isa(xs, Vertex) && value(xs) == tuple ? inputs(xs) :
|
||||
isconstant(xs) && value(xs).value isa Tuple ? value(xs).value :
|
||||
xs isa Vertex && value(xs) == tuple ? inputs(xs) :
|
||||
nothing
|
||||
end
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ function collect_state(v::IVertex)
|
|||
offset = Int[]
|
||||
default = Param[]
|
||||
prewalk!(v) do v
|
||||
isa(value(v), Offset) || return v
|
||||
value(v) isa Offset || return v
|
||||
if (i = findfirst(state, v[1])) == 0
|
||||
push!(state, v[1])
|
||||
push!(offset, max(0, -value(v).n))
|
||||
|
@ -91,7 +91,7 @@ function unrollgraph(v::IVertex, n; seq = true, stateful = true)
|
|||
for i = 1:n
|
||||
vars = inputs(steps[i][1])
|
||||
postwalk!(steps[i]) do v
|
||||
isa(value(v), Offset) || return v
|
||||
value(v) isa Offset || return v
|
||||
varid = findfirst(vars,v[1])
|
||||
getvar(varid, value(v).n + i, steps, offset, default, stateful = stateful)
|
||||
end
|
||||
|
@ -131,4 +131,4 @@ function unroll1(model)
|
|||
Unrolled(model, graph, state, false, 1)
|
||||
end
|
||||
|
||||
flip(model) = Capacitor(map(x -> isa(x, Offset) ? -x : x, atomise(model)))
|
||||
flip(model) = Capacitor(map(x -> x isa Offset ? -x : x, atomise(model)))
|
||||
|
|
|
@ -9,8 +9,8 @@ end
|
|||
DataFlow.tocall(h::Hint, x) = :($x::$(h.typ))
|
||||
|
||||
function gethint(v::IVertex)
|
||||
while isa(value(v), Union{Line,Frame}) v = v[1] end
|
||||
isa(value(v), Hint) && return value(v).typ
|
||||
while value(v) isa Union{Line,Frame} v = v[1] end
|
||||
value(v) isa Hint && return value(v).typ
|
||||
return
|
||||
end
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ function rebatch(xs)
|
|||
end
|
||||
|
||||
convertel(T::Type, xs::Batch) =
|
||||
isa(eltype(eltype(xs)), T) ? xs :
|
||||
eltype(eltype(xs)) isa T ? xs :
|
||||
Batch(map(x->convertel(T, x), xs))
|
||||
|
||||
# Add batching semantics to functions operating on raw arrays
|
||||
|
|
Loading…
Reference in New Issue