Skip to content

Commit 6c45e7b

Browse files
authored
[Utilities] fix support for complex values in Indicator distance_to_set (#2927)
1 parent 1cbe497 commit 6c45e7b

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/Utilities/distance_to_set.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -613,27 +613,27 @@ function distance_to_set(
613613
distance::ProjectionUpperBoundDistance,
614614
x::AbstractVector{T},
615615
set::MOI.Indicator{MOI.ACTIVATE_ON_ONE},
616-
) where {T<:Real}
616+
) where {T<:Number}
617617
_check_dimension(x, set)
618618
return min(
619619
# Distance of x[1] from 0
620620
abs(x[1]),
621621
# Distance of x[1] from 1 + distance to set
622-
sqrt((1 - x[1])^2 + distance_to_set(distance, x[2], set.set)^2),
622+
sqrt(abs(1 - x[1])^2 + distance_to_set(distance, x[2], set.set)^2),
623623
)
624624
end
625625

626626
function distance_to_set(
627627
distance::ProjectionUpperBoundDistance,
628628
x::AbstractVector{T},
629629
set::MOI.Indicator{MOI.ACTIVATE_ON_ZERO},
630-
) where {T}
630+
) where {T<:Number}
631631
_check_dimension(x, set)
632632
return min(
633633
# Distance of x[1] from 1
634634
abs(one(T) - x[1]),
635635
# Distance of x[1] from 0 + distance to set
636-
sqrt(x[1]^2 + distance_to_set(distance, x[2], set.set)^2),
636+
sqrt(abs(x[1])^2 + distance_to_set(distance, x[2], set.set)^2),
637637
)
638638
end
639639

@@ -647,7 +647,7 @@ function distance_to_set(
647647
::ProjectionUpperBoundDistance,
648648
x::AbstractVector{T},
649649
set::MOI.NormNuclearCone,
650-
) where {T}
650+
) where {T<:Real}
651651
_check_dimension(x, set)
652652
X = reshape(x[2:end], set.row_dim, set.column_dim)
653653
return max(sum(LinearAlgebra.svdvals(X)) - x[1], zero(T))
@@ -663,7 +663,7 @@ function distance_to_set(
663663
::ProjectionUpperBoundDistance,
664664
x::AbstractVector{T},
665665
set::MOI.NormSpectralCone,
666-
) where {T}
666+
) where {T<:Real}
667667
_check_dimension(x, set)
668668
X = reshape(x[2:end], set.row_dim, set.column_dim)
669669
return max(maximum(LinearAlgebra.svdvals(X)) - x[1], zero(T))

test/Utilities/distance_to_set.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,24 @@ function test_HermitianPositiveSemidefiniteConeTriangle()
515515
return
516516
end
517517

518+
function test_indicator_complex()
519+
_test_set(
520+
MOI.Indicator{MOI.ACTIVATE_ON_ZERO}(MOI.EqualTo(1.0+2.0im)),
521+
[0.0, 1.0+2.0im] => 0.0,
522+
[0.01, 1.0+1.0im] => 0.99,
523+
[0.0, 1.0+1.0im] => 1.0,
524+
[0.0, 1.0+1.5im] => 0.5,
525+
)
526+
_test_set(
527+
MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.EqualTo(1.0+2.0im)),
528+
[1.0, 1.0+2.0im] => 0.0,
529+
[0.99, 1.0+1.0im] => 0.99,
530+
[1.0, 1.0+1.0im] => 1.0,
531+
[1.0, 1.0+1.5im] => 0.5,
532+
)
533+
return
534+
end
535+
518536
end
519537

520538
TestFeasibilityChecker.runtests()

0 commit comments

Comments
 (0)