From aab54b80c0068d71f3688e0a4ad8c1b9be89dd96 Mon Sep 17 00:00:00 2001 From: Lorenzo Stella Date: Sat, 28 Oct 2023 12:09:47 +0200 Subject: [PATCH 01/11] Remove gradient API --- src/ProximalCore.jl | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/src/ProximalCore.jl b/src/ProximalCore.jl index bc8277a..fd2e46b 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) From 18c4b09835817fce61b4600ca68936716526a5ce Mon Sep 17 00:00:00 2001 From: Lorenzo Stella Date: Sat, 28 Oct 2023 12:10:45 +0200 Subject: [PATCH 02/11] Bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 3b8ebd1..e2f6b9d 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.1" +version = "0.2.0" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" From 4f0aaa172990a4b43865646a00107fa57a3d2b41 Mon Sep 17 00:00:00 2001 From: Lorenzo Stella Date: Fri, 29 Dec 2023 17:47:01 +0100 Subject: [PATCH 03/11] Update version number --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index e2f6b9d..d662abc 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ProximalCore" uuid = "dc4f5ac2-75d1-4f31-931e-60435d74994b" authors = ["Lorenzo Stella "] -version = "0.2.0" +version = "1.0.0" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" From 8b883fa39ad6a73fcc3d7c7bda75470b396c9ec5 Mon Sep 17 00:00:00 2001 From: Lorenzo Stella Date: Fri, 29 Dec 2023 17:47:37 +0100 Subject: [PATCH 04/11] Revert --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index d662abc..e2f6b9d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ProximalCore" uuid = "dc4f5ac2-75d1-4f31-931e-60435d74994b" authors = ["Lorenzo Stella "] -version = "1.0.0" +version = "0.2.0" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" From 7265492668d465ebe512990a41082d65f2d1359f Mon Sep 17 00:00:00 2001 From: Lorenzo Stella Date: Fri, 29 Dec 2023 17:48:50 +0100 Subject: [PATCH 05/11] Update compat --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index e2f6b9d..a6c625f 100644 --- a/Project.toml +++ b/Project.toml @@ -7,4 +7,5 @@ version = "0.2.0" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" [compat] +LinearAlgebra = "1.2" julia = "1.2" From 2a8cc1c92afe7bc326342cec8e4a94f0b0c67ab3 Mon Sep 17 00:00:00 2001 From: Lorenzo Stella Date: Fri, 29 Dec 2023 17:52:22 +0100 Subject: [PATCH 06/11] Update tests --- test/runtests.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 7cad8a8..c774b7e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,9 +2,9 @@ using Test using Aqua using LinearAlgebra using ProximalCore -using ProximalCore: prox, gradient, convex_conjugate -using ProximalCore: Zero, IndZero -import ProximalCore: prox!, is_convex, is_generalized_quadratic +using ProximalCore: prox, prox! +using ProximalCore: Zero, IndZero, convex_conjugate +import ProximalCore: is_convex, is_generalized_quadratic @testset "Aqua" begin Aqua.test_all(ProximalCore) @@ -38,7 +38,6 @@ end 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 end From 76e42ba9015a3bde6a36885f6dd66d023786914c Mon Sep 17 00:00:00 2001 From: Lorenzo Stella Date: Fri, 29 Dec 2023 17:55:36 +0100 Subject: [PATCH 07/11] Update tests --- test/runtests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index c774b7e..6ea3dae 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,9 +2,9 @@ using Test using Aqua using LinearAlgebra using ProximalCore -using ProximalCore: prox, prox! +using ProximalCore: prox using ProximalCore: Zero, IndZero, convex_conjugate -import ProximalCore: is_convex, is_generalized_quadratic +import ProximalCore: prox!, is_convex, is_generalized_quadratic @testset "Aqua" begin Aqua.test_all(ProximalCore) From 4c4866b2cc9ef1c4c58386b46279b441a426e711 Mon Sep 17 00:00:00 2001 From: Lorenzo Stella Date: Fri, 29 Dec 2023 18:39:40 +0100 Subject: [PATCH 08/11] Update tests --- test/runtests.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 6ea3dae..25f369b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -58,6 +58,16 @@ end 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 From 18d139db585cc339ea1ee697f7a56cc32e86b02d Mon Sep 17 00:00:00 2001 From: Lorenzo Stella Date: Fri, 29 Dec 2023 18:41:47 +0100 Subject: [PATCH 09/11] Remove gradient --- src/ProximalCore.jl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/ProximalCore.jl b/src/ProximalCore.jl index fd2e46b..4c1cb9c 100644 --- a/src/ProximalCore.jl +++ b/src/ProximalCore.jl @@ -53,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) From c34346908b6967626ece0160763454aebcebfc82 Mon Sep 17 00:00:00 2001 From: Lorenzo Stella Date: Fri, 29 Dec 2023 19:33:16 +0100 Subject: [PATCH 10/11] Update tests --- test/runtests.jl | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 25f369b..ff08292 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -36,9 +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)) - 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 @@ -52,9 +53,11 @@ end @test is_generalized_quadratic(IndZero()) for T in [Float32, Float64] - @test let x = T[1.0, 2.0, 3.0] - prox(IndZero(), x, T(42)) == (T[0, 0, 0], T(0)) - end + x = T[1.0, 2.0, 3.0] + @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 From 7a5b622d588a969b96f657715b4f7eadf39c49c1 Mon Sep 17 00:00:00 2001 From: Lorenzo Stella Date: Fri, 29 Dec 2023 19:46:39 +0100 Subject: [PATCH 11/11] Fix bug --- src/ProximalCore.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ProximalCore.jl b/src/ProximalCore.jl index 4c1cb9c..728e3d3 100644 --- a/src/ProximalCore.jl +++ b/src/ProximalCore.jl @@ -66,9 +66,9 @@ struct IndZero end function (::IndZero)(x) R = real(eltype(x)) if iszero(x) - return R(Inf) + return R(0) end - return R(0) + return R(Inf) end is_convex(::Type{IndZero}) = true