Skip to content

Commit 27bf37c

Browse files
committed
Update
1 parent 7545358 commit 27bf37c

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

src/Utilities/distance_to_set.jl

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function _reshape(
194194
MOI.LogDetConeTriangle,
195195
MOI.RootDetConeTriangle,
196196
},
197-
) where {T}
197+
) where {T<:Real}
198198
n = isqrt(2 * length(x))
199199
# The type annotation is needed for JET.
200200
X = zeros(T, n, n)::Matrix{T}
@@ -208,6 +208,24 @@ function _reshape(
208208
return LinearAlgebra.Symmetric(X)
209209
end
210210

211+
function _reshape(
212+
x::AbstractVector{T},
213+
set::MOI.PositiveSemidefiniteConeTriangle,
214+
) where {T<:Complex}
215+
n = isqrt(2 * length(x))
216+
# The type annotation is needed for JET.
217+
X = zeros(T, n, n)::Matrix{T}
218+
k = 1
219+
for i in 1:n
220+
for j in 1:i
221+
X[i, j] = conj(x[k])
222+
X[j, i] = x[k]
223+
k += 1
224+
end
225+
end
226+
return LinearAlgebra.Hermitian(X)
227+
end
228+
211229
# This is the minimal L2-norm.
212230
function distance_to_set(
213231
::ProjectionUpperBoundDistance,
@@ -565,13 +583,7 @@ function distance_to_set(
565583
# The norm should correspond to `MOI.Utilities.set_dot` so it's the
566584
# Frobenius norm, which is the Euclidean norm of the vector of eigenvalues.
567585
eigvals = LinearAlgebra.eigvals(_reshape(x, set))
568-
return LinearAlgebra.norm(_drop_positives.(eigvals), 2)
569-
end
570-
571-
_drop_positives(x::T) where {T<:Real} = min(zero(T), x)
572-
573-
function _drop_positives(x::T)::T where {T<:Complex}
574-
return ifelse(isreal(x), _drop_positives(real(x)), x)
586+
return LinearAlgebra.norm(min.(0, eigvals), 2)
575587
end
576588

577589
"""

test/Utilities/distance_to_set.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ function test_positivesemidefiniteconesquare()
321321
[1.0, -1.0, -1.0, 1.0] => 0.0,
322322
[1.0, -2.0, -2.0, 1.0] => 1.0,
323323
[1.0, 1.1, 1.1, -2.3] => 2.633053201505194,
324-
[1.0, -2.0, -2.0, 1.0] => 1.0,;
324+
[1.0, -2.0, -2.0, 1.0] => 1.0;
325325
mismatch = [1.0],
326326
)
327327
return
@@ -496,7 +496,7 @@ function test_PositiveSemidefiniteConeTriangle_Complex()
496496
ComplexF64[1.0, -1.0, 1.0] => 0.0,
497497
ComplexF64[1.0, -2.0, 1.0] => 1.0,
498498
ComplexF64[1.0, 1.1, -2.3] => 2.633053201505194,
499-
ComplexF64[1.0, 1-im, 1.0] => 2.449489742783177;
499+
ComplexF64[1.0, 1-im, 1.0] => 0.41421356237309537;
500500
mismatch = [1.0],
501501
)
502502
return
@@ -509,7 +509,7 @@ function test_HermitianPositiveSemidefiniteConeTriangle()
509509
[1.0, -1.0, 1.0, 0.0] => 0.0,
510510
[1.0, -2.0, 1.0, 0.0] => 1.0,
511511
[1.0, 1.1, -2.3, 0.0] => 2.633053201505194,
512-
[1.0, 1.0, 1.0, -1.0] => 2.449489742783177;
512+
[1.0, 1.0, 1.0, -1.0] => 0.41421356237309537;
513513
mismatch = [1.0],
514514
)
515515
return

0 commit comments

Comments
 (0)