Skip to content

Commit 9e7dcc8

Browse files
committed
[Utilities] fix support for complex values in Indicator distance_to_set
1 parent 1cbe497 commit 9e7dcc8

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

src/Utilities/distance_to_set.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -613,27 +613,28 @@ 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)
618+
618619
return min(
619620
# Distance of x[1] from 0
620621
abs(x[1]),
621622
# Distance of x[1] from 1 + distance to set
622-
sqrt((1 - x[1])^2 + distance_to_set(distance, x[2], set.set)^2),
623+
sqrt(abs(1 - x[1])^2 + distance_to_set(distance, x[2], set.set)^2),
623624
)
624625
end
625626

626627
function distance_to_set(
627628
distance::ProjectionUpperBoundDistance,
628629
x::AbstractVector{T},
629630
set::MOI.Indicator{MOI.ACTIVATE_ON_ZERO},
630-
) where {T}
631+
) where {T<:Number}
631632
_check_dimension(x, set)
632633
return min(
633634
# Distance of x[1] from 1
634635
abs(one(T) - x[1]),
635636
# Distance of x[1] from 0 + distance to set
636-
sqrt(x[1]^2 + distance_to_set(distance, x[2], set.set)^2),
637+
sqrt(abs(x[1])^2 + distance_to_set(distance, x[2], set.set)^2),
637638
)
638639
end
639640

@@ -647,7 +648,7 @@ function distance_to_set(
647648
::ProjectionUpperBoundDistance,
648649
x::AbstractVector{T},
649650
set::MOI.NormNuclearCone,
650-
) where {T}
651+
) where {T<:Real}
651652
_check_dimension(x, set)
652653
X = reshape(x[2:end], set.row_dim, set.column_dim)
653654
return max(sum(LinearAlgebra.svdvals(X)) - x[1], zero(T))
@@ -663,7 +664,7 @@ function distance_to_set(
663664
::ProjectionUpperBoundDistance,
664665
x::AbstractVector{T},
665666
set::MOI.NormSpectralCone,
666-
) where {T}
667+
) where {T<:Real}
667668
_check_dimension(x, set)
668669
X = reshape(x[2:end], set.row_dim, set.column_dim)
669670
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)