Help creating a JuMP variable array

This is because Diagonal only stores the diagonal elements, and uses the zero function to get the off-diagonal elements when needed for generic methods. Since

julia> typeof(zero(Rdiag[1]))
JuMP.GenericAffExpr{Float64,JuMP.Variable}

we have typeof(Diagonal(Rdiag)[1, 2]) != typeof(Diagonal(Rdiag)[1, 1]), and since flipdim uses the element type of its input matrix as the element type of its output, you get an error saying that you can’t put a GenericAffExpr in a matrix of Variables.

You can work around this using

flipdim(Matrix(Diagonal(Rdiag)), 2)

Edit: opened this issue: https://github.com/JuliaLang/julia/issues/27494.

1 Like