Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple code fails #457

Closed
haavardhvarnes opened this issue Jun 10, 2020 · 1 comment
Closed

Simple code fails #457

haavardhvarnes opened this issue Jun 10, 2020 · 1 comment

Comments

@haavardhvarnes
Copy link

I was trying ForwardDiff and found I have this simple function where calculating jacobian fails:
function g(x::Array{Float64,1})
c1_x1mostneg = x[1] .- x[2:end]
c2_x4mostpos = x[[1,2,3,5]] .- x[4]
return [c1_x1mostneg;c2_x4mostpos]
end
dg = x -> ForwardDiff.jacobian(g, x)
dg(randn(5))

with error message:
julia> dg(randn(5))
ERROR: MethodError: no method matching g(::Array{ForwardDiff.Dual{ForwardDiff.Tag{typeof(g),Float64},Float64,5},1})
Closest candidates are:
g(::Array{Float64,1}) at none:2
Stacktrace:
[1] vector_mode_dual_eval(::typeof(g), ::Array{Float64,1}, ::ForwardDiff.JacobianConfig{ForwardDiff.Tag{typeof(g),Float64},Float64,5,Array{ForwardDiff.Dual{ForwardDiff.Tag{typeof(g),Float64},Float64,5},1}}) at /Users/havard/.julia/packages/ForwardDiff/cXTw0/src/apiutils.jl:37
[2] vector_mode_jacobian(::typeof(g), ::Array{Float64,1}, ::ForwardDiff.JacobianConfig{ForwardDiff.Tag{typeof(g),Float64},Float64,5,Array{ForwardDiff.Dual{ForwardDiff.Tag{typeof(g),Float64},Float64,5},1}}) at /Users/havard/.julia/packages/ForwardDiff/cXTw0/src/jacobian.jl:140
[3] jacobian(::Function, ::Array{Float64,1}, ::ForwardDiff.JacobianConfig{ForwardDiff.Tag{typeof(g),Float64},Float64,5,Array{ForwardDiff.Dual{ForwardDiff.Tag{typeof(g),Float64},Float64,5},1}}, ::Val{true}) at /Users/havard/.julia/packages/ForwardDiff/cXTw0/src/jacobian.jl:17
[4] jacobian(::Function, ::Array{Float64,1}, ::ForwardDiff.JacobianConfig{ForwardDiff.Tag{typeof(g),Float64},Float64,5,Array{ForwardDiff.Dual{ForwardDiff.Tag{typeof(g),Float64},Float64,5},1}}) at /Users/havard/.julia/packages/ForwardDiff/cXTw0/src/jacobian.jl:15 (repeats 2 times)
[5] (::var"#82#83")(::Array{Float64,1}) at ./none:1
[6] top-level scope at none:0

What do I misunderstand here?

@andreasnoack
Copy link
Member

The error message clearly states what the problem is. Please use discourse.julialang.org for questions like these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants