Skip to content

Commit

Permalink
Add missing downgrade constructor to NonDifferentiable from higher di… (
Browse files Browse the repository at this point in the history
#133)

* Add missing downgrade constructor to NonDifferentiable from higher diffs.

* Update nondifferentiable.jl

* Update nondifferentiable.jl

* Update NLSolversBase.jl

* Fixitup.
  • Loading branch information
pkofod authored Oct 2, 2020
1 parent fa47b94 commit 0c30a5e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/NLSolversBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ include("objective_types/incomplete.jl")
include("objective_types/constraints.jl")
include("interface.jl")

NonDifferentiable(f::OnceDifferentiable, x::AbstractArray) = NonDifferentiable(f.f, x, copy(f.F))
NonDifferentiable(f::TwiceDifferentiable, x::AbstractArray) = NonDifferentiable(f.f, x, copy(f.F))
NonDifferentiable(f::TwiceDifferentiableHV, x::AbstractArray) = NonDifferentiable(f.f, x, copy(f.F))
end # module
3 changes: 3 additions & 0 deletions test/incomplete.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
v = randn(10)
od_fg_and_hv = TwiceDifferentiableHV(only_fg_and_hv!(just_fg!, just_hv!), x)
od_fghv = TwiceDifferentiableHV(only_fghv!(just_fghv!), x)
ndtdhv = NonDifferentiable(od_fghv, v)
@test value(ndtdhv, v) === value(od_fghv, v)

for OD in (od_fg_and_hv, od_fghv)
gradient!(OD, x)
@test gradient(OD) == g(x)
Expand Down
5 changes: 5 additions & 0 deletions test/objective_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
od = OnceDifferentiable(exponential, exponential_gradient!, x_seed, 0.0, g_seed)
xrand = rand(2)
value_gradient!(od, xrand)
ndod = NonDifferentiable(od, xrand)
@test value(ndod, xrand) === value(od, xrand)
fcache = value(od)
gcache = copy(gradient(od))
value_gradient!(od, zeros(2))
Expand All @@ -58,6 +60,9 @@
td = TwiceDifferentiable(exponential, exponential_gradient!, exponential_hessian!, x_seed, 0.0, g_seed)
xrand = rand(2)
value_gradient!(td, xrand)
ndtd = NonDifferentiable(td, xrand)
@test value(ndtd, xrand) === value(td, xrand)

fcache = value(td)
gcache = copy(gradient(td))
value_gradient!(td, zeros(2))
Expand Down

0 comments on commit 0c30a5e

Please sign in to comment.