@@ -190,7 +190,6 @@ function Base.showerror(io::IO, e::NaNTspanError)
190
190
println (io, TruncatedStacktraces. VERBOSE_MSG)
191
191
end
192
192
193
-
194
193
const NON_SOLVER_MESSAGE = """
195
194
The arguments to solve are incorrect.
196
195
The second argument must be a solver choice, `solve(prob,alg)`
454
453
455
454
function init_call (_prob, args... ; merge_callbacks = true , kwargshandle = nothing ,
456
455
kwargs... )
457
-
458
456
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
460
459
461
460
if has_kwargs (_prob)
462
461
if merge_callbacks && haskey (_prob. kwargs, :callback ) && haskey (kwargs, :callback )
@@ -505,38 +504,38 @@ function init_up(prob::DEProblem, sensealg, u0, p, args...; kwargs...)
505
504
_alg = prepare_alg (alg, _prob. u0, _prob. p, _prob)
506
505
check_prob_alg_pairing (_prob, alg) # alg for improved inference
507
506
508
- if length (args) === 1 && args[ 1 ] === nothing
507
+ if length (args) <= 1
509
508
init_call (_prob, _alg; kwargs... )
510
509
else
511
- init_call (_prob, _alg, args[ 2 : end ] . .. ; kwargs... )
510
+ init_call (_prob, _alg, Base . tail ( args) ... ; kwargs... )
512
511
end
513
512
elseif haskey (prob. kwargs, :alg ) && (isempty (args) || args[1 ] === nothing )
514
513
alg = prob. kwargs[:alg ]
515
514
_prob = get_concrete_problem (prob, isadaptive (alg); kwargs... )
516
515
_alg = prepare_alg (alg, _prob. u0, _prob. p, _prob)
517
516
check_prob_alg_pairing (_prob, alg) # alg for improved inference
518
- if length (args) === 1 && args[ 1 ] === nothing
517
+ if length (args) <= 1
519
518
init_call (_prob, _alg; kwargs... )
520
519
else
521
- init_call (_prob, _alg, args[ 2 : end ] . .. ; kwargs... )
520
+ init_call (_prob, _alg, Base . tail ( args) ... ; kwargs... )
522
521
end
523
522
elseif ! isempty (args) && typeof (args[1 ]) <: DEAlgorithm
524
523
alg = args[1 ]
525
524
_prob = get_concrete_problem (prob, isadaptive (alg); kwargs... )
526
525
check_prob_alg_pairing (_prob, alg)
527
526
_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
530
529
_prob = get_concrete_problem (prob, ! (typeof (prob) <: DiscreteProblem ); kwargs... )
531
530
init_call (_prob, args... ; kwargs... )
532
531
end
533
532
end
534
533
535
534
function solve_call (_prob, args... ; merge_callbacks = true , kwargshandle = nothing ,
536
535
kwargs... )
537
-
538
536
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
540
539
541
540
if has_kwargs (_prob)
542
541
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
1007
1006
_prob = get_concrete_problem (prob, isadaptive (alg); u0 = u0, p = p, kwargs... )
1008
1007
_alg = prepare_alg (alg, _prob. u0, _prob. p, _prob)
1009
1008
check_prob_alg_pairing (_prob, alg) # use alg for improved inference
1010
- if length (args) === 1 && args[ 1 ] === nothing
1009
+ if length (args) <= 1
1011
1010
solve_call (_prob, _alg; kwargs... )
1012
1011
else
1013
- solve_call (_prob, _alg, args[ 2 : end ] . .. ; kwargs... )
1012
+ solve_call (_prob, _alg, Base . tail ( args) ... ; kwargs... )
1014
1013
end
1015
1014
elseif haskey (prob. kwargs, :alg ) && (isempty (args) || args[1 ] === nothing )
1016
1015
alg = prob. kwargs[:alg ]
1017
1016
_prob = get_concrete_problem (prob, isadaptive (alg); u0 = u0, p = p, kwargs... )
1018
1017
_alg = prepare_alg (alg, _prob. u0, _prob. p, _prob)
1019
1018
check_prob_alg_pairing (_prob, alg) # use alg for improved inference
1020
- if length (args) === 1 && args[ 1 ] === nothing
1019
+ if length (args) <= 1
1021
1020
solve_call (_prob, _alg; kwargs... )
1022
1021
else
1023
- solve_call (_prob, _alg, args[ 2 : end ] . .. ; kwargs... )
1022
+ solve_call (_prob, _alg, Base . tail ( args) ... ; kwargs... )
1024
1023
end
1025
1024
elseif ! isempty (args) && typeof (args[1 ]) <: DEAlgorithm
1026
1025
alg = args[1 ]
1027
1026
_prob = get_concrete_problem (prob, isadaptive (alg); u0 = u0, p = p, kwargs... )
1028
1027
_alg = prepare_alg (alg, _prob. u0, _prob. p, _prob)
1029
1028
check_prob_alg_pairing (_prob, alg) # use alg for improved inference
1030
1029
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
1036
1031
_prob = get_concrete_problem (prob, ! (typeof (prob) <: DiscreteProblem ); u0 = u0,
1037
1032
p = p, kwargs... )
1038
1033
solve_call (_prob, args... ; kwargs... )
@@ -1425,17 +1420,15 @@ end
1425
1420
1426
1421
function _solve_adjoint (prob, sensealg, u0, p, originator, args... ; merge_callbacks = true ,
1427
1422
kwargs... )
1428
- _prob = if haskey (kwargs, :alg ) && (isempty (args) || args[1 ] === nothing )
1423
+ alg, _prob = if haskey (kwargs, :alg ) && (isempty (args) || args[1 ] === nothing )
1429
1424
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... )
1431
1426
elseif ! isempty (args) && typeof (args[1 ]) <: DEAlgorithm
1432
1427
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,
1439
1432
kwargs... )
1440
1433
end
1441
1434
@@ -1452,26 +1445,24 @@ function _solve_adjoint(prob, sensealg, u0, p, originator, args...; merge_callba
1452
1445
end
1453
1446
1454
1447
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... )
1456
1449
else
1457
- _concrete_solve_adjoint (_prob, args[ 1 ] , sensealg, u0, p, originator,
1450
+ _concrete_solve_adjoint (_prob, alg , sensealg, u0, p, originator,
1458
1451
Base. tail (args)... ; kwargs... )
1459
1452
end
1460
1453
end
1461
1454
1462
1455
function _solve_forward (prob, sensealg, u0, p, originator, args... ; merge_callbacks = true ,
1463
1456
kwargs... )
1464
- _prob = if haskey (kwargs, :alg ) && (isempty (args) || args[1 ] === nothing )
1457
+ alg, _prob = if haskey (kwargs, :alg ) && (isempty (args) || args[1 ] === nothing )
1465
1458
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... )
1467
1460
elseif ! isempty (args) && typeof (args[1 ]) <: DEAlgorithm
1468
1461
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,
1475
1466
kwargs... )
1476
1467
end
1477
1468
@@ -1488,10 +1479,10 @@ function _solve_forward(prob, sensealg, u0, p, originator, args...; merge_callba
1488
1479
end
1489
1480
1490
1481
if isempty (args)
1491
- _concrete_solve_forward (prob, nothing , sensealg, u0, p; kwargs... )
1482
+ _concrete_solve_forward (_prob, alg , sensealg, u0, p, originator ; kwargs... )
1492
1483
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... )
1495
1486
end
1496
1487
end
1497
1488
0 commit comments