Closed b-fg closed 1 year ago
The broadcasting function does not mutate a
. To be equivalent to the loop it would be addX!(a, x) = sum(a .= a .+ x)
, which gives the same error.
In general you will need to make arrays of the right type to store Dual numbers, e.g. using similar(x)
.
I am sure this is covered somewhere and https://github.com/JuliaDiff/ForwardDiff.jl/issues/136#issuecomment-237941790 is very much related, but I am struggling to understand why does this MWE work
but not this one:
With error:
ERROR: MethodError: no method matching +(::Vector{Float64}, ::ForwardDiff.Dual{ForwardDiff.Tag{var"#5#6"{Vector{Float64}}, Float64}, Float64, 1})
What is special about broadcasting instead of explicitly writing the loop? Thanks!