Skip to content

Commit 4068f80

Browse files
authored
allow sumlargest(x,k), sumsmallest(x,k), and sumlargesteigs(x,k) for k=0 (#429)
* fix 423 * bump version, fix NEWS
1 parent 9a68809 commit 4068f80

File tree

7 files changed

+20
-8
lines changed

7 files changed

+20
-8
lines changed

NEWS.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
# Changes in v0.14.3
1+
# Changes in v0.14.5
2+
3+
* allow `sumlargest(x,k)`, `sumsmallest(x,k)`, and `sumlargesteigs(x,k)` for `k=0` (simply returns `Constant(0)`). ([#429](https://github.com/jump-dev/Convex.jl/pull/429)).
4+
5+
# Changes in v0.14.4
26

37
* fixed a bug where the values of variables were being converted to `Float64` even if the problem was solved in high precision. ([#427](https://github.com/jump-dev/Convex.jl/pull/427)).
48

9+
# Changes in v0.14.3
10+
11+
* update compatibility bounds for BenchmarkTools 0.6
12+
513
# Changes in v0.14.2
614

715
* added lasso, ridge, and elastic net regression examples ([#420](https://github.com/jump-dev/Convex.jl/pull/420)). Thanks to @PaulSoderlind!

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Convex"
22
uuid = "f65535da-76fb-5f13-bab9-19810c17039a"
3-
version = "0.14.4"
3+
version = "0.14.5"
44

55
[deps]
66
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/atoms/lp_cone/sumlargest.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ function conic_form!(x::SumLargestAtom, unique_conic_forms::UniqueConicForms)
6060
return get_conic_form(unique_conic_forms, x)
6161
end
6262

63-
sumlargest(x::AbstractExpr, k::Int) = SumLargestAtom(x, k)
64-
sumsmallest(x::AbstractExpr, k::Int) = -SumLargestAtom(-x, k)
63+
sumlargest(x::AbstractExpr, k::Int) = k == 0 ? Constant(0) : SumLargestAtom(x, k)
64+
sumsmallest(x::AbstractExpr, k::Int) = k == 0 ? Constant(0) : -SumLargestAtom(-x, k)

src/atoms/sdp_cone/sumlargesteigs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function evaluate(x::SumLargestEigs)
4242
eigvals(evaluate(x.children[1]))[end-x.children[2]:end]
4343
end
4444

45-
sumlargesteigs(x::AbstractExpr, k::Int) = SumLargestEigs(x, Constant(k))
45+
sumlargesteigs(x::AbstractExpr, k::Int) = k == 0 ? Constant(0) : SumLargestEigs(x, Constant(k))
4646

4747
# Create the equivalent conic problem:
4848
# minimize sk + Tr(Z)

src/problem_depot/problems/lp.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ end
147147

148148
@add_problem lp function lp_sumlargest_atom(handle_problem!, ::Val{test}, atol, rtol, ::Type{T}) where {T, test}
149149
x = Variable(2)
150-
p = minimize(sumlargest(x, 2), x >= [1; 1]; numeric_type = T)
150+
p = minimize(sumlargest(x, 2) + sumlargest(x,0), x >= [1; 1]; numeric_type = T)
151151

152152
if test
153153
@test vexity(p) == ConvexVexity()
@@ -173,7 +173,7 @@ end
173173

174174
@add_problem lp function lp_sumsmallest_atom(handle_problem!, ::Val{test}, atol, rtol, ::Type{T}) where {T, test}
175175
x = Variable(4, 4)
176-
p = minimize(sumlargest(x, 2), sumsmallest(x, 4) >= 1; numeric_type = T)
176+
p = minimize(sumlargest(x, 2) + sumsmallest(x,0), sumsmallest(x, 4) >= 1; numeric_type = T)
177177

178178
if test
179179
@test vexity(p) == ConvexVexity()

src/problem_depot/problems/sdp.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ end
221221
end
222222

223223
x = Semidefinite(3)
224-
p = minimize(sumlargesteigs(x, 2), [x[i,:] >= i for i=1:3]...; numeric_type = T)
224+
p = minimize(sumlargesteigs(x, 2) + sumlargesteigs(x,0), [x[i,:] >= i for i=1:3]...; numeric_type = T)
225225

226226
handle_problem!(p)
227227

test/test_utilities.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,10 @@ end
420420
c = 1.0
421421
@test evaluate(Constant(c)) c
422422
@test Constant(c).size == (1,1)
423+
424+
@test evaluate(sumlargesteigs(Variable(4, 4), 0)) == 0
425+
@test evaluate(sumlargest(Variable(4), 0)) == 0
426+
@test evaluate(sumsmallest(Variable(4), 0)) == 0
423427
end
424428

425429
@testset "Base.vect" begin

0 commit comments

Comments
 (0)