@@ -41,19 +41,63 @@ df(t::Union{InplaceObjective, NotInplaceObjective}) = t.df
4141fdf (t:: Union{InplaceObjective, NotInplaceObjective} ) = t. fdf
4242
4343# Mutating version
44- make_f (t:: InplaceObjective , x, F:: Real ) = x -> fdf (t)(F, nothing , x)
45- make_f (t:: InplaceObjective , x, F) = (F, x) -> fdf (t)(F, nothing , x)
46- make_f (t:: InPlaceObjectiveFGH , x, F:: Real ) = x -> t. fgh (F, nothing , nothing , x)
47- make_f (t:: InPlaceObjectiveFGHv , x, F:: Real ) = x -> t. fghv (F, nothing , nothing , x, nothing )
48-
49-
50- make_df (t:: InplaceObjective , x, F) = (DF, x) -> fdf (t)(nothing , DF, x)
51- make_df (t:: InPlaceObjectiveFGH , x, F) = (DF, x) -> t. fgh (nothing , DF, nothing , x)
52- make_df (t:: InPlaceObjectiveFGHv , x, F) = (DF, x) -> t. fghv (nothing , DF, nothing , x, nothing )
44+ function make_f (t:: InplaceObjective , x, F:: Real )
45+ (; fdf, fgh, fghv) = t
46+ if fdf != = nothing
47+ return let fdf = fdf, F = F
48+ x -> fdf (F, nothing , x)
49+ end
50+ elseif fgh != = nothing
51+ return let fgh = fgh, F = F
52+ x -> fgh (F, nothing , nothing , x)
53+ end
54+ elseif fghv != = nothing
55+ return let fghv = fghv, F = F
56+ x -> fghv (F, nothing , nothing , x, nothing )
57+ end
58+ else
59+ throw (ArgumentError (" Cannot construct function for evaluating the objective function: No suitable function was provided." ))
60+ end
61+ end
62+ make_f (t:: InplaceObjective , x, F) = let fdf = t. fdf; (F, x) -> fdf (F, nothing , x); end
63+
64+ function make_df (t:: InplaceObjective , x, F)
65+ (; fdf, fgh, fghv) = t
66+ if fdf != = nothing
67+ return let fdf = fdf
68+ (DF, x) -> fdf (nothing , DF, x)
69+ end
70+ elseif fgh != = nothing
71+ return let fgh = fgh
72+ (DF, x) -> fgh (nothing , DF, nothing , x)
73+ end
74+ elseif fghv != = nothing
75+ return let fghv = fghv
76+ (DF, x) -> fghv (nothing , DF, nothing , x, nothing )
77+ end
78+ else
79+ throw (ArgumentError (" Cannot construct function for evaluating the gradient of the objective function: No suitable function was provided.." ))
80+ end
81+ end
5382
54- make_fdf (t:: InplaceObjective , x, F:: Real ) = (G, x) -> fdf (t)(F, G, x)
55- make_fdf (t:: InPlaceObjectiveFGH , x, F:: Real ) = (G, x) -> t. fgh (F, G, nothing , x)
56- make_fdf (t:: InPlaceObjectiveFGHv , x, F:: Real ) = (G, x) -> t. fghv (F, G, nothing , x, nothing )
83+ function make_fdf (t:: InplaceObjective , x, F:: Real )
84+ (; fdf, fgh, fghv) = t
85+ if fdf != = nothing
86+ return let fdf = fdf, F = F
87+ (G, x) -> fdf (F, G, x)
88+ end
89+ elseif fgh != = nothing
90+ return let fgh = fgh, F = F
91+ (G, x) -> fgh (F, G, nothing , x)
92+ end
93+ elseif fghv != = nothing
94+ return let fghv = fghv, F = F
95+ (G, x) -> fghv (F, G, nothing , x, nothing )
96+ end
97+ else
98+ throw (ArgumentError (" Cannot construct function that evaluates both the objective function and its gradient: No suitable function was provided." ))
99+ end
100+ end
57101make_fdf (t:: InplaceObjective , x, F) = fdf (t)
58102
59103# Non-mutating version
93137const InPlaceFGH = InplaceObjective{<: Nothing ,<: Nothing ,TH,<: Nothing ,<: Nothing } where {TH}
94138const InPlaceFG_HV = InplaceObjective{<: Nothing ,TFG,<: Nothing ,THv,<: Nothing } where {TFG,THv}
95139const InPlaceFGHV = InplaceObjective{<: Nothing ,<: Nothing ,<: Nothing ,<: Nothing ,TFGHv} where {TFGHv}
96- function TwiceDifferentiable (t:: InPlaceFGH , x:: AbstractArray , F:: Real = real (zero (eltype (x))), G:: AbstractArray = alloc_DF (x, F), H = alloc_H (x, F))
140+ function TwiceDifferentiable (t:: InPlaceFGH , x:: AbstractArray , F:: Real = real (zero (eltype (x))), G:: AbstractArray = alloc_DF (x, F), H:: AbstractMatrix = alloc_H (x, F))
97141 f = x -> t. fgh (F, nothing , nothing , x)
98142 df = (G, x) -> t. fgh (nothing , G, nothing , x)
99143 fdf = (G, x) -> t. fgh (F, G, nothing , x)
0 commit comments