-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
Different solutions for in-place and not in-place functions with Vern7 #86
Comments
I found the error, it's the first Interestingly, for |
The best thing to check would be
|
I checked it with julia> macroexpand(:(@inbounds atmp[i] = (@muladd(update[i] - dt*(bhat1*k1[i] + bhat4*k4[i] + bhat5*k5[i] + bhat6*k6[i] + bhat7*k7[i] + bhat10*k10[i]))./@muladd(atol+max(abs(uprev[i]),abs(u[i])).*rtol))))
quote
$(Expr(:inbounds, true))
atmp[i] = (update[i] - dt * (bhat1 * k1[i] + bhat4 * k4[i] + bhat5 * k5[i] + bhat6 * k6[i] + bhat7 * k7[i] + bhat10 * k10[i])) ./ (atol + max(abs(uprev[i]), abs(u[i])) .* rtol)
$(Expr(:inbounds, :pop))
end whereas moving the first julia> macroexpand(:(@inbounds atmp[i] = (update[i] - dt*(@muladd(bhat1*k1[i] + bhat4*k4[i] + bhat5*k5[i] + bhat6*k6[i] + bhat7*k7[i] + bhat10*k10[i])))./@muladd(atol+max(abs(uprev[i]),abs(u[i]))*rtol)))
quote
$(Expr(:inbounds, true))
atmp[i] = (update[i] - dt * (muladd)(bhat1, k1[i], (muladd)(bhat4, k4[i], (muladd)(bhat5, k5[i], (muladd)(bhat6, k6[i], (muladd)(bhat7, k7[i], bhat10 * k10[i])))))) ./ (muladd)(max(abs(uprev[i]), abs(u[i])), rtol, atol)
$(Expr(:inbounds, :pop))
end So I guess we should change it to the latter expression. However, since the corresponding line of the not in-place method creates the expression julia> macroexpand(:(integrator.EEst = integrator.opts.internalnorm( ((update - dt*(@muladd(bhat1*k1 + bhat4*k4 + bhat5*k5 + bhat6*k6 + bhat7*k7 + bhat10*k10)))./@muladd(integrator.opts.abstol+max.(abs.(uprev),abs.(u)).*integrator.opts.reltol)))))
:(integrator.EEst = integrator.opts.internalnorm((update - dt * (muladd)(bhat1, k1, (muladd)(bhat4, k4, (muladd)(bhat5, k5, (muladd)(bhat6, k6, (muladd)(bhat7, k7, bhat10 * k10)))))) ./ (integrator.opts.abstol + max.(abs.(uprev), abs.(u)) .* integrator.opts.reltol))) and hence does not apply By the way, the same problems occur for https://github.com/JuliaDiffEq/OrdinaryDiffEq.jl/blob/master/src/integrators/verner_rk_integrators.jl#L393 There are two |
I thought I fixed the |
So do you suggest removing the second @muladd(integrator.opts.abstol+max.(abs.(uprev),abs.(u)).*integrator.opts.reltol))) ? And removing dots in lines with only scalar operations, such as @muladd(atol+max(abs(uprev[i]),abs(u[i])).*rtol)) ? And regarding the original problem with subtractions (which is caused by https://github.com/JuliaDiffEq/DiffEqBase.jl/blob/master/src/utils.jl#L34 ) - should |
Well, we don't want to remove muladd.(integrator.opts.abstol,max.(abs.(uprev),abs.(u)),integrator.opts.reltol) That should then fuse correctly and be everything we need.
Yeah. That'll make nested arrays never work though, but I am not convinced that it's something we could support without a So sure, delete these extra dots is a good fix.
It's probably best to just extend it to handle subtraction, though |
Since |
Just tested the example above on the master branch, and it seems to work now (although I still have to update the Vern methods to the syntax of the new |
During testing of PR SciML/DelayDiffEq.jl#17 I discovered that
Vern7
produces slightly different results for in-place and not in-place functions already for ODEs:The text was updated successfully, but these errors were encountered: