Hi,
without your full code (with the return it seems to be part of a function?) I have to guess a bit (see Please read: make it easier to help you) but I think I see what you did.
If you would execute your first line on REPL you would indeed just get the time and not the printed statistics, since that is what @elapsed
returns from the code it runs. So (from my code)
using Optim
f(x) = (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2
elapsed_time = @elapsed begin
res = optimize(f, [0.0, 0.0])
end
just prints the time. res
however is the whole result, i.e.
julia> typeof(res)
Optim.MultivariateOptimizationResults{NelderMead{Optim.AffineSimplexer, Optim.AdaptiveParameters}, Vector{Float64}, Float64, Float64, Vector{OptimizationState{Float64, NelderMead{Optim.AffineSimplexer, Optim.AdaptiveParameters}}}, Bool, NamedTuple{(:f_limit_reached, :g_limit_reached, :h_limit_reached, :time_limit, :callback, :f_increased), NTuple{6, Bool}}}
(and not just a number, but a very complicated type). If you print it (or get it as a return value from any function on REPL) there is – however – a nicer display, namely the full statistics (because this type really does not look nice) we already saw above.
If your posted code is within a function (which I just assume due to the return
in the last line), then your whole function is run but returns res (the complicated type above) and that on REPL prints the statistics again.
So at the place you call the function (whose inner part I think you posted) put a ;
behind that function call
Or change what you return here, do you really need to return all of res
? Or is maybe Optim.minimizer(res)
enough? That of course depends on your function
PS: And I just noticed these are your first steps here – so: Welcome to Julia Discourse