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

Cannot nlsolve with MArray #254

Open
charleskawczynski opened this issue Oct 21, 2020 · 3 comments · Fixed by JuliaDiff/DiffResults.jl#18
Open

Cannot nlsolve with MArray #254

charleskawczynski opened this issue Oct 21, 2020 · 3 comments · Fixed by JuliaDiff/DiffResults.jl#18

Comments

@charleskawczynski
Copy link

Cannot nlsolve with MArray. MWE:

julia> using NLsolve

julia> using StaticArrays

julia> function f!(F, x)
           F[1] = (x[1]+3)*(x[2]^3-7)+18
           F[2] = sin(x[2]*exp(x[1])-1)
       end
f! (generic function with 1 method)

julia> FT = Float32
Float32

julia> a = MArray{Tuple{2},FT}(undef)
2-element MArray{Tuple{2},Float32,1,2} with indices SOneTo(2):
 1.677f-42
 0.0

julia> a .= (0.1, 1.2)
2-element MArray{Tuple{2},Float32,1,2} with indices SOneTo(2):
 0.1
 1.2

julia> nlsolve(f!, a; autodiff = :forward)
ERROR: MethodError: no method matching extract_jacobian!(::Type{ForwardDiff.Tag{typeof(f!),Float32}}, ::DiffResults.ImmutableDiffResult{1,MArray{Tuple{2},Float32,1,2},Tuple{MArray{Tuple{2,2},Float32,2,4}}}, ::MArray{Tuple{2},ForwardDiff.Dual{ForwardDiff.Tag{typeof(f!),Float32},Float32,2},1,2}, ::Int64)
Closest candidates are:
  extract_jacobian!(::Type{T}, ::AbstractArray, ::AbstractArray, ::Any) where T at C:\Users\kawcz\.julia\packages\ForwardDiff\sdToQ\src\jacobian.jl:108
  extract_jacobian!(::Type{T}, ::DiffResults.MutableDiffResult, ::AbstractArray, ::Any) where T at C:\Users\kawcz\.julia\packages\ForwardDiff\sdToQ\src\jacobian.jl:116
Stacktrace:
 [1] vector_mode_jacobian!(::DiffResults.ImmutableDiffResult{1,MArray{Tuple{2},Float32,1,2},Tuple{MArray{Tuple{2,2},Float32,2,4}}}, ::typeof(f!), ::MArray{Tuple{2},Float32,1,2}, ::MArray{Tuple{2},Float32,1,2}, ::ForwardDiff.JacobianConfig{ForwardDiff.Tag{typeof(f!),Float32},Float32,2,Tuple{MArray{Tuple{2},ForwardDiff.Dual{ForwardDiff.Tag{typeof(f!),Float32},Float32,2},1,2},MArray{Tuple{2},ForwardDiff.Dual{ForwardDiff.Tag{typeof(f!),Float32},Float32,2},1,2}}}) at C:\Users\kawcz\.julia\packages\ForwardDiff\sdToQ\src\jacobian.jl:166
 [2] jacobian!(::DiffResults.ImmutableDiffResult{1,MArray{Tuple{2},Float32,1,2},Tuple{MArray{Tuple{2,2},Float32,2,4}}}, ::Function, ::MArray{Tuple{2},Float32,1,2}, ::MArray{Tuple{2},Float32,1,2}, ::ForwardDiff.JacobianConfig{ForwardDiff.Tag{typeof(f!),Float32},Float32,2,Tuple{MArray{Tuple{2},ForwardDiff.Dual{ForwardDiff.Tag{typeof(f!),Float32},Float32,2},1,2},MArray{Tuple{2},ForwardDiff.Dual{ForwardDiff.Tag{typeof(f!),Float32},Float32,2},1,2}}}, ::Val{false}) at C:\Users\kawcz\.julia\packages\ForwardDiff\sdToQ\src\jacobian.jl:74
 [3] (::NLSolversBase.var"#fj_forwarddiff!#24"{typeof(f!),ForwardDiff.JacobianConfig{ForwardDiff.Tag{typeof(f!),Float32},Float32,2,Tuple{MArray{Tuple{2},ForwardDiff.Dual{ForwardDiff.Tag{typeof(f!),Float32},Float32,2},1,2},MArray{Tuple{2},ForwardDiff.Dual{ForwardDiff.Tag{typeof(f!),Float32},Float32,2},1,2}}},MArray{Tuple{2},Float32,1,2}})(::MArray{Tuple{2},Float32,1,2}, ::MArray{Tuple{2,2},Float32,2,4}, ::MArray{Tuple{2},Float32,1,2}) at C:\Users\kawcz\.julia\packages\NLSolversBase\QPnui\src\objective_types\oncedifferentiable.jl:160
 [4] value_jacobian!!(::OnceDifferentiable{MArray{Tuple{2},Float32,1,2},MArray{Tuple{2,2},Float32,2,4},MArray{Tuple{2},Float32,1,2}}, ::MArray{Tuple{2},Float32,1,2}, ::MArray{Tuple{2,2},Float32,2,4}, ::MArray{Tuple{2},Float32,1,2}) at C:\Users\kawcz\.julia\packages\NLSolversBase\QPnui\src\interface.jl:124
 [5] value_jacobian!! at C:\Users\kawcz\.julia\packages\NLSolversBase\QPnui\src\interface.jl:122 [inlined]
 [6] trust_region_(::OnceDifferentiable{MArray{Tuple{2},Float32,1,2},MArray{Tuple{2,2},Float32,2,4},MArray{Tuple{2},Float32,1,2}}, ::MArray{Tuple{2},Float32,1,2}, ::Float32, ::Float32, ::Int64, ::Bool, ::Bool, ::Bool, ::Float32, ::Bool, ::NLsolve.NewtonTrustRegionCache{MArray{Tuple{2},Float32,1,2}}) at C:\Users\kawcz\.julia\packages\NLsolve\04rfI\src\solvers\trust_region.jl:119
 [7] trust_region at C:\Users\kawcz\.julia\packages\NLsolve\04rfI\src\solvers\trust_region.jl:235 [inlined] (repeats 2 times)
 [8] nlsolve(::OnceDifferentiable{MArray{Tuple{2},Float32,1,2},MArray{Tuple{2,2},Float32,2,4},MArray{Tuple{2},Float32,1,2}}, ::MArray{Tuple{2},Float32,1,2}; method::Symbol, xtol::Float32, ftol::Float32, iterations::Int64, store_trace::Bool, show_trace::Bool, extended_trace::Bool, linesearch::Static, linsolve::NLsolve.var"#27#29", factor::Float32, autoscale::Bool, m::Int64, beta::Int64, aa_start::Int64, droptol::Float32) at C:\Users\kawcz\.julia\packages\NLsolve\04rfI\src\nlsolve\nlsolve.jl:26
 [9] nlsolve(::Function, ::MArray{Tuple{2},Float32,1,2}; method::Symbol, autodiff::Symbol, inplace::Bool, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\kawcz\.julia\packages\NLsolve\04rfI\src\nlsolve\nlsolve.jl:52
 [10] top-level scope at REPL[7]:1
@pkofod
Copy link
Member

pkofod commented Dec 16, 2020

Does it work with JuliaDiff/DiffResults.jl#18 ?

@charleskawczynski
Copy link
Author

Does it work with JuliaDiff/DiffResults.jl#18 ?

Yes, it does.

@pkofod
Copy link
Member

pkofod commented Dec 17, 2020

Okay. We can add a test here then when it's merged. Please let me know when it's in :)

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

Successfully merging a pull request may close this issue.

2 participants