Skip to content

Commit 8179609

Browse files
Merge pull request #937 from prbzrg/use-alg
use correct `alg`
2 parents b6195fd + c7dd384 commit 8179609

File tree

1 file changed

+32
-41
lines changed

1 file changed

+32
-41
lines changed

src/solve.jl

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ function Base.showerror(io::IO, e::NaNTspanError)
190190
println(io, TruncatedStacktraces.VERBOSE_MSG)
191191
end
192192

193-
194193
const NON_SOLVER_MESSAGE = """
195194
The arguments to solve are incorrect.
196195
The second argument must be a solver choice, `solve(prob,alg)`
@@ -454,9 +453,9 @@ end
454453

455454
function init_call(_prob, args...; merge_callbacks = true, kwargshandle = nothing,
456455
kwargs...)
457-
458456
kwargshandle = kwargshandle === nothing ? KeywordArgError : kwargshandle
459-
kwargshandle = has_kwargs(_prob) && haskey(_prob.kwargs, :kwargshandle) ? _prob.kwargs[:kwargshandle] : kwargshandle
457+
kwargshandle = has_kwargs(_prob) && haskey(_prob.kwargs, :kwargshandle) ?
458+
_prob.kwargs[:kwargshandle] : kwargshandle
460459

461460
if has_kwargs(_prob)
462461
if merge_callbacks && haskey(_prob.kwargs, :callback) && haskey(kwargs, :callback)
@@ -505,38 +504,38 @@ function init_up(prob::DEProblem, sensealg, u0, p, args...; kwargs...)
505504
_alg = prepare_alg(alg, _prob.u0, _prob.p, _prob)
506505
check_prob_alg_pairing(_prob, alg) # alg for improved inference
507506

508-
if length(args) === 1 && args[1] === nothing
507+
if length(args) <= 1
509508
init_call(_prob, _alg; kwargs...)
510509
else
511-
init_call(_prob, _alg, args[2:end]...; kwargs...)
510+
init_call(_prob, _alg, Base.tail(args)...; kwargs...)
512511
end
513512
elseif haskey(prob.kwargs, :alg) && (isempty(args) || args[1] === nothing)
514513
alg = prob.kwargs[:alg]
515514
_prob = get_concrete_problem(prob, isadaptive(alg); kwargs...)
516515
_alg = prepare_alg(alg, _prob.u0, _prob.p, _prob)
517516
check_prob_alg_pairing(_prob, alg) # alg for improved inference
518-
if length(args) === 1 && args[1] === nothing
517+
if length(args) <= 1
519518
init_call(_prob, _alg; kwargs...)
520519
else
521-
init_call(_prob, _alg, args[2:end]...; kwargs...)
520+
init_call(_prob, _alg, Base.tail(args)...; kwargs...)
522521
end
523522
elseif !isempty(args) && typeof(args[1]) <: DEAlgorithm
524523
alg = args[1]
525524
_prob = get_concrete_problem(prob, isadaptive(alg); kwargs...)
526525
check_prob_alg_pairing(_prob, alg)
527526
_alg = prepare_alg(alg, _prob.u0, _prob.p, _prob)
528-
init_call(_prob, _alg, args[2:end]...; kwargs...)
529-
else
527+
init_call(_prob, _alg, Base.tail(args)...; kwargs...)
528+
else # Default algorithm handling
530529
_prob = get_concrete_problem(prob, !(typeof(prob) <: DiscreteProblem); kwargs...)
531530
init_call(_prob, args...; kwargs...)
532531
end
533532
end
534533

535534
function solve_call(_prob, args...; merge_callbacks = true, kwargshandle = nothing,
536535
kwargs...)
537-
538536
kwargshandle = kwargshandle === nothing ? KeywordArgError : kwargshandle
539-
kwargshandle = has_kwargs(_prob) && haskey(_prob.kwargs, :kwargshandle) ? _prob.kwargs[:kwargshandle] : kwargshandle
537+
kwargshandle = has_kwargs(_prob) && haskey(_prob.kwargs, :kwargshandle) ?
538+
_prob.kwargs[:kwargshandle] : kwargshandle
540539

541540
if has_kwargs(_prob)
542541
if merge_callbacks && haskey(_prob.kwargs, :callback) && haskey(kwargs, :callback)
@@ -1007,32 +1006,28 @@ function solve_up(prob::Union{DEProblem, NonlinearProblem}, sensealg, u0, p, arg
10071006
_prob = get_concrete_problem(prob, isadaptive(alg); u0 = u0, p = p, kwargs...)
10081007
_alg = prepare_alg(alg, _prob.u0, _prob.p, _prob)
10091008
check_prob_alg_pairing(_prob, alg) # use alg for improved inference
1010-
if length(args) === 1 && args[1] === nothing
1009+
if length(args) <= 1
10111010
solve_call(_prob, _alg; kwargs...)
10121011
else
1013-
solve_call(_prob, _alg, args[2:end]...; kwargs...)
1012+
solve_call(_prob, _alg, Base.tail(args)...; kwargs...)
10141013
end
10151014
elseif haskey(prob.kwargs, :alg) && (isempty(args) || args[1] === nothing)
10161015
alg = prob.kwargs[:alg]
10171016
_prob = get_concrete_problem(prob, isadaptive(alg); u0 = u0, p = p, kwargs...)
10181017
_alg = prepare_alg(alg, _prob.u0, _prob.p, _prob)
10191018
check_prob_alg_pairing(_prob, alg) # use alg for improved inference
1020-
if length(args) === 1 && args[1] === nothing
1019+
if length(args) <= 1
10211020
solve_call(_prob, _alg; kwargs...)
10221021
else
1023-
solve_call(_prob, _alg, args[2:end]...; kwargs...)
1022+
solve_call(_prob, _alg, Base.tail(args)...; kwargs...)
10241023
end
10251024
elseif !isempty(args) && typeof(args[1]) <: DEAlgorithm
10261025
alg = args[1]
10271026
_prob = get_concrete_problem(prob, isadaptive(alg); u0 = u0, p = p, kwargs...)
10281027
_alg = prepare_alg(alg, _prob.u0, _prob.p, _prob)
10291028
check_prob_alg_pairing(_prob, alg) # use alg for improved inference
10301029
solve_call(_prob, _alg, Base.tail(args)...; kwargs...)
1031-
elseif isempty(args) # Default algorithm handling
1032-
_prob = get_concrete_problem(prob, !(typeof(prob) <: DiscreteProblem); u0 = u0,
1033-
p = p, kwargs...)
1034-
solve_call(_prob, args...; kwargs...)
1035-
else
1030+
else # Default algorithm handling
10361031
_prob = get_concrete_problem(prob, !(typeof(prob) <: DiscreteProblem); u0 = u0,
10371032
p = p, kwargs...)
10381033
solve_call(_prob, args...; kwargs...)
@@ -1425,17 +1420,15 @@ end
14251420

14261421
function _solve_adjoint(prob, sensealg, u0, p, originator, args...; merge_callbacks = true,
14271422
kwargs...)
1428-
_prob = if haskey(kwargs, :alg) && (isempty(args) || args[1] === nothing)
1423+
alg, _prob = if haskey(kwargs, :alg) && (isempty(args) || args[1] === nothing)
14291424
alg = kwargs[:alg]
1430-
get_concrete_problem(prob, isadaptive(alg); u0 = u0, p = p, kwargs...)
1425+
alg, get_concrete_problem(prob, isadaptive(alg); u0 = u0, p = p, kwargs...)
14311426
elseif !isempty(args) && typeof(args[1]) <: DEAlgorithm
14321427
alg = args[1]
1433-
get_concrete_problem(prob, isadaptive(alg); u0 = u0, p = p, kwargs...)
1434-
elseif isempty(args) # Default algorithm handling
1435-
get_concrete_problem(prob, !(typeof(prob) <: DiscreteProblem); u0 = u0, p = p,
1436-
kwargs...)
1437-
else
1438-
get_concrete_problem(prob, !(typeof(prob) <: DiscreteProblem); u0 = u0, p = p,
1428+
alg, get_concrete_problem(prob, isadaptive(alg); u0 = u0, p = p, kwargs...)
1429+
else # Default algorithm handling
1430+
alg = !(typeof(prob) <: DiscreteProblem)
1431+
alg, get_concrete_problem(prob, alg; u0 = u0, p = p,
14391432
kwargs...)
14401433
end
14411434

@@ -1452,26 +1445,24 @@ function _solve_adjoint(prob, sensealg, u0, p, originator, args...; merge_callba
14521445
end
14531446

14541447
if isempty(args)
1455-
_concrete_solve_adjoint(_prob, nothing, sensealg, u0, p, originator; kwargs...)
1448+
_concrete_solve_adjoint(_prob, alg, sensealg, u0, p, originator; kwargs...)
14561449
else
1457-
_concrete_solve_adjoint(_prob, args[1], sensealg, u0, p, originator,
1450+
_concrete_solve_adjoint(_prob, alg, sensealg, u0, p, originator,
14581451
Base.tail(args)...; kwargs...)
14591452
end
14601453
end
14611454

14621455
function _solve_forward(prob, sensealg, u0, p, originator, args...; merge_callbacks = true,
14631456
kwargs...)
1464-
_prob = if haskey(kwargs, :alg) && (isempty(args) || args[1] === nothing)
1457+
alg, _prob = if haskey(kwargs, :alg) && (isempty(args) || args[1] === nothing)
14651458
alg = kwargs[:alg]
1466-
get_concrete_problem(prob, isadaptive(alg); u0 = u0, p = p, kwargs...)
1459+
alg, get_concrete_problem(prob, isadaptive(alg); u0 = u0, p = p, kwargs...)
14671460
elseif !isempty(args) && typeof(args[1]) <: DEAlgorithm
14681461
alg = args[1]
1469-
get_concrete_problem(prob, isadaptive(alg); u0 = u0, p = p, kwargs...)
1470-
elseif isempty(args) # Default algorithm handling
1471-
get_concrete_problem(prob, !(typeof(prob) <: DiscreteProblem); u0 = u0, p = p,
1472-
kwargs...)
1473-
else
1474-
get_concrete_problem(prob, !(typeof(prob) <: DiscreteProblem); u0 = u0, p = p,
1462+
alg, get_concrete_problem(prob, isadaptive(alg); u0 = u0, p = p, kwargs...)
1463+
else # Default algorithm handling
1464+
alg = !(typeof(prob) <: DiscreteProblem)
1465+
alg, get_concrete_problem(prob, alg; u0 = u0, p = p,
14751466
kwargs...)
14761467
end
14771468

@@ -1488,10 +1479,10 @@ function _solve_forward(prob, sensealg, u0, p, originator, args...; merge_callba
14881479
end
14891480

14901481
if isempty(args)
1491-
_concrete_solve_forward(prob, nothing, sensealg, u0, p; kwargs...)
1482+
_concrete_solve_forward(_prob, alg, sensealg, u0, p, originator; kwargs...)
14921483
else
1493-
_concrete_solve_forward(prob, args[1], sensealg, u0, p, Base.tail(args)...;
1494-
kwargs...)
1484+
_concrete_solve_forward(_prob, alg, sensealg, u0, p, originator,
1485+
Base.tail(args)...; kwargs...)
14951486
end
14961487
end
14971488

0 commit comments

Comments
 (0)