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

*(::Real, ::Hermitian) is not hermitian #3694

Closed
odow opened this issue Feb 29, 2024 · 5 comments · Fixed by #3695
Closed

*(::Real, ::Hermitian) is not hermitian #3694

odow opened this issue Feb 29, 2024 · 5 comments · Fixed by #3695

Comments

@odow
Copy link
Member

odow commented Feb 29, 2024

julia> using JuMP, LinearAlgebra

julia> A = LinearAlgebra.Hermitian([1 1+1im; 1-1im 2])
2×2 Hermitian{Complex{Int64}, Matrix{Complex{Int64}}}:
 1+0im  1+1im
 1-1im  2+0im

julia> model = Model();

julia> @variable(model, x)
x

julia> x * A
2×2 Matrix{GenericAffExpr{ComplexF64, VariableRef}}:
 x           (1 + im) x
 (1 - im) x  2 x

x-ref jump-dev/MutableArithmetics.jl#264 (comment)

@odow
Copy link
Member Author

odow commented Feb 29, 2024

I guess the problem with *(a::AbstractMutable, A::LinearAlgebra.Hermitian) is that there is no way to know if a is real or complex.

@araujoms
Copy link
Contributor

Why not? As far as I understand there's only three possibilities that need to be tested: GenericVariableRef{T}, GenericAffExpr{T, GenericVariableRef{T}}, and GenericAffExpr{Complex{T}, GenericVariableRef{T}}. A bit cumbersome but doable, no?

@odow
Copy link
Member Author

odow commented Feb 29, 2024

We could do this in JuMP, but there is no easy fix in MutableArithmetics for arbitrary types.

@araujoms
Copy link
Contributor

I see. Maybe it is worth it to introduce RealMutableScalar and ComplexMutableScalar supertypes? I had a similar problem in jump-dev/Hypatia.jl#831: I needed to dispatch a function on whether the argument was a real or complex Mutable, and I couldn't figure out how. So in the end I just did a ugly hack hoping that a better programmer could fix it.

@odow
Copy link
Member Author

odow commented Feb 29, 2024

I'd rather not do that unless absolutely necessary. MA is already too complicated. In this case, the answer is still correct, it's just not the most performant.

We can fix this in JuMP though, so I'll move the issue.

@odow odow transferred this issue from jump-dev/MutableArithmetics.jl Feb 29, 2024
@odow odow closed this as completed in #3695 Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants