Skip to content

Commit

Permalink
Positional arguments in symbolic API need type restriction. (apache#134)
Browse files Browse the repository at this point in the history
* fix positional arguments can only be SymbolicNodes

* fix missing signature of Symbolic function in docs
  • Loading branch information
vchuravy authored and pluskid committed Sep 6, 2016
1 parent ae1d45b commit 9e3a60a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/symbolic-node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ function _define_atomic_symbol_creator(hdr :: MX_handle)

signature = _format_signature(Int(ref_nargs[]), ref_arg_names)
f_desc = " " * func_name_s * "(" * signature * ")\n\n"
f_desc = unsafe_wrap(String, ref_desc[]) * "\n\n"
f_desc *= unsafe_wrap(String, ref_desc[]) * "\n\n"
if !isempty(kv_nargs_s)
f_desc *= "This function support variable length positional `SymbolicNode` inputs.\n\n"
end
Expand All @@ -620,9 +620,9 @@ function _define_atomic_symbol_creator(hdr :: MX_handle)
f_desc *= "* `attrs::Dict{Symbol, AbstractString}`: The attributes associated with this `SymbolicNode`.\n\n"
f_desc *= "Returns `$(_format_typestring(unsafe_wrap(String, ref_ret_type[])))`."

# function $func_name(args...; kwargs...)
func_head = Expr(:call, func_name, Expr(:parameters, Expr(:..., :kwargs)), Expr(:..., :args))
func_body = quote
func_def = quote
@doc $f_desc ->
function $func_name(args::SymbolicNode...; kwargs...)
idx = findfirst(x -> x[1] == :name, kwargs)
if idx > 0
name = kwargs[idx][2]
Expand Down Expand Up @@ -702,13 +702,9 @@ function _define_atomic_symbol_creator(hdr :: MX_handle)
end

return node
end

func_def = Expr(:function, func_head, Expr(:block, func_body))
return quote
@doc $f_desc ->
$func_def
end
end # function
end # quote
return func_def
end

function _get_atomic_symbol_creators()
Expand Down
7 changes: 7 additions & 0 deletions test/unittest/symbolic-node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ function test_attrs()
@test_throws MethodError mx.Convolution(data=data2, kernel = (1,1), num_filter = 1, attrs = Dict(:test => "1.0", :test2 => 1.0))
end

function test_functions()
info("SymbolicNode::Functions")
data = mx.Variable(:data)
typeof(mx.sum(data)) == mx.SymbolicNode
end

################################################################################
# Run tests
################################################################################
Expand All @@ -116,5 +122,6 @@ test_infer_shape()
test_infer_shape_error()
test_saveload()
test_attrs()
test_functions()

end

0 comments on commit 9e3a60a

Please sign in to comment.