-
-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathbasic_solutions.jl
105 lines (90 loc) · 3.46 KB
/
basic_solutions.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""
$(TYPEDEF)
Representation of the solution to an linear system Ax=b defined by a LinearProblem
## Fields
- `u`: the representation of the optimization's solution.
- `resid`: the residual of the solver, if the method is an iterative method.
- `alg`: the algorithm type used by the solver.
- `iters`: the number of iterations used to solve the equation, if the method is an iterative
method.
- `retcode`: the return code from the solver. Used to determine whether the solver solved
successfully or whether it exited due to an error. For more details, see
[the return code documentation](https://docs.sciml.ai/SciMLBase/stable/interfaces/Solutions/#retcodes).
- `cache`: the `LinearCache` object containing the solver's internal cached variables. This
is given to allow continuation of solver usage, for example, solving `Ax=b` with the same
`A` and a new `b` without refactorizing `A`. See the caching interface tutorial for details
on how to use the `cache` effectively: http://docs.sciml.ai/LinearSolve/stable/tutorials/caching_interface/
- `stats`: statistics of the solver, such as the number of function evaluations required.
"""
struct LinearSolution{T, N, uType, R, A, C, S} <: AbstractLinearSolution{T, N}
u::uType
resid::R
alg::A
retcode::ReturnCode.T
iters::Int
cache::C
stats::S
end
function build_linear_solution(alg, u, resid, cache;
retcode = ReturnCode.Default,
iters = 0, stats = nothing)
T = eltype(eltype(u))
N = length((size(u)...,))
LinearSolution{T, N, typeof(u), typeof(resid), typeof(alg), typeof(cache),
typeof(stats)}(u,
resid,
alg,
retcode,
iters,
cache,
stats)
end
TruncatedStacktraces.@truncate_stacktrace LinearSolution 1 2
"""
$(TYPEDEF)
Representation of the solution to an quadrature integral_lb^ub f(x) dx defined by a IntegralProblem
## Fields
- `u`: the representation of the optimization's solution.
- `resid`: the residual of the solver.
- `alg`: the algorithm type used by the solver.
- `retcode`: the return code from the solver. Used to determine whether the solver solved
successfully or whether it exited due to an error. For more details, see
[the return code documentation](https://docs.sciml.ai/SciMLBase/stable/interfaces/Solutions/#retcodes).
- `chi`: the variance estimate of the estimator from Monte Carlo quadrature methods.
- `stats`: statistics of the solver, such as the number of function evaluations required.
"""
struct IntegralSolution{T, N, uType, R, P, A, C, S} <: AbstractIntegralSolution{T, N}
u::uType
resid::R
prob::P
alg::A
retcode::ReturnCode.T
chi::C
stats::S
end
TruncatedStacktraces.@truncate_stacktrace IntegralSolution 1 2
struct QuadratureSolution end
@deprecate QuadratureSolution(args...; kwargs...) IntegralSolution(args...; kwargs...)
function build_solution(prob::AbstractIntegralProblem,
alg, u, resid; chi = nothing,
retcode = ReturnCode.Default, stats = nothing, kwargs...)
T = eltype(eltype(u))
N = length((size(u)...,))
IntegralSolution{T, N, typeof(u), typeof(resid), typeof(prob), typeof(alg), typeof(chi),
typeof(stats)}(u,
resid,
prob,
alg,
retcode,
chi,
stats)
end
function wrap_sol(sol)
if hasproperty(sol, :prob) && hasproperty(sol.prob, :problem_type)
wrap_sol(sol, sol.prob.problem_type)
else
sol
end
end
# Define a default `wrap_sol` that does nothing
wrap_sol(sol, _) = sol