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

Enable reduce_indices over AbstractArrays #194

Closed
wants to merge 8 commits into from

Conversation

glennmoy
Copy link

@glennmoy glennmoy commented Feb 24, 2021

Somewhat closes #193 as it only accepts integer dims.

julia> A = AxisArray(collect(reshape(1:15,3,5)), :y, :x)
2-dimensional AxisArray{Int64,2,...} with axes:
    :y, Base.OneTo(3)
    :x, Base.OneTo(5)
And data, a 3×5 Array{Int64,2}:
 1  4  7  10  13
 2  5  8  11  14
 3  6  9  12  15

julia> mapslices(sum, A; dims=1)
1×5 Array{Int64,2}:
 6  15  24  33  42

I'm not fully sure what's needed to enable Axis dims, perhaps overloading Base.mapslices directly since it seems to assume the dims args are always integers (used for indexing).

julia> mapslices(sum, A; dims=Axis{:y})
ERROR: ArgumentError: invalid index: Axis{:y,T} where T of type UnionAll
Stacktrace:
 [1] to_index(::Type{T} where T) at ./indices.jl:297
 [2] to_index(::Array{Any,1}, ::Type{T} where T) at ./indices.jl:274
 [3] to_indices at ./indices.jl:325 [inlined]
 [4] to_indices at ./indices.jl:322 [inlined]
 [5] setindex!(::Array{Any,1}, ::Base.Slice{Base.OneTo{Int64}}, ::Type{T} where T) at ./abstractarray.jl:1153
 [6] mapslices(::typeof(sum), ::AxisArray{Int64,2,Array{Int64,2},Tuple{Axis{:y,Base.OneTo{Int64}},Axis{:x,Base.OneTo{Int64}}}}; dims::Type{T} where T) at ./abstractarray.jl:2078
 [7] top-level scope at REPL[203]:1

Copy link
Contributor

@rofinn rofinn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think you'll need to overload mapslices directly.

Manifest.toml Outdated Show resolved Hide resolved
@glennmoy
Copy link
Author

glennmoy commented Feb 25, 2021

Yeah, I think you'll need to overload mapslices directly.

Closing in favour of #195

@glennmoy glennmoy closed this Feb 25, 2021
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 this pull request may close these issues.

mapslices errors for AxisArrays
2 participants