Skip to content

Commit f2e2b7c

Browse files
committed
Add tests
1 parent 92c5707 commit f2e2b7c

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

src/Bridges/Constraint/bridges/HermitianToComplexSymmetricBridge.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,16 @@ end
4343
# Should be favored over `HermitianToSymmetricPSDBridge`
4444
MOI.Bridges.bridging_cost(::Type{<:HermitianToComplexSymmetricBridge}) = 0.5
4545

46-
function _promote_complex_vcat(::Type{T}, ::Type{G}) where {T,G}
46+
function _promote_complex_vcat(::Type{T}, ::Type{G}) where {T<:Real,G}
4747
S = MOI.Utilities.scalar_type(G)
48-
M = MOI.Utilities.promote_operation(*, Complex{T}, S)
49-
return MOI.Utilities.promote_operation(vcat, T, M)
48+
if S === T
49+
M = Complex{T}
50+
elseif S <: MOI.Utilities.TypedLike{T}
51+
M = MOI.Utilities.similar_type(S, Complex{T})
52+
else
53+
M = MOI.Utilities.promote_operation(*, Complex{T}, Complex{T}, S)
54+
end
55+
return MOI.Utilities.promote_operation(vcat, Complex{T}, M)
5056
end
5157

5258
function concrete_bridge_type(
@@ -97,7 +103,7 @@ function MOI.Bridges.map_function(
97103
else
98104
imag_index += 1
99105
real_scalars[real_index] =
100-
complex_scalars[real_index] +
106+
one(Complex{T}) * complex_scalars[real_index] +
101107
(one(T) * im) * complex_scalars[imag_index]
102108
end
103109
end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright (c) 2017: Miles Lubin and contributors
2+
# Copyright (c) 2017: Google Inc.
3+
#
4+
# Use of this source code is governed by an MIT-style license that can be found
5+
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
6+
7+
module TestConstraintHermitianToComplexSymmetric
8+
9+
using Test
10+
11+
import MathOptInterface as MOI
12+
13+
function runtests()
14+
for name in names(@__MODULE__; all = true)
15+
if startswith("$(name)", "test_")
16+
@testset "$(name)" begin
17+
getfield(@__MODULE__, name)()
18+
end
19+
end
20+
end
21+
return
22+
end
23+
24+
function test_dimension_2()
25+
MOI.Bridges.runtests(
26+
MOI.Bridges.Constraint.HermitianToComplexSymmetricBridge,
27+
model -> begin
28+
a, b, c = MOI.add_variables(model, 3)
29+
MOI.add_constraint(
30+
model,
31+
MOI.Utilities.vectorize([1.0 * a + 2.0 * b, 3.0 * c, 4.0 * b, 5.0 * a]),
32+
MOI.HermitianPositiveSemidefiniteConeTriangle(2),
33+
)
34+
end,
35+
model -> begin
36+
a, b, c = MOI.add_variables(model, 3)
37+
MOI.add_constraint(
38+
model,
39+
MOI.Utilities.vectorize([Complex(1.0) * a + Complex(2.0) * b, Complex(3.0) * c + 5.0 * im * a, Complex(4.0) * b]),
40+
MOI.PositiveSemidefiniteConeTriangle(2),
41+
)
42+
end,
43+
)
44+
return
45+
end
46+
47+
end # module
48+
49+
TestConstraintHermitianToComplexSymmetric.runtests()

0 commit comments

Comments
 (0)