Skip to content

Commit

Permalink
Fix mx.chain var reference in macro (#299)
Browse files Browse the repository at this point in the history
fix #298
  • Loading branch information
iblislin authored and pluskid committed Oct 26, 2017
1 parent 71f2d40 commit 3824df0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/nn-factory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fully connected layers.
Returns the constructed MLP.
"""
function MLP(input, spec; hidden_activation::Base.Symbol=:relu, prefix=gensym())
function MLP(input, spec; hidden_activation::Symbol=:relu, prefix=gensym())
spec = convert(Vector{Union{Int,Tuple}}, spec)

n_layer = length(spec)
Expand Down
3 changes: 2 additions & 1 deletion src/symbolic-node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,8 @@ macro chain(layers)
return esc(layer)
else
if @capture(layer, f_(x__))
return :($f($last_layer, $(x...)))
x′ = esc.(x)
return :($f($last_layer, $(x′...)))
else
throw(AssertionError("$layer is not a valid function call and cannot be chained."))
end
Expand Down
13 changes: 13 additions & 0 deletions test/unittest/symbolic-node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ function test_chain()
@test mx.list_arguments(model) == [:data,:fc1_weight,:fc1_bias,:fc2_weight,:fc2_bias]
@test mx.list_outputs(model) == [:fc2_output]
@test mx.list_auxiliary_states(model) == Symbol[]

let layerconfig = [20, 10, 6]
model = @mx.chain mx.Variable(:data) =>
mx.MLP(layerconfig, prefix=:magic_) =>
mx.LinearRegressionOutput(mx.Variable(:label))

@test mx.list_arguments(model) == [
:data,
:magic_fc1_weight, :magic_fc1_bias,
:magic_fc2_weight, :magic_fc2_bias,
:magic_fc3_weight, :magic_fc3_bias,
:label]
end
end

function test_internal()
Expand Down

0 comments on commit 3824df0

Please sign in to comment.