JuliaArrays / JuliaArrays/AxisArrays.jl
Function 'atvalue' cannot handle negative ranges
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 207
- Forks
- 41
- PR merge metrics
- No merged PRs in 30d
Description
Dear all,
I recently noticed an inconvenient issue with the atvalue function, namely that it does not work for negatively iterated ranges/units. Here's an example:
using AxisArrays
using Unitful: mm
AA = AxisArray(reshape(1:11^2, (11, 11)),
Axis{:x}(-5mm:1mm:5mm), # positive
Axis{:y}(5mm:-1mm:-5mm)) # negative
# positive direction
println(AA[x = atvalue(1mm)])
# negative direction
println(AA[y = atvalue(1mm)])
While the instantiation of the AxisArray and the first example in the positive direction (x-axis) work perfectly fine, the latter in the negative direction (y-axis) fails and prints the following error message:
ERROR: LoadError: BoundsError: attempt to access 11-element StepRange{Unitful.Quantity{Int64, 𝐋, Unitful.FreeUnits{(mm,), 𝐋, nothing}}, Unitful.Quantity{Int64, 𝐋, Unitful.FreeUnits{(mm,), 𝐋, nothing}}} at index [TolValue(1 mm, tol=0 mm)]
Stacktrace:
[1] axisindexes(#unused#::Type{AxisArrays.Dimensional}, ax::StepRange{Unitful.Quantity{Int64, 𝐋, Unitful.FreeUnits{(mm,), 𝐋, nothing}}, Unitful.Quantity{Int64, 𝐋, Unitful.FreeUnits{(mm,), 𝐋, nothing}}}, idx::AxisArrays.TolValue{Unitful.Quantity{Int64, 𝐋, Unitful.FreeUnits{(mm,), 𝐋, nothing}}})
@ AxisArrays ~/.julia/packages/AxisArrays/v7vf4/src/indexing.jl:234
[2] axisindexes
@ ~/.julia/packages/AxisArrays/v7vf4/src/indexing.jl:199 [inlined]
[3] macro expansion
@ ~/.julia/packages/AxisArrays/v7vf4/src/indexing.jl:394 [inlined]
[4] _to_index
@ ~/.julia/packages/AxisArrays/v7vf4/src/indexing.jl:349 [inlined]
[5] to_index
@ ~/.julia/packages/AxisArrays/v7vf4/src/indexing.jl:347 [inlined]
[6] macro expansion
@ ~/.julia/packages/AxisArrays/v7vf4/src/indexing.jl:153 [inlined]
[7] to_index
@ ~/.julia/packages/AxisArrays/v7vf4/src/indexing.jl:141 [inlined]
[8] getindex
@ ~/.julia/packages/AxisArrays/v7vf4/src/indexing.jl:123 [inlined]
[9] #getindex#38
@ ~/.julia/packages/AxisArrays/v7vf4/src/indexing.jl:164 [inlined]
[10] top-level scope
I wonder if there is a simple solution to that problem (am I doing something wrong?) or if this undesired behavior needs to be fixed inside of the package.
Kindly,
EminentCoder
PS: Unitful does not contribute to the error, the problem remains without the units as well.
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 in src/indexing.jl around axisindexes, especially the logic reported at line 234, and run the provided reproducer with both ordinary ranges and Unitful ranges. The issue is done when atvalue works for descending ranges while the existing ascending-range behavior continues to pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100