DynamicExpressions.jl
DynamicExpressions.jl copied to clipboard
Suppress Warning from ForwardDiff Duals
Turns out ForwardDiff.jl already works with DynamicExpressions, but we would want to turn off the type mismatch warnings.
using ForwardDiff, DynamicExpressions
operators = OperatorEnum(; binary_operators=[+, -, *], unary_operators=[cos]);
x1 = Node(; feature=1)
x2 = Node(; feature=2)
expr = x1 * cos(x2 - 3.2)
X = rand(2, 5)
ForwardDiff.gradient(X) do X
return sum(abs2, first(eval_tree_array(expr, X, operators)))
end
┌ Warning: Warning: eval_tree_array received mixed types: tree=Float32 and data=ForwardDiff.Dual{ForwardDiff.Tag{var"#13#14", Float64}, Float64, 10}.
└ @ DynamicExpressions.EvaluateModule /mnt/research/lux/DynamicExpressions.jl/src/Evaluate.jl:95
2×5 Matrix{Float64}:
0.182636 0.882172 0.906966 0.161635 1.86929
-0.020271 -0.363872 -0.0764073 -0.0126587 -0.331082