From 3da5fecc3655d4c4b537c6d737d8fb9908220e3e Mon Sep 17 00:00:00 2001 From: Lorenzo Stella Date: Fri, 29 Dec 2023 20:02:38 +0100 Subject: [PATCH] Fix IndZero (#4) --- Project.toml | 3 ++- src/ProximalCore.jl | 4 ++-- test/runtests.jl | 7 ++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index 3b8ebd1..6c7f1d1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,10 +1,11 @@ name = "ProximalCore" uuid = "dc4f5ac2-75d1-4f31-931e-60435d74994b" authors = ["Lorenzo Stella "] -version = "0.1.1" +version = "0.1.2" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" [compat] +LinearAlgebra = "1.2" julia = "1.2" diff --git a/src/ProximalCore.jl b/src/ProximalCore.jl index bc8277a..0bc6855 100644 --- a/src/ProximalCore.jl +++ b/src/ProximalCore.jl @@ -101,9 +101,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 diff --git a/test/runtests.jl b/test/runtests.jl index 7cad8a8..dab2832 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -53,9 +53,10 @@ 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)) end end