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

Function 'atvalue' cannot handle negative ranges #215

Open
EminentCoder opened this issue Feb 14, 2023 · 0 comments
Open

Function 'atvalue' cannot handle negative ranges #215

EminentCoder opened this issue Feb 14, 2023 · 0 comments

Comments

@EminentCoder
Copy link

EminentCoder commented Feb 14, 2023

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.

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

No branches or pull requests

1 participant