diff --git a/src/NLSolversBase.jl b/src/NLSolversBase.jl index d4eb3a9..47d07b0 100644 --- a/src/NLSolversBase.jl +++ b/src/NLSolversBase.jl @@ -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 diff --git a/test/incomplete.jl b/test/incomplete.jl index d52b8f2..99cf8ff 100644 --- a/test/incomplete.jl +++ b/test/incomplete.jl @@ -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) diff --git a/test/objective_types.jl b/test/objective_types.jl index b61acc4..8e7f679 100644 --- a/test/objective_types.jl +++ b/test/objective_types.jl @@ -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)) @@ -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))