Skip to content

Commit 0c30a5e

Browse files
authored
Add missing downgrade constructor to NonDifferentiable from higher di… (#133)
* Add missing downgrade constructor to NonDifferentiable from higher diffs. * Update nondifferentiable.jl * Update nondifferentiable.jl * Update NLSolversBase.jl * Fixitup.
1 parent fa47b94 commit 0c30a5e

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/NLSolversBase.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,7 @@ include("objective_types/incomplete.jl")
6969
include("objective_types/constraints.jl")
7070
include("interface.jl")
7171

72+
NonDifferentiable(f::OnceDifferentiable, x::AbstractArray) = NonDifferentiable(f.f, x, copy(f.F))
73+
NonDifferentiable(f::TwiceDifferentiable, x::AbstractArray) = NonDifferentiable(f.f, x, copy(f.F))
74+
NonDifferentiable(f::TwiceDifferentiableHV, x::AbstractArray) = NonDifferentiable(f.f, x, copy(f.F))
7275
end # module

test/incomplete.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@
9595
v = randn(10)
9696
od_fg_and_hv = TwiceDifferentiableHV(only_fg_and_hv!(just_fg!, just_hv!), x)
9797
od_fghv = TwiceDifferentiableHV(only_fghv!(just_fghv!), x)
98+
ndtdhv = NonDifferentiable(od_fghv, v)
99+
@test value(ndtdhv, v) === value(od_fghv, v)
100+
98101
for OD in (od_fg_and_hv, od_fghv)
99102
gradient!(OD, x)
100103
@test gradient(OD) == g(x)

test/objective_types.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
od = OnceDifferentiable(exponential, exponential_gradient!, x_seed, 0.0, g_seed)
3737
xrand = rand(2)
3838
value_gradient!(od, xrand)
39+
ndod = NonDifferentiable(od, xrand)
40+
@test value(ndod, xrand) === value(od, xrand)
3941
fcache = value(od)
4042
gcache = copy(gradient(od))
4143
value_gradient!(od, zeros(2))
@@ -58,6 +60,9 @@
5860
td = TwiceDifferentiable(exponential, exponential_gradient!, exponential_hessian!, x_seed, 0.0, g_seed)
5961
xrand = rand(2)
6062
value_gradient!(td, xrand)
63+
ndtd = NonDifferentiable(td, xrand)
64+
@test value(ndtd, xrand) === value(td, xrand)
65+
6166
fcache = value(td)
6267
gcache = copy(gradient(td))
6368
value_gradient!(td, zeros(2))

0 commit comments

Comments
 (0)