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

Wrap reshaped vector in LinearAlgebra.Hermitian #3245

Merged
merged 3 commits into from
Feb 27, 2023
Merged

Conversation

blegat
Copy link
Member

@blegat blegat commented Feb 27, 2023

This is done for the Symmetric counterpart:

return LinearAlgebra.Symmetric(matrix)

@codecov
Copy link

codecov bot commented Feb 27, 2023

Codecov Report

Base: 98.08% // Head: 98.08% // No change to project coverage 👍

Coverage data is based on head (cbabac9) compared to base (4d64d8d).
Patch coverage: 100.00% of modified lines in pull request are covered.

❗ Current head cbabac9 differs from pull request most recent head 1d5ba9e. Consider uploading reports for the commit 1d5ba9e to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3245   +/-   ##
=======================================
  Coverage   98.08%   98.08%           
=======================================
  Files          34       34           
  Lines        4656     4656           
=======================================
  Hits         4567     4567           
  Misses         89       89           
Impacted Files Coverage Δ
src/sd.jl 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@odow odow merged commit 45f64f0 into master Feb 27, 2023
@odow odow deleted the bl/reshape_hermitian branch February 27, 2023 19:20
@odow
Copy link
Member

odow commented Feb 27, 2023

I think this broke:

julia> model = Model(SCS.Optimizer);

julia> E = [@variable(model, [1:d, 1:d] in HermitianPSDCone()) for i in 1:n]
4-element Vector{LinearAlgebra.Hermitian{GenericAffExpr{ComplexF64, VariableRef}, Matrix{GenericAffExpr{ComplexF64, VariableRef}}}}:
 [_[1] _[2] + (0.0 + 1.0im) _[11] _[4] + (0.0 + 1.0im) _[12] _[7] + (0.0 + 1.0im) _[14]; _[2] + (0.0 - 1.0im) _[11] _[3] _[5] + (0.0 + 1.0im) _[13] _[8] + (0.0 + 1.0im) _[15]; _[4] + (0.0 - 1.0im) _[12] _[5] + (0.0 - 1.0im) _[13] _[6] _[9] + (0.0 + 1.0im) _[16]; _[7] + (0.0 - 1.0im) _[14] _[8] + (0.0 - 1.0im) _[15] _[9] + (0.0 - 1.0im) _[16] _[10]]
 [_[17] _[18] + (0.0 + 1.0im) _[27] _[20] + (0.0 + 1.0im) _[28] _[23] + (0.0 + 1.0im) _[30]; _[18] + (0.0 - 1.0im) _[27] _[19] _[21] + (0.0 + 1.0im) _[29] _[24] + (0.0 + 1.0im) _[31]; _[20] + (0.0 - 1.0im) _[28] _[21] + (0.0 - 1.0im) _[29] _[22] _[25] + (0.0 + 1.0im) _[32]; _[23] + (0.0 - 1.0im) _[30] _[24] + (0.0 - 1.0im) _[31] _[25] + (0.0 - 1.0im) _[32] _[26]]
 [_[33] _[34] + (0.0 + 1.0im) _[43] _[36] + (0.0 + 1.0im) _[44] _[39] + (0.0 + 1.0im) _[46]; _[34] + (0.0 - 1.0im) _[43] _[35] _[37] + (0.0 + 1.0im) _[45] _[40] + (0.0 + 1.0im) _[47]; _[36] + (0.0 - 1.0im) _[44] _[37] + (0.0 - 1.0im) _[45] _[38] _[41] + (0.0 + 1.0im) _[48]; _[39] + (0.0 - 1.0im) _[46] _[40] + (0.0 - 1.0im) _[47] _[41] + (0.0 - 1.0im) _[48] _[42]]
 [_[49] _[50] + (0.0 + 1.0im) _[59] _[52] + (0.0 + 1.0im) _[60] _[55] + (0.0 + 1.0im) _[62]; _[50] + (0.0 - 1.0im) _[59] _[51] _[53] + (0.0 + 1.0im) _[61] _[56] + (0.0 + 1.0im) _[63]; _[52] + (0.0 - 1.0im) _[60] _[53] + (0.0 - 1.0im) _[61] _[54] _[57] + (0.0 + 1.0im) _[64]; _[55] + (0.0 - 1.0im) _[62] _[56] + (0.0 - 1.0im) _[63] _[57] + (0.0 - 1.0im) _[64] _[58]]

julia> @constraint(model, sum(E) .== LinearAlgebra.I)
ERROR: MethodError: no method matching isreal(::GenericAffExpr{ComplexF64, VariableRef})
Closest candidates are:
  isreal(::Complex) at complex.jl:133
  isreal(::Missing) at missing.jl:101
  isreal(::Union{LinearAlgebra.Hermitian{T, S}, LinearAlgebra.Symmetric{T, S}} where {T, S}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/symmetric.jl:317
  ...
Stacktrace:
 [1] setindex!(A::LinearAlgebra.Hermitian{GenericAffExpr{ComplexF64, VariableRef}, Matrix{GenericAffExpr{ComplexF64, VariableRef}}}, v::GenericAffExpr{ComplexF64, VariableRef}, i::Int64, j::Int64)
   @ LinearAlgebra /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/symmetric.jl:232
 [2] +(A::LinearAlgebra.Hermitian{GenericAffExpr{ComplexF64, VariableRef}, Matrix{GenericAffExpr{ComplexF64, VariableRef}}}, J::LinearAlgebra.UniformScaling{Int64})
   @ LinearAlgebra /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/uniformscaling.jl:219
 [3] -
   @ /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/uniformscaling.jl:160 [inlined]
 [4] sub_mul
   @ ~/.julia/packages/MutableArithmetics/geMUn/src/MutableArithmetics.jl:38 [inlined]
 [5] _broadcast_with_uniform_scaling!
   @ ~/.julia/packages/MutableArithmetics/geMUn/src/broadcast.jl:184 [inlined]
 [6] broadcast!!(::typeof(MutableArithmetics.sub_mul), ::LinearAlgebra.Hermitian{GenericAffExpr{ComplexF64, VariableRef}, Matrix{GenericAffExpr{ComplexF64, VariableRef}}}, ::LinearAlgebra.UniformScaling{Bool})
   @ MutableArithmetics ~/.julia/packages/MutableArithmetics/geMUn/src/broadcast.jl:170
 [7] macro expansion
   @ ~/.julia/packages/MutableArithmetics/geMUn/src/rewrite.jl:322 [inlined]
 [8] macro expansion
   @ ~/.julia/dev/JuMP/src/macros.jl:832 [inlined]
 [9] top-level scope
   @ REPL[20]:1

@odow
Copy link
Member

odow commented Feb 27, 2023

I have a PR with a tutorial and a fix incoming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants