-
Notifications
You must be signed in to change notification settings - Fork 56
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
Avoid type promotions due to hard-coded tolerances #438
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #438 +/- ##
=======================================
Coverage 86.24% 86.24%
=======================================
Files 38 38
Lines 2413 2413
=======================================
Hits 2081 2081
Misses 332 332 ☔ View full report in Codecov by Sentry. |
Before changing anything and (maybe wastefully) re-running CI again, it looks like the pattern λ = oftype(rtol, 0.7) (and similar) can work instead of |
If I recall, the units need to be stripped for |
So sure, that seems like a more direct change. (Thanks much for this.) |
...in the `AlefieldPotraShi` solver.
My understanding is that The "outer" At any rate, switching to what I've just pushed does still pass the unitful tests locally. |
I've failed to find a proper test case for my particular problem, but along the way I've discovered another apparent mishandling of unitful numbers — the outstanding issue is that the following patch does not (Edit: Changed the diff to cover two test case loops rather than just one) diff --git a/src/convergence.jl b/src/convergence.jl
index c7379b4..4746638 100644
--- a/src/convergence.jl
+++ b/src/convergence.jl
@@ -205,7 +205,7 @@ function is_small_Δx(
state::AbstractUnivariateZeroState,
options,
)
- δ = abs(state.xn1 - state.xn0)
+ δ = _unitless(abs(state.xn1 - state.xn0))
δₐ, δᵣ = options.xabstol, options.xreltol
Δₓ = max(_unitless(δₐ), _unitless(abs(state.xn1)) * δᵣ)
Δₓ = sqrt(sqrt(sqrt((abs(_unitless(Δₓ)))))) # faster than x^(1/8)
diff --git a/test/test_composable.jl b/test/test_composable.jl
index b0ff7bf..bd6fede 100644
--- a/test/test_composable.jl
+++ b/test/test_composable.jl
@@ -29,12 +29,14 @@ using ForwardDiff
y0 = 16m
y(t) = -g * t^2 + v0 * t + y0
- for order in orders
+ @testset "$order" for order in orders
@test find_zero(y, 1.8s, order) ≈ 1.886053370668014s
+ @test find_zero(y, 1.8f0s, order) isa typeof(1.88f0s)
end
- for M in [Roots.Bisection(), Roots.A42(), Roots.AlefeldPotraShi()]
+ @testset "$M" for M in [Roots.Bisection(), Roots.A42(), Roots.AlefeldPotraShi()]
@test find_zero(y, (1.8s, 1.9s), M) ≈ 1.886053370668014s
+ @test find_zero(y, (1.8f0s, 1.9f0s), M) isa typeof(1.88f0s)
end
xrts = find_zeros(y, 0s, 10s) |
Thanks! Am I waiting for this new diff to be included before merging? |
Thanks again!! If this is ready to merge just let me know. |
I've added a slightly tweaked version of what I described above. With just the additional cases in the two loops, it's revealed that the change in I still haven't discovered a way to directly test my original problem and fixes (to the tolerances in |
Yes, good to go. |
...in the
AlefieldPotraShi
solver.I ran into these constants causing a type promotion from
Float32
toFloat64
in a code I'm writing. Changing these locally avoids the error for me.Unfortunately, I don't have an easy/isolated reproducer which can be turned into a test case — until the error arose, I had assumed a non-bracketing method was being used because I only provide an initial guess, so the implementation must get here on its own.