Repository navigation
Labels
bugSomething isn't working
Description
Despite this comment:
https://github.com/JuliaOpt/MutableArithmetics.jl/blob/9b6f9a0206fd3f423122749077b4dd9fed2532ba/src/rewrite.jl#L48
julia> @rewrite(1 .+ sum(1 for i in 1:0) * 1^2)
ERROR: ArgumentError: reducing over an empty collection is not allowed
Stacktrace:
[1] _empty_reduce_error() at ./reduce.jl:216
[2] mapreduce_empty_iter(::Function, ::Function, ::Base.Generator{UnitRange{Int64},getfield(Main, Symbol("##31#32"))}, ::Base.EltypeUnknown) at ./reduce.jl:261
[3] mapfoldl_impl at ./reduce.jl:57 [inlined]
[4] #mapfoldl#187 at ./reduce.jl:72 [inlined]
[5] mapfoldl at ./reduce.jl:72 [inlined]
[6] #mapreduce#191 at ./reduce.jl:205 [inlined]
[7] mapreduce at ./reduce.jl:205 [inlined]
[8] sum at ./reduce.jl:399 [inlined]
[9] sum(::Base.Generator{UnitRange{Int64},getfield(Main, Symbol("##31#32"))}) at ./reduce.jl:416
[10] top-level scope at /Users/oscar/.julia/packages/MutableArithmetics/Oy9aO/src/rewrite.jl:224There is also this nasty bug:
julia> @rewrite(sum(1 for i in 1:0) .- 0)
ERROR: MethodError: no method matching -(::MutableArithmetics.Zero, ::Int64)
Closest candidates are:
-(::Complex{Bool}, ::Real) at complex.jl:298
-(::Missing, ::Number) at missing.jl:97
-(::Base.CoreLogging.LogLevel, ::Integer) at logging.jl:107
...
Stacktrace:
[1] sub_mul(::MutableArithmetics.Zero, ::Int64) at /Users/oscar/.julia/packages/MutableArithmetics/Oy9aO/src/MutableArithmetics.jl:31
[2] _broadcast_getindex_evalf at ./broadcast.jl:578 [inlined]
[3] _broadcast_getindex at ./broadcast.jl:551 [inlined]
[4] getindex at ./broadcast.jl:511 [inlined]
[5] copy at ./broadcast.jl:763 [inlined]
[6] materialize at ./broadcast.jl:753 [inlined]
[7] broadcast(::typeof(MutableArithmetics.sub_mul), ::MutableArithmetics.Zero, ::Int64) at ./broadcast.jl:707
[8] broadcast_fallback!(::MutableArithmetics.NotMutable, ::Function, ::MutableArithmetics.Zero, ::Int64) at /Users/oscar/.julia/packages/MutableArithmetics/Oy9aO/src/broadcast.jl:85
[9] broadcast!(::Function, ::MutableArithmetics.Zero, ::Int64) at /Users/oscar/.julia/packages/MutableArithmetics/Oy9aO/src/broadcast.jl:77
[10] top-level scope at /Users/oscar/.julia/packages/MutableArithmetics/Oy9aO/src/rewrite.jl:224
julia> @rewrite(0 .- sum(1 for i in 1:0))
0Distilled from: jump-dev/JuMP.jl#2195
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
odow commentedon Apr 3, 2020
Not actually fixed by #45
odow commentedon Jan 14, 2021
I took a look into this.
@rewrite(1 .+ sum(1 for i in 1:0) * 1^2)is still an issue. But it's not an easy fix, so I'm in favor of closing as "won't-fix".Julia 1.6 introduces an
initkeyword that can be used as the default when the collection is empty. We should encourage this instead.Base Julia is also inconsistent in when it throws an error:
blegat commentedon May 2, 2021
What would be the fix ? Consistently throwing the error or consistenstly returning
MA.Zero()? It seems thatMA.Zero()would always be a correct answer but it might cause type unstability.odow commentedon May 2, 2021
Returning
MA.Zeroseems like the way to go. Or we should decide that throwing the reducing not allowed error is okay, and document that in JuMP.