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

eltype of -Symmetric(Q) #32374

Closed
blegat opened this issue Jun 20, 2019 · 0 comments · Fixed by #32375 or jump-dev/JuMP.jl#1993
Closed

eltype of -Symmetric(Q) #32374

blegat opened this issue Jun 20, 2019 · 0 comments · Fixed by #32375 or jump-dev/JuMP.jl#1993

Comments

@blegat
Copy link
Contributor

blegat commented Jun 20, 2019

The eltype if -Q where Q is a matrix is expected not to change which is incorrect when the eltype is Bool or VariableRef:

julia> B = ones(Bool, 1, 1)
1×1 Array{Bool,2}:
 true

julia> -Symmetric(B)
ERROR: InexactError: Bool(-1)
Stacktrace:
 [1] Type at ./float.jl:73 [inlined]
 [2] convert at ./number.jl:7 [inlined]
 [3] setindex! at ./array.jl:767 [inlined]
 [4] copyto!(::IndexLinear, ::Array{Bool,2}, ::IndexLinear, ::Array{Int64,2}) at ./abstractarray.jl:753
 [5] copyto! at ./abstractarray.jl:745 [inlined]
 [6] Type at ./array.jl:482 [inlined]
 [7] convert at ./array.jl:474 [inlined]
 [8] Type at /build/julia/src/julia-1.1.1/usr/share/julia/stdlib/v1.1/LinearAlgebra/src/symmetric.jl:10 [inlined]
 [9] -(::Symmetric{Bool,Array{Bool,2}}) at /build/julia/src/julia-1.1.1/usr/share/julia/stdlib/v1.1/LinearAlgebra/src/symmetric.jl:394
 [10] top-level scope at none:0

julia> model = Model()
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

julia> @variable(model, Q[1:2, 1:2], Symmetric)
2×2 Symmetric{VariableRef,Array{VariableRef,2}}:
 Q[1,1]  Q[1,2]
 Q[1,2]  Q[2,2]

julia> -Q
ERROR: MethodError: Cannot `convert` an object of type GenericAffExpr{Float64,VariableRef} to an object of type VariableRef
Closest candidates are:
  convert(::Type{T}, ::T) where T at essentials.jl:154
  VariableRef(::Any, ::Any) at /home/blegat/.julia/dev/JuMP/src/variables.jl:99
Stacktrace:
 [1] setindex!(::Array{VariableRef,2}, ::GenericAffExpr{Float64,VariableRef}, ::Int64) at ./array.jl:767
 [2] copyto! at ./abstractarray.jl:753 [inlined]
 [3] copyto! at ./abstractarray.jl:745 [inlined]
 [4] Array{VariableRef,2}(::Array{GenericAffExpr{Float64,VariableRef},2}) at ./array.jl:482
 [5] convert at ./array.jl:474 [inlined]
 [6] Type at /build/julia/src/julia-1.1.1/usr/share/julia/stdlib/v1.1/LinearAlgebra/src/symmetric.jl:10 [inlined]
 [7] -(::Symmetric{VariableRef,Array{VariableRef,2}}) at /build/julia/src/julia-1.1.1/usr/share/julia/stdlib/v1.1/LinearAlgebra/src/symmetric.jl:394
 [8] top-level scope at none:0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant