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

reduce(hcat,v) fails for offset v with vector eltype #37628

Open
yha opened this issue Sep 17, 2020 · 2 comments · May be fixed by #37629
Open

reduce(hcat,v) fails for offset v with vector eltype #37628

yha opened this issue Sep 17, 2020 · 2 comments · May be fixed by #37629
Labels
domain:arrays [a, r, r, a, y, s]

Comments

@yha
Copy link
Contributor

yha commented Sep 17, 2020

On Julia 1.5.1:

julia> using OffsetArrays

julia> reduce(hcat, OffsetVector([1:2, 1:2],10))
ERROR: BoundsError: attempt to access 2-element Array{UnitRange{Int64},1} at index [-9]
@johnnychen94
Copy link
Sponsor Member

This is not supported yet.

See also: JuliaArrays/OffsetArrays.jl#63

@yha
Copy link
Contributor Author

yha commented Sep 17, 2020

See also: JuliaArrays/OffsetArrays.jl#63

That seems to be a different issue, as the vectors being concatenated (arguments to hcat) have offsets, whereas the current issue is about the argument to reduce having an offset.
Since reduce is defined for a general iterator, it shouldn't matter what the input axes of its second argument are, only what it returns when iterated.
EDIT: the original example was bad, because it should also fail for a different reason. I edited it now. This should clarify the problem:

julia> reduce(hcat, [1:2, 1:2])
2×2 Array{Int64,2}:
 1  1
 2  2

julia> reduce(hcat, OffsetVector([1:2, 1:2], 10)) # should return the same result
ERROR: BoundsError: attempt to access 2-element Array{UnitRange{Int64},1} at index [-9]

EDIT 2: a possible workaround is directly invoking the general method:

julia> invoke(reduce, Tuple{Any,Any}, hcat, OffsetVector([1:2,1:2],10))
2×2 Array{Int64,2}:
 1  1
 2  2

@johnnychen94 johnnychen94 linked a pull request Sep 17, 2020 that will close this issue
@brenhinkeller brenhinkeller added the domain:arrays [a, r, r, a, y, s] label Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:arrays [a, r, r, a, y, s]
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants