Description
Hi,
I'm encountering an issue when trying to find the jacobian of a vector field.
1 function f(qx, qy, q, d)
2 K = length(q)
3 ∑q = cumsum(q)
4 coeff = (.5 + d)/K
5 A = [cos.(∑q) sin.(∑q)]
6 return [qx, qy] .+ coeff.*A'*centrosymmetric(K)
7 end
8
9 f(q, d) = f(q[1], q[2], q[3:end], d)
10
11 ForwardDiff.jacobian(x->f(x, d), q)
where q
is an array of TF <: Real
when f
is called outside of ForwardDiff functions.
centrosymmetric(K)
simply returns a KxK
centrosymmetric matrix filled with integer values.
This used to work fine on julia 1.7.2 but I just upgraded to 1.8.1 and it throws the following error.
ERROR: LoadError: + not defined for ForwardDiff.Dual{ForwardDiff.Tag{MyCustomPackage.var"#337#339"{Float64}, Float64}, Float64, 7}
The slack trace says line 6 is problematic...
I find it weird: if i get rid of the addition and only keep the matrix multiplication, I don't get the error even though multiplying matrices requires its fair share of additions.
Has anyone an idea of how to easily fix the issue?
I could modify A
and add a line filled with 1
s on top of the centrosymmetric matrix to embed the addition in the matrix product but it seems inferior to broadcasting +
to me...