@@ -10,6 +10,7 @@ import LinearAlgebra
1010import SparseArrays
1111using Test
1212
13+ import LDLFactorizations
1314import MathOptInterface as MOI
1415
1516function runtests ()
@@ -344,16 +345,13 @@ function test_semidefinite_cholesky_fail()
344345 model = MOI. Bridges. Constraint. QuadtoSOC {Float64} (inner)
345346 x = MOI. add_variables (model, 2 )
346347 f = 0.5 * x[1 ] * x[1 ] + 1.0 * x[1 ] * x[2 ] + 0.5 * x[2 ] * x[2 ]
347- @test_throws (
348- MOI. UnsupportedConstraint,
349- MOI. add_constraint (model, f, MOI. LessThan (1.0 )),
350- )
351- # F, S = MOI.VectorAffineFunction{Float64}, MOI.RotatedSecondOrderCone
352- # ci = only(MOI.get(inner, MOI.ListOfConstraintIndices{F,S}()))
353- # g = MOI.get(inner, MOI.ConstraintFunction(), ci)
354- # y = MOI.get(inner, MOI.ListOfVariableIndices())
355- # sum_y = 1.0 * y[1] + 1.0 * y[2]
356- # @test isapprox(g, MOI.Utilities.vectorize([1.0, 1.0, sum_y, 0.0]))
348+ c = MOI. add_constraint (model, f, MOI. LessThan (1.0 ))
349+ F, S = MOI. VectorAffineFunction{Float64}, MOI. RotatedSecondOrderCone
350+ ci = only (MOI. get (inner, MOI. ListOfConstraintIndices {F,S} ()))
351+ g = MOI. get (inner, MOI. ConstraintFunction (), ci)
352+ y = MOI. get (inner, MOI. ListOfVariableIndices ())
353+ sum_y = 1.0 * y[1 ] + 1.0 * y[2 ]
354+ @test isapprox (g, MOI. Utilities. vectorize ([1.0 , 1.0 , sum_y, 0.0 ]))
357355 return
358356end
359357
@@ -363,8 +361,12 @@ function test_compute_sparse_sqrt_edge_cases()
363361 [1.0 0.0 ; 0.0 2.0 ],
364362 # Cholesky works, with pivoting
365363 [1.0 0.0 1.0 ; 0.0 1.0 1.0 ; 1.0 1.0 3.0 ],
364+ # Cholesky fails due to 0 eigen value. LDL works
365+ [1.0 1.0 ; 1.0 1.0 ],
366366 # Cholesky succeeds, even though 0 eigen value
367367 [2.0 2.0 ; 2.0 2.0 ],
368+ # Cholesky fails because of 0 column/row. LDL works
369+ [2.0 0.0 ; 0.0 0.0 ],
368370 ]
369371 B = SparseArrays. sparse (A)
370372 f = zero (MOI. ScalarQuadraticFunction{eltype (A)})
@@ -379,8 +381,6 @@ function test_compute_sparse_sqrt_edge_cases()
379381 # Test failures
380382 for A in Any[
381383 [- 1.0 0.0 ; 0.0 1.0 ],
382- [1.0 1.0 ; 1.0 1.0 ],
383- [2.0 0.0 ; 0.0 0.0 ],
384384 # Found from test_quadratic_nonconvex_constraint_basic
385385 [0.0 - 1.0 ; - 1.0 0.0 ],
386386 # Different element type. We could potentially make this work in future,
@@ -400,6 +400,20 @@ function test_compute_sparse_sqrt_edge_cases()
400400 return
401401end
402402
403+ function test_compute_sparse_sqrt_fallback ()
404+ # Test the default fallback that is hit when LDLFactorizations isn't loaded.
405+ # We could put the test somewhere else so it runs before this file is
406+ # loaded, but that's pretty flakey for a long-term solution. Instead, we're
407+ # going to abuse the lack of a strong type signature to hit it:
408+ f = zero (MOI. ScalarAffineFunction{Float64})
409+ A = SparseArrays. sparse ([- 1.0 0.0 ; 0.0 1.0 ])
410+ @test_throws (
411+ MOI. AddConstraintNotAllowed{typeof (f),MOI. GreaterThan{Float64}},
412+ MOI. Bridges. Constraint. compute_sparse_sqrt (A, f, MOI. GreaterThan (0.0 )),
413+ )
414+ return
415+ end
416+
403417end # module
404418
405419TestConstraintQuadToSOC. runtests ()
0 commit comments