-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathruntests.jl
More file actions
176 lines (147 loc) · 4.6 KB
/
runtests.jl
File metadata and controls
176 lines (147 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using Test
using ProximalOperators
using ProximalOperators: ArrayOrTuple
using ProximalCore:
is_proximable,
is_separable,
is_convex,
is_singleton_indicator,
is_cone_indicator,
is_affine_indicator,
is_set_indicator,
is_smooth,
is_quadratic,
is_generalized_quadratic,
is_strongly_convex,
is_positively_homogeneous,
is_support
using Aqua
using Documenter
function call_test(f, x::ArrayOrTuple{R}) where R <: Real
try
fx = @inferred f(x)
@test typeof(fx) == R
return fx
catch e
if !isa(e, MethodError)
return nothing
end
end
end
Base.zero(xs::Tuple) = Base.zero.(xs)
# tests equality of the results of prox, prox! and prox_naive
function prox_test(f, x::ArrayOrTuple{R}, gamma=1) where R <: Real
y, fy = @inferred prox(f, x, gamma)
@test typeof(fy) == R
y_prealloc = zero(x)
fy_prealloc = prox!(y_prealloc, f, x, gamma)
@test typeof(fy_prealloc) == R
y_naive, fy_naive = ProximalOperators.prox_naive(f, x, gamma)
@test typeof(fy_naive) == R
rtol = if is_proximable(f) sqrt(eps(R)) else 1e-4 end
if is_convex(f)
@test all(isapprox.(y_prealloc, y, rtol=rtol, atol=100*eps(R)))
@test all(isapprox.(y_naive, y, rtol=rtol, atol=100*eps(R)))
if is_set_indicator(f)
@test fy_prealloc == 0
end
@test isapprox(fy_prealloc, fy, rtol=rtol, atol=100*eps(R))
@test isapprox(fy_naive, fy, rtol=rtol, atol=100*eps(R))
end
if !is_set_indicator(f) || is_proximable(f)
f_at_y = call_test(f, y)
if f_at_y !== nothing
@test isapprox(f_at_y, fy, rtol=rtol, atol=100*eps(R))
end
end
return y, fy
end
# tests equality of the results of prox, prox! and prox_naive
function gradient_test(f, x::ArrayOrTuple{R}, gamma=R(1)) where R <: Real
grad_fx, fx = gradient(f, x)
@test typeof(fx) == R
return grad_fx, fx
end
# test predicates consistency
# i.e., that more specific properties imply less specific ones
# e.g., the indicator of a subspace is the indicator of a set in particular
function predicates_test(f)
preds = [
is_convex,
is_strongly_convex,
is_generalized_quadratic,
is_quadratic,
is_smooth,
is_singleton_indicator,
is_cone_indicator,
is_affine_indicator,
is_set_indicator,
is_positively_homogeneous,
is_support,
]
for pred in preds
# check that the value of the predicate can be inferred
@inferred (arg -> Val(pred(arg)))(f)
end
# quadratic => generalized_quadratic && smooth
@test !is_quadratic(f) || (is_generalized_quadratic(f) && is_smooth(f))
# (singleton || cone || affine) => set
@test !(is_singleton_indicator(f) || is_cone_indicator(f) || is_affine_indicator(f)) || is_set_indicator(f)
# cone => positively homogeneous
@test !is_cone_indicator(f) || is_positively_homogeneous(f)
# (convex && positively homogeneous) <=> (convex && support)
@test (is_convex(f) && is_positively_homogeneous(f)) == (is_convex(f) && is_support(f))
# strongly_convex => convex
@test !is_strongly_convex(f) || is_convex(f)
end
@testset "Aqua" begin
Aqua.test_all(ProximalOperators; ambiguities=false)
end
@testset "Documentation" begin
doctest(ProximalOperators)
end
@testset "Utilities" begin
include("test_symmetricpacked.jl")
end
@testset "Functions" begin
include("test_cubeNormL2.jl")
include("test_huberLoss.jl")
include("test_indAffine.jl")
include("test_leastSquares.jl")
include("test_logisticLoss.jl")
include("test_quadratic.jl")
include("test_linear.jl")
include("test_indHyperslab.jl")
include("test_graph.jl")
include("test_normL1plusL2.jl")
end
include("test_calls.jl")
include("test_indPolyhedral.jl")
@testset "Gradients" begin
include("test_gradients.jl")
end
@testset "Calculus rules" begin
include("test_calculus.jl")
include("test_epicompose.jl")
include("test_moreauEnvelope.jl")
include("test_precompose.jl")
include("test_pointwiseMinimum.jl")
include("test_postcompose.jl")
include("test_regularize.jl")
include("test_separableSum.jl")
include("test_slicedSeparableSum.jl")
include("test_precomposedSlicedSeparableSum.jl")
include("test_sum.jl")
include("test_reshapeInput.jl")
end
@testset "Equivalences" begin
include("test_equivalences.jl")
end
include("test_optimality_conditions.jl")
@testset "Hardcoded" begin
include("test_results.jl")
end
@testset "Demos" begin
include("../demos/lasso.jl")
include("../demos/rpca.jl")
end