diff --git a/Project.toml b/Project.toml index 6c7f1d1..a6c625f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ProximalCore" uuid = "dc4f5ac2-75d1-4f31-931e-60435d74994b" authors = ["Lorenzo Stella "] -version = "0.1.2" +version = "0.2.0" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/ProximalCore.jl b/src/ProximalCore.jl index 0bc6855..728e3d3 100644 --- a/src/ProximalCore.jl +++ b/src/ProximalCore.jl @@ -8,36 +8,6 @@ is_convex(::T) where T = is_convex(T) is_generalized_quadratic(::Type) = false is_generalized_quadratic(::T) where T = is_generalized_quadratic(T) -""" - gradient!(y, f, x) - -In-place gradient (and value) of `f` at `x`. - -The gradient is written to the (pre-allocated) array `y`, which should have the same shape/size as `x`. - -Returns the value `f` at `x`. - -See also: [`gradient`](@ref). -""" -gradient! - -""" - gradient(f, x) - -Gradient (and value) of `f` at `x`. - -Return a tuple `(y, fx)` consisting of -- `y`: the gradient of `f` at `x` -- `fx`: the value of `f` at `x` - -See also: [`gradient!`](@ref). -""" -function gradient(f, x) - y = similar(x) - fx = gradient!(y, f, x) - return y, fx -end - """ prox!(y, f, x, gamma=1) @@ -83,11 +53,6 @@ struct Zero end (::Zero)(x) = real(eltype(x))(0) -function gradient!(y, f::Zero, x) - y .= eltype(x)(0) - return f(x) -end - function prox!(y, ::Zero, x, gamma) y .= x return real(eltype(y))(0) diff --git a/test/runtests.jl b/test/runtests.jl index dab2832..ff08292 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,8 +2,8 @@ using Test using Aqua using LinearAlgebra using ProximalCore -using ProximalCore: prox, gradient, convex_conjugate -using ProximalCore: Zero, IndZero +using ProximalCore: prox +using ProximalCore: Zero, IndZero, convex_conjugate import ProximalCore: prox!, is_convex, is_generalized_quadratic @testset "Aqua" begin @@ -36,10 +36,10 @@ end @test is_generalized_quadratic(Zero()) for T in [Float32, Float64] - @test let x = T[1.0, 2.0, 3.0] - prox(Zero(), x, T(42)) == (x, T(0)) - gradient(Zero(), x) == (T[0, 0, 0], T(0)) - end + x = T[1.0, 2.0, 3.0] + @test Zero()(x) == T(0) + @test prox(Zero(), x, T(42)) == (x, T(0)) + @test prox(Zero(), x, ) == (x, T(0)) end end @@ -57,9 +57,20 @@ end @test IndZero()(x) == T(Inf) @test IndZero()(T[0, 0, 0]) == T(0) @test prox(IndZero(), x, T(42)) == (T[0, 0, 0], T(0)) + @test prox(IndZero(), x) == (T[0, 0, 0], T(0)) end end + + @testset "Others" begin + + @inferred (f -> Val(is_convex(f)))(42) + @inferred (f -> Val(is_generalized_quadratic(f)))(42) + + @test !is_convex(42) + @test !is_generalized_quadratic(42) + + end @testset "Conjugation" begin