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

Reduction over OffsetArray error #107

Closed
GregPlowman opened this issue Mar 27, 2020 · 0 comments · Fixed by #108
Closed

Reduction over OffsetArray error #107

GregPlowman opened this issue Mar 27, 2020 · 0 comments · Fixed by #108

Comments

@GregPlowman
Copy link
Contributor

As discussed on Discourse:
https://discourse.julialang.org/t/reducing-sum-of-offsetarray/36571

using OffsetArrays
A = rand(3,3)
B = OffsetArray(A, -1:1, 5:7)
sum(A, dims=1)   # OK
sum(B, dims=1)   # errors

Here’s the output:

Julia-1.4.0> sum(B, dims=1)
ERROR: ArgumentError: No method is implemented for reducing index range of type typeof(i).
Please implement reduced_index for this index type or report this as an issue.

Stacktrace:
 [1] reduced_index(::OffsetArrays.IdOffsetRange{Int64,Base.OneTo{Int64}}) at .\reducedim.jl:8
 [2] reduced_indices(::Tuple{OffsetArrays.IdOffsetRange{Int64,Base.OneTo{Int64}},OffsetArrays.IdOffsetRange{Int64,Base.OneTo{Int64}}}, ::Int64) at .\reducedim.jl:23
 [3] reduced_indices at .\reducedim.jl:15 [inlined]
 [4] reducedim_initarray(::OffsetArray{Float64,2,Array{Float64,2}}, ::Int64, ::Float64, ::Type{Float64}) at .\reducedim.jl:92
 [5] reducedim_initarray at .\reducedim.jl:93 [inlined]
 [6] reducedim_init at .\reducedim.jl:172 [inlined]
 [7] _mapreduce_dim at .\reducedim.jl:317 [inlined]
 [8] #mapreduce#580 at .\reducedim.jl:307 [inlined]
 [9] _sum at .\reducedim.jl:679 [inlined]
 [10] _sum at .\reducedim.jl:678 [inlined]
 [11] #sum#583 at .\reducedim.jl:652 [inlined]
 [12] top-level scope at REPL[5]:1

Suggested fix by @AndiMD

Base.reduced_index(i::OffsetArrays.IdOffsetRange) = oftype(i, first(i):first(i))
timholy added a commit that referenced this issue Mar 29, 2020
timholy added a commit that referenced this issue Mar 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant