JuliaArrays / JuliaArrays/AxisArrays.jl
support permutedims and reshape
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 207
- Forks
- 41
- PR merge metrics
- No merged PRs in 30d
Description
one common thing is to using broadcasting on named vectors, for which one is put into another dimension.
permutedims(a) as well as reshape(a, 1, :) can be used to bring a column vector a to row format. reshape(a, 1, 1, :) would create a 3rd-dim vector.
It would be great if these operations preserve the indexing.
using AxisArrays
AxisArray(1:3, ["A", "B", "C"])["A"] # works and returns 1
permutedims(AxisArray(1:3, ["A", "B", "C"]))["A"]
gives an error
ArgumentError: invalid index: "A" of type String
Stacktrace:
[1] to_index(::String) at ./indices.jl:297
[2] to_index(::Base.ReshapedArray{Int64,2,AxisArray{Int64,1,UnitRange{Int64},Tuple{Axis{:row,Array{String,1}}}},Tuple{}}, ::String) at ./indices.jl:274
[3] to_indices at ./indices.jl:325 [inlined]
[4] to_indices at ./indices.jl:322 [inlined]
[5] getindex(::Base.ReshapedArray{Int64,2,AxisArray{Int64,1,UnitRange{Int64},Tuple{Axis{:row,Array{String,1}}}},Tuple{}}, ::String) at ./abstractarray.jl:980
[6] top-level scope at In[182]:1
The ultimate goal would be that the following works and preserves indexes as would be intuitive:
a = AxisArray(1:3, ["A", "B", "C"])
tuple.(a, permutedims(a))
# currently returns a plain standard Array
3×3 Array{Tuple{Int64,Int64},2}:
(1, 1) (1, 2) (1, 3)
(2, 1) (2, 2) (2, 3)
(3, 1) (3, 2) (3, 3)
and similar for using reshape instead of permutedims
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the issue's AxisArray, permutedims, reshape, and broadcast examples to reproduce the indexing errors and plain-Array result. Trace the array transformation and indexing entry points involved, then verify that permutedims, reshape, and the demonstrated tuple broadcast preserve axis indexes without breaking existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100