@@ -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)
209209end
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.
212230function distance_to_set (
213231 :: ProjectionUpperBoundDistance ,
@@ -553,7 +571,7 @@ function distance_to_set(
553571 MOI. PositiveSemidefiniteConeSquare,
554572 MOI. PositiveSemidefiniteConeTriangle,
555573 },
556- ) where {T<: Real }
574+ ) where {T<: Union{ Real,Complex} }
557575 _check_dimension (x, set)
558576 # We should return the norm of `A` defined by:
559577 # ```julia
@@ -565,8 +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- eigvals .= min .(zero (T), eigvals)
569- return LinearAlgebra. norm (eigvals, 2 )
586+ return LinearAlgebra. norm (min .(0 , eigvals), 2 )
570587end
571588
572589"""
@@ -702,3 +719,44 @@ function distance_to_set(
702719 push! (eigvals_neg, max (x[1 ] - x[2 ] * sum (log .(eigvals_pos)), zero (T)))
703720 return LinearAlgebra. norm (eigvals_neg, 2 )
704721end
722+
723+ """
724+ distance_to_set(
725+ ::ProjectionUpperBoundDistance,
726+ x::AbstractVector,
727+ set::MOI.Scaled{S},
728+ )
729+
730+ This is the distance in the un-scaled space.
731+ """
732+ function distance_to_set (
733+ dist:: ProjectionUpperBoundDistance ,
734+ x:: AbstractVector{T} ,
735+ set:: MOI.Scaled{S} ,
736+ ) where {T,S<: MOI.AbstractVectorSet }
737+ _check_dimension (x, set)
738+ scale = MOI. Utilities. SetDotScalingVector {T} (set. set)
739+ return distance_to_set (dist, x ./ scale, set. set)
740+ end
741+
742+ function distance_to_set (
743+ dist:: ProjectionUpperBoundDistance ,
744+ x:: AbstractVector{T} ,
745+ set:: MOI.HermitianPositiveSemidefiniteConeTriangle ,
746+ ) where {T<: Real }
747+ _check_dimension (x, set)
748+ output_set = MOI. PositiveSemidefiniteConeTriangle (set. side_dimension)
749+ y = zeros (Complex{T}, MOI. dimension (output_set))
750+ real_offset, imag_offset = 0 , length (y)
751+ for col in 1 : set. side_dimension
752+ for row in 1 : col
753+ real_offset += 1
754+ y[real_offset] = x[real_offset]
755+ if row != col
756+ imag_offset += 1
757+ y[real_offset] += x[imag_offset] * im
758+ end
759+ end
760+ end
761+ return distance_to_set (dist, y, output_set)
762+ end
0 commit comments