Skip to content

Commit de7c66d

Browse files
committed
Update
1 parent d298200 commit de7c66d

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

ext/MathOptInterfaceLDLFactorizationsExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import SparseArrays
1414
# The type signature of this function is not important, so long as it is more
1515
# specific than the (untyped) generic fallback with the error pointing to
1616
# LDLFactorizations.jl
17-
function MOI.Bridges.Constraint.compute_sparse_sqrt_root_fallback(
17+
function MOI.Bridges.Constraint.compute_sparse_sqrt_fallback(
1818
Q::AbstractMatrix,
1919
::F,
2020
::S,

src/Bridges/Constraint/bridges/QuadtoSOCBridge.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ end
6060
const QuadtoSOC{T,OT<:MOI.ModelLike} =
6161
SingleBridgeOptimizer{QuadtoSOCBridge{T},OT}
6262

63-
function compute_sparse_sqrt_root_fallback(Q, ::F, ::S) where {F,S}
63+
function compute_sparse_sqrt_fallback(Q, ::F, ::S) where {F,S}
6464
msg = """
6565
Unable to transform a quadratic constraint into a SecondOrderCone
6666
constraint because the quadratic constraint is not strongly convex and
@@ -79,10 +79,10 @@ function compute_sparse_sqrt_root_fallback(Q, ::F, ::S) where {F,S}
7979
return throw(MOI.AddConstraintNotAllowed{F,S}(msg))
8080
end
8181

82-
function compute_sparse_sqrt_root(Q, func, set)
82+
function compute_sparse_sqrt(Q, func, set)
8383
factor = LinearAlgebra.cholesky(Q; check = false)
8484
if !LinearAlgebra.issuccess(factor)
85-
return compute_sparse_sqrt_root_fallback(Q, func, set)
85+
return compute_sparse_sqrt_fallback(Q, func, set)
8686
end
8787
L, p = SparseArrays.sparse(factor.L), factor.p
8888
# We have Q = P' * L * L' * P. We want to find Q = U' * U, so U = L' * P
@@ -117,7 +117,7 @@ function bridge_constraint(
117117
MOI.ScalarAffineTerm(scale * term.coefficient, term.variable),
118118
) for term in func.affine_terms
119119
]
120-
I, J, V = compute_sparse_sqrt_root(LinearAlgebra.Symmetric(Q), func, set)
120+
I, J, V = compute_sparse_sqrt(LinearAlgebra.Symmetric(Q), func, set)
121121
for (i, j, v) in zip(I, J, V)
122122
push!(
123123
vector_terms,

test/Bridges/Constraint/QuadtoSOCBridge.jl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ function test_semidefinite_cholesky_fail()
355355
return
356356
end
357357

358-
function test_compute_sparse_U_edge_cases()
358+
function test_compute_sparse_sqrt_edge_cases()
359359
f = zero(MOI.ScalarQuadraticFunction{Float64})
360360
s = MOI.GreaterThan(0.0)
361361
for A in [
@@ -371,7 +371,7 @@ function test_compute_sparse_U_edge_cases()
371371
[2.0 0.0; 0.0 0.0],
372372
]
373373
B = SparseArrays.sparse(A)
374-
I, J, V = MOI.Bridges.Constraint.compute_sparse_sqrt_root(B, f, s)
374+
I, J, V = MOI.Bridges.Constraint.compute_sparse_sqrt(B, f, s)
375375
U = zeros(size(A))
376376
for (i, j, v) in zip(I, J, V)
377377
U[i, j] += v
@@ -382,7 +382,21 @@ function test_compute_sparse_U_edge_cases()
382382
B = SparseArrays.sparse(A)
383383
@test_throws(
384384
MOI.UnsupportedConstraint{typeof(f),typeof(s)},
385-
MOI.Bridges.Constraint.compute_sparse_sqrt_root(B, f, s),
385+
MOI.Bridges.Constraint.compute_sparse_sqrt(B, f, s),
386+
)
387+
return
388+
end
389+
390+
function test_compute_sparse_sqrt_fallback()
391+
# Test the default fallback that is hit when LDLFactorizations isn't loaded.
392+
# We could put the test somewhere else so it runs before this file is
393+
# loaded, but that's pretty flakey for a long-term solution. Instead, we're
394+
# going to abuse the lack of a strong type signature to hit it:
395+
f = zero(MOI.ScalarAffineFunction{Float64})
396+
A = SparseArrays.sparse([-1.0 0.0; 0.0 1.0])
397+
@test_throws(
398+
MOI.AddConstraintNotAllowed{typeof(f),MOI.GreaterThan{Float64}},
399+
MOI.Bridges.Constraint.compute_sparse_sqrt(A, f, MOI.GreaterThan(0.0)),
386400
)
387401
return
388402
end

0 commit comments

Comments
 (0)