-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Description
The following produces an error:
julia> accumulate((acc, x) -> acc+x[1], 0, [(1,2), (3,4), (5,6)])
ERROR: MethodError: no method matching rcum_promote_type(::##1#2, ::Type{Int64}, ::Type{Tuple{Int64,Int64}})
Closest candidates are:
rcum_promote_type(::Any, ::Type{T<:Number}) where T<:Number at multidimensional.jl:585
rcum_promote_type(::Any, ::Type{T}) where T at multidimensional.jl:586
rcum_promote_type(::Any, ::Type{T}, !Matched::Type{S<:Number}) where {T, S<:Number} at multidimensional.jl:584
...
Stacktrace:
[1] accumulate at ./multidimensional.jl:760 [inlined] (repeats 2 times)
[2] macro expansion at ./REPL.jl:97 [inlined]
[3] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73
The same happens for
accumulate((acc, x) -> x, "", ['a', 'b', 'c'])
It seems that accumulate(op, v0, x)
tries to guess the type of the output array based on both the type of the initial value and the type of the input array, while it should only consider the first.
Changing this line:
julia/base/multidimensional.jl
Line 1105 in 4440b0f
T = rcum_promote_type(op, typeof(v0), eltype(x)) |
to:
T = rcum_promote_type(op, typeof(v0))
seems to fix the issue, but I am not sure whether there is a reason to prefer the original version.
Metadata
Metadata
Assignees
Labels
No labels