Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
31 changes: 17 additions & 14 deletions src/Bridges/Constraint/bridges/QuadtoSOCBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,25 @@ function compute_sparse_sqrt_fallback(Q, ::F, ::S) where {F,S}
end

function compute_sparse_sqrt(Q, func, set)
factor = try
LinearAlgebra.cholesky(Q; check = false)
catch
msg = "There was an error computing a Cholesky decomposition"
try
factor = LinearAlgebra.cholesky(Q; check = false)
if !LinearAlgebra.issuccess(factor)
return compute_sparse_sqrt_fallback(Q, func, set)
end
L, p = SparseArrays.sparse(factor.L), factor.p
# We have Q = P' * L * L' * P. We want to find Q = U' * U, so U = L' * P
# First, compute L'. Note I and J are reversed
J, I, V = SparseArrays.findnz(L)
# Then, we want to permute the columns of L'. The rows stay in the same
# order.
return I, p[J], V
catch err
if err isa MOI.AddConstraintNotAllowed
rethrow(err)
end
msg = "There was an error computing a matrix square root"
throw(MOI.UnsupportedConstraint{typeof(func),typeof(set)}(msg))
end
if !LinearAlgebra.issuccess(factor)
return compute_sparse_sqrt_fallback(Q, func, set)
end
L, p = SparseArrays.sparse(factor.L), factor.p
# We have Q = P' * L * L' * P. We want to find Q = U' * U, so U = L' * P
# First, compute L'. Note I and J are reversed
J, I, V = SparseArrays.findnz(L)
# Then, we want to permute the columns of L'. The rows stay in the same
# order.
return I, p[J], V
end

function bridge_constraint(
Expand Down
1 change: 1 addition & 0 deletions test/Bridges/Constraint/test_QuadtoSOCBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ function test_compute_sparse_sqrt_edge_cases()
BigFloat[1.0 0.0; 0.0 2.0],
BigFloat[1.0 1.0; 1.0 1.0],
]
@show A
Comment thread
odow marked this conversation as resolved.
Outdated
B = SparseArrays.sparse(A)
f = zero(MOI.ScalarQuadraticFunction{eltype(A)})
s = MOI.GreaterThan(zero(eltype(A)))
Expand Down
Loading