Hi all,
Perhaps this should be taken as a comment, but I wanted to raise it nonetheless, as it is an issue I have run into time and time again, and I am beginning to suspect I am missing something.
The following code, taken from the Optim.jl docs, runs fine in Julia 1.0.2:
using Optim
rosenbrock(x) = (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2
result = optimize(rosenbrock, [0.0,0.0], BFGS())
However, when I change this to:
using Optim
rosenbrock(x) = (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2
result = optimize(rosenbrock, [0,0], BFGS())
I get the following error:
InexactError: Int64(Int64, NaN)
Stacktrace:
[1] Type at ./float.jl:700 [inlined]
[2] convert at ./number.jl:7 [inlined]
[3] fill!(::Array{Int64,1}, ::Float64) at ./array.jl:386
[4] x_of_nans at /Users/thomasmoore/.julia/packages/NLSolversBase/ylZ0n/src/NLSolversBase.jl:45 [inlined]
[5] alloc_DF at /Users/thomasmoore/.julia/packages/NLSolversBase/ylZ0n/src/objective_types/abstract.jl:21 [inlined]
[6] Type at ./none:0 [inlined]
[7] promote_objtype at /Users/thomasmoore/.julia/packages/Optim/ULNLZ/src/multivariate/optimize/interface.jl:40 [inlined]
[8] #optimize#87(::Bool, ::Symbol, ::Function, ::Function, ::Array{Int64,1}, ::BFGS{InitialStatic{Float64},HagerZhang{Float64,Base.RefValue{Bool}},getfield(Optim, Symbol("##17#19"))}, ::Optim.Options{Float64,Nothing}) at /Users/thomasmoore/.julia/packages/Optim/ULNLZ/src/multivariate/optimize/interface.jl:113
[9] optimize(::Function, ::Array{Int64,1}, ::BFGS{InitialStatic{Float64},HagerZhang{Float64,Base.RefValue{Bool}},getfield(Optim, Symbol("##17#19"))}, ::Optim.Options{Float64,Nothing}) at /Users/thomasmoore/.julia/packages/Optim/ULNLZ/src/multivariate/optimize/interface.jl:113 (repeats 2 times)
[10] top-level scope at In[33]:3
All I have done is change an input from a float to an integer, and the program has failed. Itās a little embarrassing, but in the year Iāve been playing around with Julia, this exact problem has cost me a lot of time, when working with ODE solvers, optimisation routines, and several other packages.
Now, part of me feels that, given that 0 == 0.0 returns True, this should simply never be an issue, but Iām sure there are technical reasons why Integers and Floats must be treated separately.
I suppose my main concern is that, to a novice like me, the error message is completely unintuitive. I donāt know if Iāve installed something incorrectly, made a mistake in my function definition, or done something else entirely wrong.
Are there any plans in the works to provide a more intuitive error message - even something like āInt64 provided where Float64 expected in test.jl, line 22ā. Alternatively, perhaps it is possible to provide some guidance on how to interpret these error messages? For the novice user like me, itās rather daunting diving straight into the Julia codebase, especially for ODE solvers, which interlink with so many different packages.
Thanks
Tom