Skip to content

Commit f40159f

Browse files
authored
Move traits to ProximalCore.jl & implement is_locally_smooth where suitable (#152)
* move traits to ProximalCore.jl & implement is_locally_smooth where suitable Besides removing traits.jl that contained the functions moved to ProximalCore.jl and applying renaming that occured in ProximalCore.jl v0.2.0, the commit contains the following changes: Added traits: - `is_proximable = true` added to `SqrNormL2` - `is_positively_homogeneous = true` added to `SumPositive` - `is_locally_smooth = true` added to `LogBarrier` - `is_locally_smooth = true` added to `NormL2` `is_locally_smooth(T{W}) = is_locally_smooth(W)` added where W is the wrapped function: - `Postcompose` - `Precompose` - `PrecomposeDiagonal` - `Regularized` - `SeparableSum` - `SlicedSeparableSum` - `Sum` - `Tilt` - `Translate` * fix "UndefVarError: `ProximalCore` not defined in Main" when rendering documentation * add running doctests to test suite
1 parent 86dcef2 commit f40159f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+197
-194
lines changed

Project.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name = "ProximalOperators"
22
uuid = "a725b495-10eb-56fe-b38b-717eba820537"
33
version = "0.16.1"
44

5+
[workspace]
6+
projects = ["docs", "test", "benchmark"]
7+
58
[deps]
69
IterativeSolvers = "42fd0dbc-a981-5370-80f2-aaf504508153"
710
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -15,7 +18,7 @@ TSVD = "9449cd9e-2762-5aa3-a617-5413e99d722e"
1518
IterativeSolvers = "0.8 - 0.9"
1619
LinearAlgebra = "1.4"
1720
OSQP = "0.3 - 0.8"
18-
ProximalCore = "0.1"
21+
ProximalCore = "0.2.0"
1922
SparseArrays = "1.4"
2023
SuiteSparse = "1.4"
2124
TSVD = "0.3 - 0.4"

docs/make.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Documenter, ProximalOperators, ProximalCore
22

3+
DocMeta.setdocmeta!(ProximalCore, :DocTestSetup, :(import ProximalCore); recursive=true)
4+
35
makedocs(
46
modules = [ProximalOperators, ProximalCore],
57
sitename = "ProximalOperators.jl",

src/ProximalOperators.jl

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,27 @@ module ProximalOperators
44

55
using LinearAlgebra
66
import ProximalCore: prox, prox!, gradient, gradient!
7-
import ProximalCore: is_convex, is_generalized_quadratic
7+
import ProximalCore:
8+
is_convex,
9+
is_strongly_convex,
10+
is_generalized_quadratic,
11+
is_proximable,
12+
is_separable,
13+
is_singleton_indicator,
14+
is_cone_indicator,
15+
is_affine_indicator,
16+
is_set_indicator,
17+
is_smooth,
18+
is_locally_smooth,
19+
is_support
820

9-
const RealOrComplex{R <: Real} = Union{R, Complex{R}}
10-
const HermOrSym{T, S} = Union{Hermitian{T, S}, Symmetric{T, S}}
11-
const RealBasedArray{R} = AbstractArray{C, N} where {C <: RealOrComplex{R}, N}
12-
const TupleOfArrays{R} = Tuple{RealBasedArray{R}, Vararg{RealBasedArray{R}}}
13-
const ArrayOrTuple{R} = Union{RealBasedArray{R}, TupleOfArrays{R}}
14-
const TransposeOrAdjoint{M} = Union{Transpose{C,M} where C, Adjoint{C,M} where C}
15-
const Maybe{T} = Union{T, Nothing}
21+
const RealOrComplex{R<:Real} = Union{R,Complex{R}}
22+
const HermOrSym{T,S} = Union{Hermitian{T,S},Symmetric{T,S}}
23+
const RealBasedArray{R} = AbstractArray{C,N} where {C<:RealOrComplex{R},N}
24+
const TupleOfArrays{R} = Tuple{RealBasedArray{R},Vararg{RealBasedArray{R}}}
25+
const ArrayOrTuple{R} = Union{RealBasedArray{R},TupleOfArrays{R}}
26+
const TransposeOrAdjoint{M} = Union{Transpose{C,M} where C,Adjoint{C,M} where C}
27+
const Maybe{T} = Union{T,Nothing}
1628

1729
export prox, prox!, gradient, gradient!
1830

@@ -23,7 +35,6 @@ include("utilities/linops.jl")
2335
include("utilities/symmetricpacked.jl")
2436
include("utilities/uniformarrays.jl")
2537
include("utilities/normdiff.jl")
26-
include("utilities/traits.jl")
2738

2839
# Basic functions
2940

src/calculus/conjugate.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ struct Conjugate{T}
2020
end
2121
end
2222

23-
is_prox_accurate(::Type{Conjugate{T}}) where T = is_prox_accurate(T)
23+
is_proximable(::Type{Conjugate{T}}) where T = is_proximable(T)
2424
is_convex(::Type{Conjugate{T}}) where T = true
25-
is_cone(::Type{Conjugate{T}}) where T = is_cone(T) && is_convex(T)
25+
is_cone_indicator(::Type{Conjugate{T}}) where T = is_cone_indicator(T) && is_convex(T)
2626
is_smooth(::Type{Conjugate{T}}) where T = is_strongly_convex(T)
2727
is_strongly_convex(::Type{Conjugate{T}}) where T = is_smooth(T)
2828
is_generalized_quadratic(::Type{Conjugate{T}}) where T = is_generalized_quadratic(T)
29-
is_set(::Type{Conjugate{T}}) where T = is_convex(T) && is_support(T)
30-
is_positively_homogeneous(::Type{Conjugate{T}}) where T = is_convex(T) && is_set(T)
29+
is_set_indicator(::Type{Conjugate{T}}) where T = is_convex(T) && is_support(T)
30+
is_positively_homogeneous(::Type{Conjugate{T}}) where T = is_convex(T) && is_set_indicator(T)
3131

3232
Conjugate(f::T) where T = Conjugate{T}(f)
3333

@@ -37,7 +37,7 @@ Conjugate(f::T) where T = Conjugate{T}(f)
3737
function prox!(y, g::Conjugate, x, gamma)
3838
# Moreau identity
3939
v = prox!(y, g.f, x/gamma, 1/gamma)
40-
if is_set(g)
40+
if is_set_indicator(g)
4141
v = real(eltype(x))(0)
4242
else
4343
v = real(dot(x, y)) - gamma * real(dot(y, y)) - v
@@ -50,7 +50,7 @@ end
5050

5151
function prox_naive(g::Conjugate, x, gamma)
5252
y, v = prox_naive(g.f, x/gamma, 1/gamma)
53-
return x - gamma * y, if is_set(g) real(eltype(x))(0) else real(dot(x, y)) - gamma * real(dot(y, y)) - v end
53+
return x - gamma * y, if is_set_indicator(g) real(eltype(x))(0) else real(dot(x, y)) - gamma * real(dot(y, y)) - v end
5454
end
5555

5656
# TODO: hard-code conjugation rules? E.g. precompose/epicompose

src/calculus/distL2.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct DistL2{R, T}
1414
ind::T
1515
lambda::R
1616
function DistL2{R, T}(ind::T, lambda::R) where {R, T}
17-
if !is_set(ind)
17+
if !is_set_indicator(ind)
1818
error("`ind` must be a convex set")
1919
end
2020
if lambda <= 0
@@ -25,7 +25,7 @@ struct DistL2{R, T}
2525
end
2626
end
2727

28-
is_prox_accurate(::Type{DistL2{R, T}}) where {R, T} = is_prox_accurate(T)
28+
is_proximable(::Type{DistL2{R, T}}) where {R, T} = is_proximable(T)
2929
is_convex(::Type{DistL2{R, T}}) where {R, T} = is_convex(T)
3030

3131
DistL2(ind::T, lambda::R=1) where {R, T} = DistL2{R, T}(ind, lambda)

src/calculus/pointwiseMinimum.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ PointwiseMinimum(fs...) = PointwiseMinimum{typeof(fs)}(fs)
1717

1818
component_types(::Type{PointwiseMinimum{T}}) where T = fieldtypes(T)
1919

20-
@generated is_set(::Type{T}) where T <: PointwiseMinimum = return all(is_set, component_types(T)) ? :(true) : :(false)
21-
@generated is_cone(::Type{T}) where T <: PointwiseMinimum = return all(is_cone, component_types(T)) ? :(true) : :(false)
20+
@generated is_set_indicator(::Type{T}) where T <: PointwiseMinimum = return all(is_set_indicator, component_types(T)) ? :(true) : :(false)
21+
@generated is_cone_indicator(::Type{T}) where T <: PointwiseMinimum = return all(is_cone_indicator, component_types(T)) ? :(true) : :(false)
2222

2323
function (g::PointwiseMinimum{T})(x) where T
2424
return minimum(f(x) for f in g.fs)

src/calculus/postcompose.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ struct Postcompose{T, R, S}
2323
end
2424
end
2525

26-
is_prox_accurate(::Type{<:Postcompose{T}}) where T = is_prox_accurate(T)
26+
is_proximable(::Type{<:Postcompose{T}}) where T = is_proximable(T)
2727
is_separable(::Type{<:Postcompose{T}}) where T = is_separable(T)
2828
is_convex(::Type{<:Postcompose{T}}) where T = is_convex(T)
29-
is_set(::Type{<:Postcompose{T}}) where T = is_set(T)
30-
is_singleton(::Type{<:Postcompose{T}}) where T = is_singleton(T)
31-
is_cone(::Type{<:Postcompose{T}}) where T = is_cone(T)
32-
is_affine(::Type{<:Postcompose{T}}) where T = is_affine(T)
29+
is_set_indicator(::Type{<:Postcompose{T}}) where T = is_set_indicator(T)
30+
is_singleton_indicator(::Type{<:Postcompose{T}}) where T = is_singleton_indicator(T)
31+
is_cone_indicator(::Type{<:Postcompose{T}}) where T = is_cone_indicator(T)
32+
is_affine_indicator(::Type{<:Postcompose{T}}) where T = is_affine_indicator(T)
3333
is_smooth(::Type{<:Postcompose{T}}) where T = is_smooth(T)
34+
is_locally_smooth(::Type{<:Postcompose{T}}) where T = is_locally_smooth(T)
3435
is_generalized_quadratic(::Type{<:Postcompose{T}}) where T = is_generalized_quadratic(T)
3536
is_strongly_convex(::Type{<:Postcompose{T}}) where T = is_strongly_convex(T)
3637

src/calculus/precompose.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ struct Precompose{T, M, U, V}
3737
end
3838
end
3939

40-
is_prox_accurate(::Type{<:Precompose{T}}) where T = is_prox_accurate(T)
40+
is_proximable(::Type{<:Precompose{T}}) where T = is_proximable(T)
4141
is_convex(::Type{<:Precompose{T}}) where T = is_convex(T)
42-
is_set(::Type{<:Precompose{T}}) where T = is_set(T)
43-
is_singleton(::Type{<:Precompose{T}}) where T = is_singleton(T)
44-
is_cone(::Type{<:Precompose{T}}) where T = is_cone(T)
45-
is_affine(::Type{<:Precompose{T}}) where T = is_affine(T)
42+
is_set_indicator(::Type{<:Precompose{T}}) where T = is_set_indicator(T)
43+
is_singleton_indicator(::Type{<:Precompose{T}}) where T = is_singleton_indicator(T)
44+
is_cone_indicator(::Type{<:Precompose{T}}) where T = is_cone_indicator(T)
45+
is_affine_indicator(::Type{<:Precompose{T}}) where T = is_affine_indicator(T)
4646
is_smooth(::Type{<:Precompose{T}}) where T = is_smooth(T)
47+
is_locally_smooth(::Type{<:Precompose{T}}) where T = is_locally_smooth(T)
4748
is_generalized_quadratic(::Type{<:Precompose{T}}) where T = is_generalized_quadratic(T)
4849
is_strongly_convex(::Type{<:Precompose{T}}) where T = is_strongly_convex(T)
4950

src/calculus/precomposeDiagonal.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ struct PrecomposeDiagonal{T, R, S}
3232
end
3333

3434
is_separable(::Type{<:PrecomposeDiagonal{T}}) where T = is_separable(T)
35-
is_prox_accurate(::Type{<:PrecomposeDiagonal{T}}) where T = is_prox_accurate(T)
35+
is_proximable(::Type{<:PrecomposeDiagonal{T}}) where T = is_proximable(T)
3636
is_convex(::Type{<:PrecomposeDiagonal{T}}) where T = is_convex(T)
37-
is_set(::Type{<:PrecomposeDiagonal{T}}) where T = is_set(T)
38-
is_singleton(::Type{<:PrecomposeDiagonal{T}}) where T = is_singleton(T)
39-
is_cone(::Type{<:PrecomposeDiagonal{T}}) where T = is_cone(T)
40-
is_affine(::Type{<:PrecomposeDiagonal{T}}) where T = is_affine(T)
37+
is_set_indicator(::Type{<:PrecomposeDiagonal{T}}) where T = is_set_indicator(T)
38+
is_singleton_indicator(::Type{<:PrecomposeDiagonal{T}}) where T = is_singleton_indicator(T)
39+
is_cone_indicator(::Type{<:PrecomposeDiagonal{T}}) where T = is_cone_indicator(T)
40+
is_affine_indicator(::Type{<:PrecomposeDiagonal{T}}) where T = is_affine_indicator(T)
4141
is_smooth(::Type{<:PrecomposeDiagonal{T}}) where T = is_smooth(T)
42+
is_locally_smooth(::Type{<:PrecomposeDiagonal{T}}) where T = is_locally_smooth(T)
4243
is_generalized_quadratic(::Type{<:PrecomposeDiagonal{T}}) where T = is_generalized_quadratic(T)
4344
is_strongly_convex(::Type{<:PrecomposeDiagonal{T}}) where T = is_strongly_convex(T)
4445

src/calculus/regularize.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ struct Regularize{T, S, A}
2525
end
2626

2727
is_separable(::Type{<:Regularize{T}}) where T = is_separable(T)
28-
is_prox_accurate(::Type{<:Regularize{T}}) where T = is_prox_accurate(T)
28+
is_proximable(::Type{<:Regularize{T}}) where T = is_proximable(T)
2929
is_convex(::Type{<:Regularize{T}}) where T = is_convex(T)
3030
is_smooth(::Type{<:Regularize{T}}) where T = is_smooth(T)
31+
is_locally_smooth(::Type{<:Regularize{T}}) where T = is_locally_smooth(T)
3132
is_generalized_quadratic(::Type{<:Regularize{T}}) where T = is_generalized_quadratic(T)
3233
is_strongly_convex(::Type{<:Regularize}) = true
3334

0 commit comments

Comments
 (0)