Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/atoms/second_order_cone/quadform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ function quadform(x::AbstractExpr, A::Value)
if length(size(A)) != 2 || size(A, 1) != size(A, 2)
error("Quadratic form only takes square matrices")
end
if !issymmetric(A)
error("Quadratic form only defined for symmetric matrices")
if !ishermitian(A)
error("Quadratic form only defined for Hermitian matrices")
end
V = eigvals(Symmetric(Matrix(A)))

if all(V .>= 0)
if isposdef(A)
factor = 1
elseif all(V .<= 0)
elseif isposdef(.-A)
factor = -1
else
error("Quadratic forms supported only for semidefinite matrices")
end

P = real(sqrt(Matrix(factor * A)))
P = sqrt(Hermitian(factor * A))
return factor * square(norm2(P * x))
end

Expand Down
13 changes: 13 additions & 0 deletions src/problem_depot/problems/socp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,19 @@ end
@test evaluate(H) Hval atol=atol rtol=rtol
end

# https://github.com/jump-dev/Convex.jl/pull/444
x = Variable(3)
a,b,c,d,e,f = rand(6)
M = [2 a-b*im c-d*im;
a+b*im 2 e-f*im
c+d*im e+f*im 2]
y = rand(3)
p = minimize(quadform(x-y,M); numeric_type = T)
handle_problem!(p)
if test
@test evaluate(x) y 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