@@ -60,7 +60,7 @@ struct LinearProblem{uType, isinplace, F, bType, P, K} <:
60
60
p:: P
61
61
kwargs:: K
62
62
@add_kwonly function LinearProblem {iip} (A, b, p = NullParameters (); u0 = nothing ,
63
- kwargs... ) where {iip}
63
+ kwargs... ) where {iip}
64
64
warn_paramtype (p)
65
65
new {typeof(u0), iip, typeof(A), typeof(b), typeof(p), typeof(kwargs)} (A, b, u0, p,
66
66
kwargs)
@@ -82,7 +82,7 @@ TruncatedStacktraces.@truncate_stacktrace LinearProblem 1
82
82
"""
83
83
$(TYPEDEF)
84
84
"""
85
- struct StandardNonlinearProblem end
85
+ struct StandardNonlinearProblem <: AbstractProblemType end
86
86
87
87
@doc doc"""
88
88
@@ -134,20 +134,20 @@ every solve call.
134
134
* `p`: The parameters for the problem. Defaults to `NullParameters`.
135
135
* `kwargs`: The keyword arguments passed on to the solvers.
136
136
"""
137
- struct IntervalNonlinearProblem{isinplace, tType, P, F, K, PT} < :
137
+ struct IntervalNonlinearProblem{isinplace, tType, P, F, K, PT <: AbstractProblemType } < :
138
138
AbstractIntervalNonlinearProblem{nothing , isinplace}
139
139
f:: F
140
140
tspan:: tType
141
141
p:: P
142
142
problem_type:: PT
143
143
kwargs:: K
144
144
@add_kwonly function IntervalNonlinearProblem {iip} (f:: AbstractIntervalNonlinearFunction {
145
- iip,
146
- },
147
- tspan,
148
- p = NullParameters (),
149
- problem_type = StandardNonlinearProblem ();
150
- kwargs... ) where {iip}
145
+ iip,
146
+ },
147
+ tspan,
148
+ p = NullParameters (),
149
+ problem_type = StandardNonlinearProblem ();
150
+ kwargs... ) where {iip}
151
151
warn_paramtype (p)
152
152
new{iip, typeof (tspan), typeof (p), typeof (f),
153
153
typeof (kwargs), typeof (problem_type)}(f,
@@ -177,7 +177,7 @@ Define a nonlinear problem using an instance of
177
177
[`IntervalNonlinearFunction`](@ref IntervalNonlinearFunction).
178
178
"""
179
179
function IntervalNonlinearProblem (f:: AbstractIntervalNonlinearFunction , tspan,
180
- p = NullParameters (); kwargs... )
180
+ p = NullParameters (); kwargs... )
181
181
IntervalNonlinearProblem {isinplace(f)} (f, tspan, p; kwargs... )
182
182
end
183
183
@@ -233,17 +233,17 @@ page.
233
233
* `p`: The parameters for the problem. Defaults to `NullParameters`.
234
234
* `kwargs`: The keyword arguments passed on to the solvers.
235
235
"""
236
- struct NonlinearProblem{uType, isinplace, P, F, K, PT} < :
236
+ struct NonlinearProblem{uType, isinplace, P, F, K, PT <: AbstractProblemType } < :
237
237
AbstractNonlinearProblem{uType, isinplace}
238
238
f:: F
239
239
u0:: uType
240
240
p:: P
241
241
problem_type:: PT
242
242
kwargs:: K
243
243
@add_kwonly function NonlinearProblem {iip} (f:: AbstractNonlinearFunction{iip} , u0,
244
- p = NullParameters (),
245
- problem_type = StandardNonlinearProblem ();
246
- kwargs... ) where {iip}
244
+ p = NullParameters (),
245
+ problem_type = StandardNonlinearProblem ();
246
+ kwargs... ) where {iip}
247
247
warn_paramtype (p)
248
248
new{typeof (u0), iip, typeof (p), typeof (f),
249
249
typeof (kwargs), typeof (problem_type)}(f,
@@ -364,7 +364,7 @@ struct NonlinearLeastSquaresProblem{uType, isinplace, P, F, K} <:
364
364
kwargs:: K
365
365
366
366
@add_kwonly function NonlinearLeastSquaresProblem {iip} (f:: AbstractNonlinearFunction {
367
- iip}, u0, p = NullParameters (); kwargs... ) where {iip}
367
+ iip}, u0, p = NullParameters (); kwargs... ) where {iip}
368
368
warn_paramtype (p)
369
369
return new {typeof(u0), iip, typeof(p), typeof(f), typeof(kwargs)} (f, u0, p, kwargs)
370
370
end
@@ -383,7 +383,7 @@ Define a nonlinear least squares problem using an instance of
383
383
[`AbstractNonlinearFunction`](@ref AbstractNonlinearFunction).
384
384
"""
385
385
function NonlinearLeastSquaresProblem (f:: AbstractNonlinearFunction , u0,
386
- p = NullParameters (); kwargs... )
386
+ p = NullParameters (); kwargs... )
387
387
return NonlinearLeastSquaresProblem {isinplace(f)} (f, u0, p; kwargs... )
388
388
end
389
389
@@ -445,8 +445,8 @@ struct IntegralProblem{isinplace, P, F, T, K} <: AbstractIntegralProblem{isinpla
445
445
p:: P
446
446
kwargs:: K
447
447
@add_kwonly function IntegralProblem {iip} (f:: AbstractIntegralFunction{iip} , domain,
448
- p = NullParameters ();
449
- kwargs... ) where {iip}
448
+ p = NullParameters ();
449
+ kwargs... ) where {iip}
450
450
warn_paramtype (p)
451
451
new {iip, typeof(p), typeof(f), typeof(domain), typeof(kwargs)} (f,
452
452
domain, p, kwargs)
@@ -456,38 +456,40 @@ end
456
456
TruncatedStacktraces. @truncate_stacktrace IntegralProblem 1 4
457
457
458
458
function IntegralProblem (f:: AbstractIntegralFunction ,
459
- domain,
460
- p = NullParameters ();
461
- kwargs... )
459
+ domain,
460
+ p = NullParameters ();
461
+ kwargs... )
462
462
IntegralProblem {isinplace(f)} (f, domain, p; kwargs... )
463
463
end
464
464
465
465
function IntegralProblem (f:: AbstractIntegralFunction ,
466
- lb:: B ,
467
- ub:: B ,
468
- p = NullParameters ();
469
- kwargs... ) where {B}
466
+ lb:: B ,
467
+ ub:: B ,
468
+ p = NullParameters ();
469
+ kwargs... ) where {B}
470
470
IntegralProblem {isinplace(f)} (f, (lb, ub), p; kwargs... )
471
471
end
472
472
473
473
function IntegralProblem (f, args... ; nout = nothing , batch = nothing , kwargs... )
474
474
if nout != = nothing || batch != = nothing
475
- @warn " `nout` and `batch` keywords are deprecated in favor of inplace `IntegralFunction`s or `BatchIntegralFunction`s. See the updated Integrals.jl documentation for details."
475
+ @warn " `nout` and `batch` keywords are deprecated in favor of inplace `IntegralFunction`s or `BatchIntegralFunction`s. See the updated Integrals.jl documentation for details."
476
476
end
477
477
478
478
g = if isinplace (f, 3 )
479
479
if batch === nothing
480
- output_prototype = nout === nothing ? Array {Float64, 0} (undef) : Vector {Float64} (undef, nout)
480
+ output_prototype = nout === nothing ? Array {Float64, 0} (undef) :
481
+ Vector {Float64} (undef, nout)
481
482
IntegralFunction (f, output_prototype)
482
483
else
483
- output_prototype = nout === nothing ? Float64[] : Matrix {Float64} (undef, nout, 0 )
484
- BatchIntegralFunction (f, output_prototype, max_batch= batch)
484
+ output_prototype = nout === nothing ? Float64[] :
485
+ Matrix {Float64} (undef, nout, 0 )
486
+ BatchIntegralFunction (f, output_prototype, max_batch = batch)
485
487
end
486
488
else
487
489
if batch === nothing
488
490
IntegralFunction (f)
489
491
else
490
- BatchIntegralFunction (f, max_batch= batch)
492
+ BatchIntegralFunction (f, max_batch = batch)
491
493
end
492
494
end
493
495
IntegralProblem (g, args... ; kwargs... )
@@ -506,7 +508,7 @@ function Base.getproperty(prob::IntegralProblem, name::Symbol)
506
508
return Base. getfield (prob, name)
507
509
end
508
510
509
- struct QuadratureProblem end
511
+ struct QuadratureProblem <: AbstractProblemType end
510
512
@deprecate QuadratureProblem (args... ; kwargs... ) IntegralProblem (args... ; kwargs... )
511
513
512
514
@doc doc"""
@@ -548,8 +550,8 @@ struct SampledIntegralProblem{Y, X, K} <: AbstractIntegralProblem{false}
548
550
dim:: Int
549
551
kwargs:: K
550
552
@add_kwonly function SampledIntegralProblem (y:: AbstractArray , x:: AbstractVector ;
551
- dim = ndims (y),
552
- kwargs... )
553
+ dim = ndims (y),
554
+ kwargs... )
553
555
@assert dim<= ndims (y) " The integration dimension `dim` is larger than the number of dimensions of the integrand `y`"
554
556
@assert length (x)== size (y, dim) " The integrand `y` must have the same length as the sampling points `x` along the integrated dimension."
555
557
@assert axes (x, 1 )== axes (y, dim) " The integrand `y` must obey the same indexing as the sampling points `x` along the integrated dimension."
@@ -612,8 +614,8 @@ They should be an `AbstractArray` matching the geometry of `u`, where `(lcons[i]
612
614
are the lower and upper bounds for `cons[i]`.
613
615
614
616
The `f` in the `OptimizationProblem` should typically be an instance of [`OptimizationFunction`](@ref)
615
- to specify the objective function and its derivatives either by passing
616
- predefined functions for them or automatically generated using the [`ADType`](@ref).
617
+ to specify the objective function and its derivatives either by passing
618
+ predefined functions for them or automatically generated using the [`ADType`](@ref).
617
619
618
620
If `f` is a standard Julia function, it is automatically transformed into an
619
621
`OptimizationFunction` with `NoAD()`, meaning the derivative functions are not
@@ -663,10 +665,10 @@ struct OptimizationProblem{iip, F, uType, P, LB, UB, I, LC, UC, S, K} <:
663
665
sense:: S
664
666
kwargs:: K
665
667
@add_kwonly function OptimizationProblem {iip} (f:: OptimizationFunction{iip} , u0,
666
- p = NullParameters ();
667
- lb = nothing , ub = nothing , int = nothing ,
668
- lcons = nothing , ucons = nothing ,
669
- sense = nothing , kwargs... ) where {iip}
668
+ p = NullParameters ();
669
+ lb = nothing , ub = nothing , int = nothing ,
670
+ lcons = nothing , ucons = nothing ,
671
+ sense = nothing , kwargs... ) where {iip}
670
672
if xor (lb === nothing , ub === nothing )
671
673
error (" If any of `lb` or `ub` is provided, both must be provided." )
672
674
end
@@ -688,14 +690,18 @@ function OptimizationProblem(f, args...; kwargs...)
688
690
OptimizationProblem {true} (OptimizationFunction {true} (f), args... ; kwargs... )
689
691
end
690
692
691
- function OptimizationFunction (f:: NonlinearFunction , adtype:: AbstractADType = NoAD (); kwargs... )
693
+ function OptimizationFunction (f:: NonlinearFunction ,
694
+ adtype:: AbstractADType = NoAD ();
695
+ kwargs... )
692
696
if isinplace (f)
693
697
throw (ArgumentError (" Converting NonlinearFunction to OptimizationFunction is not supported with in-place functions yet." ))
694
698
end
695
699
OptimizationFunction ((u, p) -> sum (abs2, f (u, p)), adtype; kwargs... )
696
700
end
697
701
698
- function OptimizationProblem (prob:: NonlinearLeastSquaresProblem , adtype:: AbstractADType = NoAD (); kwargs... )
702
+ function OptimizationProblem (prob:: NonlinearLeastSquaresProblem ,
703
+ adtype:: AbstractADType = NoAD ();
704
+ kwargs... )
699
705
if isinplace (prob)
700
706
throw (ArgumentError (" Converting NonlinearLeastSquaresProblem to OptimizationProblem is not supported with in-place functions yet." ))
701
707
end
0 commit comments