JuliaNLSolvers / NLsolve.jl

Julia solvers for systems of nonlinear equations and mixed complementarity problems

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UndefRefError with BigFloat

protogeezer opened this issue · comments

Example from the website works with Float64 and Float32 args, e.g., but fails with BigFloat.

Stephen

julia> using NLsolve

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> function j!(J, x)
           J[1, 1] = x[2]^3-7
           J[1, 2] = 3*x[2]^2*(x[1]+3)
           u = exp(x[1])*cos(x[2]*exp(x[1])-1)
           J[2, 1] = x[2]*u
           J[2, 2] = u
       end
j! (generic function with 1 method)

julia> nlsolve(f!, j!, [ 0.1; 1.2])
Results of Nonlinear Solver Algorithm
 * Algorithm: Trust-region with dogleg and autoscaling
 * Starting Point: [0.1, 1.2]
 * Zero: [-3.7818049096324184e-16, 1.0000000000000002]
 * Inf-norm of residuals: 0.000000
 * Iterations: 4
 * Convergence: true
   * |x - x'| < 0.0e+00: false
   * |f(x)| < 1.0e-08: true
 * Function Calls (f): 5
 * Jacobian Calls (df/dx): 5

julia> nlsolve(f!, j!, [ BigFloat(0.1);BigFloat( 1.2)])
ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] getindex at ./array.jl:809 [inlined]
 [2] getindex at ./multidimensional.jl:557 [inlined]
 [3] _broadcast_getindex at ./broadcast.jl:614 [inlined]
 [4] _getindex at ./broadcast.jl:645 [inlined]
 [5] _getindex at ./broadcast.jl:644 [inlined]
 [6] _broadcast_getindex at ./broadcast.jl:620 [inlined]
 [7] _getindex at ./broadcast.jl:644 [inlined]
 [8] _broadcast_getindex at ./broadcast.jl:620 [inlined]
 [9] getindex at ./broadcast.jl:575 [inlined]
 [10] macro expansion at ./broadcast.jl:932 [inlined]
 [11] macro expansion at ./simdloop.jl:77 [inlined]
 [12] copyto! at ./broadcast.jl:931 [inlined]
 [13] copyto! at ./broadcast.jl:886 [inlined]
 [14] copy at ./broadcast.jl:862 [inlined]
 [15] materialize at ./broadcast.jl:837 [inlined]
 [16] alloc_DF(::Array{BigFloat,1}, ::Array{BigFloat,1}) at /Users/sjbespa/.julia/packages/NLSolversBase/d9ieK/src/objective_types/abstract.jl:19
 [17] OnceDifferentiable at /Users/sjbespa/.julia/packages/NLSolversBase/d9ieK/src/objective_types/oncedifferentiable.jl:192 [inlined]
 [18] nlsolve(::Function, ::Function, ::Array{BigFloat,1}; inplace::Bool, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/sjbespa/.julia/packages/NLsolve/qSriF/src/nlsolve/nlsolve.jl:62
 [19] nlsolve(::Function, ::Function, ::Array{BigFloat,1}) at /Users/sjbespa/.julia/packages/NLsolve/qSriF/src/nlsolve/nlsolve.jl:61
 [20] top-level scope at REPL[6]:1

I may have to work on the printing, but I fixed it :)

Results of Nonlinear Solver Algorithm
 * Algorithm: Trust-region with dogleg and autoscaling
 * Starting Point: BigFloat[0.1000000000000000055511151231257827021181583404541015625, 1.1999999999999999555910790149937383830547332763671875]
 * Zero: BigFloat[-2.946409394679634938485093840724924263978449639073062163340279161426250047150898e-16, 1.000000000000000086081641142290574412337466219207267268280186065609437503798838]
 * Inf-norm of residuals: 0.000000
 * Iterations: 4
 * Convergence: true
   * |x - x'| < 0.0e+00: false
   * |f(x)| < 1.0e-08: true
 * Function Calls (f): 5
 * Jacobian Calls (df/dx): 5

thanks for the bugreport

No, just leave it open. If you look here #248 I've written "fixes #247" in the pull request. That has the effect that when that PR is merged, this issue will close automatically. Then I will tag a new version and it should be available through ]up in a few hours.