Skip to content

Commit 42db3b7

Browse files
Merge pull request #2498 from SciML/fastpower
Change Core, Extrapolation, and FIRK to using FastPower.jl
2 parents c2ffc74 + 60d83c6 commit 42db3b7

File tree

10 files changed

+27
-17
lines changed

10 files changed

+27
-17
lines changed

lib/OrdinaryDiffEqCore/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1414
EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
1515
FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898"
1616
FastClosures = "9aa1b823-49e4-5ca5-8b0f-3971ec8bab6a"
17+
FastPower = "a4df4552-cc26-4903-aec0-212e50a0e84b"
1718
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
1819
FunctionWrappersWrappers = "77dc65aa-8811-40c2-897b-53d922fa7daf"
1920
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
@@ -53,6 +54,7 @@ DocStringExtensions = "0.9"
5354
EnumX = "1"
5455
FastBroadcast = "0.2, 0.3"
5556
FastClosures = "0.3"
57+
FastPower = "1"
5658
FillArrays = "1.9"
5759
FunctionWrappersWrappers = "0.1"
5860
InteractiveUtils = "1.9"

lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ using PrecompileTools
1919

2020
import FillArrays: Trues, Falses
2121

22+
import FastPower
23+
2224
# Interfaces
2325
import DiffEqBase: solve!, step!, initialize!, isadaptive
2426

lib/OrdinaryDiffEqCore/src/integrators/controllers.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ end
6868
q = inv(qmax)
6969
else
7070
expo = 1 / (get_current_adaptive_order(alg, integrator.cache) + 1)
71-
qtmp = DiffEqBase.fastpow(EEst, expo) / gamma
71+
qtmp = FastPower.fastpower(EEst, expo) / gamma
7272
@fastmath q = DiffEqBase.value(max(inv(qmax), min(inv(qmin), qtmp)))
7373
# TODO: Shouldn't this be in `step_accept_controller!` as for the PI controller?
7474
integrator.qold = DiffEqBase.value(integrator.dt) / q
@@ -141,8 +141,8 @@ end
141141
if iszero(EEst)
142142
q = inv(qmax)
143143
else
144-
q11 = DiffEqBase.fastpow(EEst, float(beta1))
145-
q = q11 / DiffEqBase.fastpow(qold, float(beta2))
144+
q11 = FastPower.fastpower(EEst, float(beta1))
145+
q = q11 / FastPower.fastpower(qold, float(beta2))
146146
integrator.q11 = q11
147147
@fastmath q = max(inv(qmax), min(inv(qmin), q / gamma))
148148
end

lib/OrdinaryDiffEqExtrapolation/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ version = "1.1.0"
66
[deps]
77
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
88
FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898"
9+
FastPower = "a4df4552-cc26-4903-aec0-212e50a0e84b"
910
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
1011
MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221"
1112
OrdinaryDiffEqCore = "bbf590c4-e513-4bbe-9b18-05decba2e5d8"
@@ -18,6 +19,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1819
DiffEqBase = "6.152.2"
1920
DiffEqDevTools = "2.44.4"
2021
FastBroadcast = "0.3.5"
22+
FastPower = "1"
2123
LinearSolve = "2.32.0"
2224
MuladdMacro = "0.2.4"
2325
OrdinaryDiffEqCore = "1.1"

lib/OrdinaryDiffEqExtrapolation/src/OrdinaryDiffEqExtrapolation.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import OrdinaryDiffEqCore: alg_order, alg_maximum_order, get_current_adaptive_or
2020
differentiation_rk_docstring
2121
using DiffEqBase, FastBroadcast, Polyester, MuladdMacro, RecursiveArrayTools, LinearSolve
2222
import OrdinaryDiffEqCore
23+
import FastPower
2324
import OrdinaryDiffEqDifferentiation: TimeDerivativeWrapper, UDerivativeWrapper, calc_J,
2425
WOperator, TimeGradientWrapper, UJacobianWrapper,
2526
build_grad_config,

lib/OrdinaryDiffEqExtrapolation/src/controllers.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ function stepsize_controller_internal!(integrator,
3131
else
3232
# Update gamma and beta1
3333
controller.beta1 = typeof(controller.beta1)(1 // (2integrator.cache.n_curr + 1))
34-
integrator.opts.gamma = DiffEqBase.fastpow(typeof(integrator.opts.gamma)(1 // 4),
34+
integrator.opts.gamma = FastPower.fastpower(typeof(integrator.opts.gamma)(1 // 4),
3535
controller.beta1)
3636
# Compute new stepsize scaling
37-
qtmp = DiffEqBase.fastpow(integrator.EEst, controller.beta1) / integrator.opts.gamma
37+
qtmp = FastPower.fastpower(integrator.EEst, controller.beta1) / integrator.opts.gamma
3838
@fastmath q = max(inv(integrator.opts.qmax), min(inv(integrator.opts.qmin), qtmp))
3939
end
4040
integrator.cache.Q[integrator.cache.n_curr - alg.min_order + 1] = q
@@ -57,10 +57,10 @@ function stepsize_predictor!(integrator,
5757
s_new = stage_number[n_new - alg.min_order + 1]
5858
# Update gamma and beta1
5959
controller.beta1 = typeof(controller.beta1)(1 // (2integrator.cache.n_curr + 1))
60-
integrator.opts.gamma = DiffEqBase.fastpow(typeof(integrator.opts.gamma)(1 // 4),
60+
integrator.opts.gamma = FastPower.fastpower(typeof(integrator.opts.gamma)(1 // 4),
6161
controller.beta1)
6262
# Compute new stepsize scaling
63-
qtmp = EEst * DiffEqBase.fastpow(DiffEqBase.fastpow(tol, (1.0 - s_curr / s_new)),
63+
qtmp = EEst * FastPower.fastpower(FastPower.fastpower(tol, (1.0 - s_curr / s_new)),
6464
controller.beta1) / integrator.opts.gamma
6565
@fastmath q = max(inv(integrator.opts.qmax), min(inv(integrator.opts.qmin), qtmp))
6666
end
@@ -158,12 +158,12 @@ function stepsize_controller_internal!(integrator,
158158
controller.beta1 = typeof(controller.beta1)(1 //
159159
(integrator.cache.n_curr - 1))
160160
end
161-
integrator.opts.gamma = DiffEqBase.fastpow(
161+
integrator.opts.gamma = FastPower.fastpower(
162162
typeof(integrator.opts.gamma)(65 //
163163
100),
164164
controller.beta1)
165165
# Compute new stepsize scaling
166-
qtmp = DiffEqBase.fastpow(integrator.EEst, controller.beta1) /
166+
qtmp = FastPower.fastpower(integrator.EEst, controller.beta1) /
167167
(integrator.opts.gamma)
168168
@fastmath q = max(inv(integrator.opts.qmax),
169169
min(inv(integrator.opts.qmin), qtmp))
@@ -175,12 +175,12 @@ function stepsize_controller_internal!(integrator,
175175
else
176176
# Update gamma and beta1
177177
controller.beta1 = typeof(controller.beta1)(1 // (2integrator.cache.n_curr + 1))
178-
integrator.opts.gamma = DiffEqBase.fastpow(
178+
integrator.opts.gamma = FastPower.fastpower(
179179
typeof(integrator.opts.gamma)(65 //
180180
100),
181181
controller.beta1)
182182
# Compute new stepsize scaling
183-
qtmp = DiffEqBase.fastpow(integrator.EEst, controller.beta1) /
183+
qtmp = FastPower.fastpower(integrator.EEst, controller.beta1) /
184184
integrator.opts.gamma
185185
@fastmath q = max(inv(integrator.opts.qmax),
186186
min(inv(integrator.opts.qmin), qtmp))

lib/OrdinaryDiffEqFIRK/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ version = "1.1.1"
66
[deps]
77
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
88
FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898"
9+
FastPower = "a4df4552-cc26-4903-aec0-212e50a0e84b"
910
GenericLinearAlgebra = "14197337-ba66-59df-a3e3-ca00e7dcff7a"
1011
GenericSchur = "c145ed77-6b09-5dd9-b285-bf645a82121e"
1112
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -25,6 +26,7 @@ Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
2526
DiffEqBase = "6.152.2"
2627
DiffEqDevTools = "2.44.4"
2728
FastBroadcast = "0.3.5"
29+
FastPower = "1"
2830
LinearAlgebra = "<0.0.1, 1"
2931
LinearSolve = "2.32.0"
3032
MuladdMacro = "0.2.4"

lib/OrdinaryDiffEqFIRK/src/OrdinaryDiffEqFIRK.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ using LinearAlgebra: I, UniformScaling, mul!, lu
2424
import LinearSolve
2525
import FastBroadcast: @..
2626
import OrdinaryDiffEqCore
27+
import FastPower
2728

2829
using OrdinaryDiffEqDifferentiation: UJacobianWrapper, build_J_W, build_jac_config,
2930
UDerivativeWrapper, calc_J!, dolinsolve, calc_J,

lib/OrdinaryDiffEqFIRK/src/controllers.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
fac = min(gamma, (1 + 2 * maxiters) * gamma / (iter + 2 * maxiters))
1818
end
1919
expo = 1 / (get_current_adaptive_order(alg, integrator.cache) + 1)
20-
qtmp = DiffEqBase.fastpow(EEst, expo) / fac
20+
qtmp = FastPower.fastpower(EEst, expo) / fac
2121
@fastmath q = DiffEqBase.value(max(inv(qmax), min(inv(qmin), qtmp)))
2222
integrator.qold = q
2323
end
@@ -31,7 +31,7 @@ function step_accept_controller!(integrator, controller::PredictiveController, a
3131
if integrator.success_iter > 0
3232
expo = 1 / (get_current_adaptive_order(alg, integrator.cache) + 1)
3333
qgus = (integrator.dtacc / integrator.dt) *
34-
DiffEqBase.fastpow((EEst^2) / integrator.erracc, expo)
34+
FastPower.fastpower((EEst^2) / integrator.erracc, expo)
3535
qgus = max(inv(qmax), min(inv(qmin), qgus / gamma))
3636
qacc = max(q, qgus)
3737
else

test/interface/composite_algorithm_test.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ v = @inferred OrdinaryDiffEqCore.ode_extrapolant(
4747
alg_mixed_r = CompositeAlgorithm((ABM54(), Tsit5()), reverse_choice)
4848
alg_mixed2 = CompositeAlgorithm((Tsit5(), ABM54()), reverse_choice)
4949

50-
@test_throws ErrorException solve(prob_ode_linear, alg_mixed)
50+
@test_throws ArgumentError solve(prob_ode_linear, alg_mixed)
5151
sol2 = solve(prob_ode_linear, Tsit5())
52-
sol3 = solve(prob_ode_linear, alg_mixed; dt = 0.05)
53-
sol4 = solve(prob_ode_linear, alg_mixed_r; dt = 0.05)
54-
sol5 = solve(prob_ode_linear, alg_mixed2; dt = 0.05)
52+
sol3 = solve(prob_ode_linear, alg_mixed; dt = 0.05, adaptive=false)
53+
sol4 = solve(prob_ode_linear, alg_mixed_r; dt = 0.05, adaptive=false)
54+
sol5 = solve(prob_ode_linear, alg_mixed2; dt = 0.05, adaptive=false)
5555
@test sol3.t == sol4.t && sol3.u == sol4.u
5656
@test sol3(0.8)sol2(0.8) atol=1e-4
5757
@test sol5(0.8)sol2(0.8) atol=1e-4

0 commit comments

Comments
 (0)