Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix complex variables of custom coefficient type #3691

Merged
merged 6 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2104,10 +2104,10 @@ function add_variable(
real_part = add_variable(model, _real(var), _real(name))
imag_part = add_variable(model, _imag(var), _imag(name))
# Efficiently build `real_part + imag_part * im`
return GenericAffExpr{ComplexF64,GenericVariableRef{T}}(
zero(ComplexF64),
real_part => one(ComplexF64),
imag_part => convert(ComplexF64, im),
return GenericAffExpr{Complex{T},GenericVariableRef{T}}(
zero(Complex{T}),
real_part => one(Complex{T}),
imag_part => convert(Complex{T}, im),
)
end

Expand Down
18 changes: 18 additions & 0 deletions test/test_complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,22 @@ function test_HermitianPSDCone_general_matrix_error()
return
end

function test_complex_generic_number_type()
for T in (Float32, Float64, Rational{BigInt}, BigFloat)
model = GenericModel{T}()
@variable(model, x in ComplexPlane())
@test x isa GenericAffExpr{Complex{T},GenericVariableRef{T}}
end
return
end

function test_hermitian_generic_number_type()
for T in (Float32, Float64, Rational{BigInt}, BigFloat)
model = GenericModel{T}()
@variable(model, x[1:2, 1:2], Hermitian)
@test x[1, 1] isa GenericAffExpr{Complex{T},GenericVariableRef{T}}
end
return
end

end # TestComplexNumberSupport
Loading