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

Broadcasting mismatched expressions in constraint fails #158

Closed
odow opened this issue Jun 1, 2022 · 1 comment · Fixed by #159
Closed

Broadcasting mismatched expressions in constraint fails #158

odow opened this issue Jun 1, 2022 · 1 comment · Fixed by #159

Comments

@odow
Copy link
Member

odow commented Jun 1, 2022

x-ref: https://discourse.julialang.org/t/jump-broadcasting-in-constraint-involving-expressions-throws-error/82044

julia> using JuMP

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

julia> @expression(model, x, zeros(AffExpr, 1, 4))
1×4 Matrix{AffExpr}:
 0  0  0  0

julia> @expression(model, y, zeros(AffExpr, 2, 4))
2×4 Matrix{AffExpr}:
 0  0  0  0
 0  0  0  0

julia> @constraint(model, y .>= x)  # A: OK
2×4 Matrix{ConstraintRef{Model, MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.GreaterThan{Float64}}, ScalarShape}}:
 0  0.0  0  0.0  0  0.0  0  0.0
 0  0.0  0  0.0  0  0.0  0  0.0

julia> @constraint(model, x .<= y)
ERROR: DimensionMismatch("destination axes (Base.OneTo(1), Base.OneTo(4)) are not compatible with source axes (Base.OneTo(2), Base.OneTo(4))")
Stacktrace:
 [1] throwdm(axdest::Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}, axsrc::Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}})
   @ Base.Broadcast ./broadcast.jl:1060
 [2] copyto!
   @ ./broadcast.jl:972 [inlined]
 [3] copyto!
   @ ./broadcast.jl:936 [inlined]
 [4] broadcast!(op::typeof(MutableArithmetics.sub_mul), A::Matrix{AffExpr}, args::Matrix{AffExpr})
   @ MutableArithmetics ~/.julia/packages/MutableArithmetics/VLWSd/src/broadcast.jl:117
 [5] broadcast_fallback!
   @ ~/.julia/packages/MutableArithmetics/VLWSd/src/broadcast.jl:173 [inlined]
 [6] broadcast!!(::typeof(MutableArithmetics.sub_mul), ::Matrix{AffExpr}, ::Matrix{AffExpr})
   @ MutableArithmetics ~/.julia/packages/MutableArithmetics/VLWSd/src/broadcast.jl:145
 [7] macro expansion
   @ ~/.julia/packages/MutableArithmetics/VLWSd/src/rewrite.jl:294 [inlined]
 [8] macro expansion
   @ ~/.julia/dev/JuMP/src/macros.jl:823 [inlined]
 [9] top-level scope
   @ REPL[6]:1
@odow odow added the Type: Bug label Jun 1, 2022
@odow
Copy link
Member Author

odow commented Jun 1, 2022

Problem in MutableArithmetics:

julia> MA.broadcast!!(MA.add_mul, BigInt[2 3], BigInt[2 3; 3 4])
ERROR: DimensionMismatch("destination axes (Base.OneTo(1), Base.OneTo(2)) are not compatible with source axes (Base.OneTo(2), Base.OneTo(2))")
Stacktrace:
 [1] throwdm(axdest::Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}, axsrc::Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}})
   @ Base.Broadcast ./broadcast.jl:1060
 [2] copyto!
   @ ./broadcast.jl:972 [inlined]
 [3] copyto!
   @ ./broadcast.jl:936 [inlined]
 [4] broadcast!(op::typeof(MutableArithmetics.add_mul), A::Matrix{BigInt}, args::Matrix{BigInt})
   @ MutableArithmetics ~/.julia/packages/MutableArithmetics/VLWSd/src/broadcast.jl:117
 [5] broadcast_fallback!
   @ ~/.julia/packages/MutableArithmetics/VLWSd/src/broadcast.jl:173 [inlined]
 [6] broadcast!!(::typeof(MutableArithmetics.add_mul), ::Matrix{BigInt}, ::Matrix{BigInt})
   @ MutableArithmetics ~/.julia/packages/MutableArithmetics/VLWSd/src/broadcast.jl:145
 [7] top-level scope
   @ REPL[51]:1

julia> MA.broadcast!!(MA.add_mul, BigInt[2 3; 3 4], BigInt[2 3])
2×2 Matrix{BigInt}:
 4  6
 5  7

@odow odow transferred this issue from jump-dev/JuMP.jl Jun 1, 2022
@odow odow closed this as completed in #159 Jun 6, 2022
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.

1 participant