Skip to content

Commit 2e6a15d

Browse files
shashiYingboMa
andcommitted
Wrap registered fn output in Num if any input is Num
Co-authored-by: "Yingbo Ma" <[email protected]>
1 parent 4cadda7 commit 2e6a15d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/register_function.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ macro register(expr, Ts = [Num, Symbolic, Real])
1717
name(x::Expr) = ((@assert x.head == :(::)); :($value($(x.args[1]))))
1818

1919
Expr(:block,
20-
[:($f($(setinds(args, symbolic_args, ts)...)) = Term{Real}($f, [$(map(name, args)...)]))
20+
[quote
21+
function $f($(setinds(args, symbolic_args, ts)...))
22+
wrap = any(x->typeof(x) <: Num, tuple($(setinds(args, symbolic_args, ts)...),)) ? Num : identity
23+
wrap(Term{Real}($f, [$(map(name, args)...)]))
24+
end
25+
end
2126
for ts in types]...) |> esc
2227
end
2328

0 commit comments

Comments
 (0)