Skip to content

Commit

Permalink
fix 398 (#399)
Browse files Browse the repository at this point in the history
* fix 398

* fix `diagm` for Julia 1.0
  • Loading branch information
ericphanson authored Aug 25, 2020
1 parent 4b1052e commit c97b779
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Changes in v0.13.5

* fix [#398](https://github.com/jump-dev/Convex.jl/issues/398) by allowing `fix!`'d variables in `quadform`.

# Changes in v0.13.4

* You can now create your own variable types by subtyping `AbstractVariable`.
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Convex"
uuid = "f65535da-76fb-5f13-bab9-19810c17039a"
version = "0.13.4"
version = "0.13.5"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
11 changes: 10 additions & 1 deletion src/atoms/second_order_cone/quadform.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

function quadform(x::Value, A::AbstractExpr)
return x' * A * x
end
Expand All @@ -23,3 +22,13 @@ function quadform(x::AbstractExpr, A::Value)
P = real(sqrt(Matrix(factor * A)))
return factor * square(norm2(P * x))
end

function quadform(x::AbstractExpr, A::AbstractExpr)
if vexity(x) == ConstVexity()
return quadform(evaluate(x), A)
elseif vexity(A) == ConstVexity()
return quadform(x, evaluate(A))
else
error("Either `x` or `A` must be constant in `quadform(x,A)`.")
end
end
21 changes: 21 additions & 0 deletions src/problem_depot/problems/socp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,27 @@ end
@test p.optval 3.7713 atol=atol rtol=rtol
@test evaluate(quadform(x, A)) -1 atol=atol rtol=rtol
end


# https://github.com/jump-dev/Convex.jl/issues/398
n = 3
b = randn(n)
x = Variable(n)
H = Semidefinite(n)
Hval = randn(n,n)
Hval .= Hval'*Hval+10*diagm(0 => ones(n)) # symmetric positive definite
fix!(H, Hval)
p = minimize(x'b + quadform(x,H), [x >= 0]; numeric_type = T)
handle_problem!(p)

p2 = minimize(x'b + quadform(x,Hval), [x >= 0]; numeric_type = T)
handle_problem!(p2)

if test
@test p.optval p2.optval atol=atol rtol=rtol
@test evaluate(H) Hval atol=atol rtol=rtol
end

end

@add_problem socp function socp_huber_atom(handle_problem!, ::Val{test}, atol, rtol, ::Type{T}) where {T, test}
Expand Down

2 comments on commit c97b779

@ericphanson
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/20132

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.13.5 -m "<description of version>" c97b779d7a8566a374639d85f542e5094f387300
git push origin v0.13.5

Please sign in to comment.