JuliaArrays / AxisArrays.jl

Performant arrays where each dimension can have a named axis with values
http://JuliaArrays.github.io/AxisArrays.jl/latest/
Other
200 stars 41 forks source link

AxisArrays: maximum not working on Julia 1.10 #226

Open tknopp opened 7 months ago

tknopp commented 7 months ago

We observed that AxisArrays has issues with Julia 1.10, that were not present in Julia 1.9. The code:

using AxisArrays, Unitful
B = AxisArray(randn(3,3), (:x,:y),(0.1u"mm",0.2u"mm"),(-0.1u"mm",-0.2u"mm"));
maximum(B, dims = 2)

results in an error

ERROR: DimensionError: 1.0 and 1.0 mm are not dimensionally compatible.
Stacktrace:
  [1] -(x::Quantity{Float64, NoDims, Unitful.FreeUnits{(), NoDims, nothing}}, y::Quantity{Float64, 𝐋, Unitful.FreeUnits{(mm,), 𝐋, nothing}})
    @ Unitful ~/.julia/packages/Unitful/R4J37/src/quantities.jl:137
  [2] -(x::Int64, y::Quantity{Float64, 𝐋, Unitful.FreeUnits{(mm,), 𝐋, nothing}})
    @ Base ./promotion.jl:424
  [3] Base.TwicePrecision{Quantity{Float64, 𝐋, Unitful.FreeUnits{(mm,), 𝐋, nothing}}}(x::Int64)
    @ Base ./twiceprecision.jl:207
  [4] StepRangeLen{Quantity{…}, Base.TwicePrecision{…}, Base.TwicePrecision{…}, Int64}(r::Base.OneTo{Int64})
    @ Base ./range.jl:1342
  [5] convert(::Type{StepRangeLen{Quantity{…}, Base.TwicePrecision{…}, Base.TwicePrecision{…}, Int64}}, r::Base.OneTo{Int64})
    @ Base ./range.jl:265
  [6] oftype(x::StepRangeLen{Quantity{…}, Base.TwicePrecision{…}, Base.TwicePrecision{…}, Int64}, y::Base.OneTo{Int64})
    @ Base ./essentials.jl:517
  [7] reduced_axis(ax::Axis{:y, StepRangeLen{Quantity{…}, Base.TwicePrecision{…}, Base.TwicePrecision{…}, Int64}})
    @ AxisArrays ~/.julia/packages/AxisArrays/CtyI0/src/core.jl:404
  [8] #19
    @ ~/.julia/packages/AxisArrays/CtyI0/src/core.jl:365 [inlined]
  [9] map
    @ ./tuple.jl:319 [inlined]
 [10] reduced_indices
    @ ~/.julia/packages/AxisArrays/CtyI0/src/core.jl:364 [inlined]
 [11] reduced_indices
    @ ~/.julia/packages/AxisArrays/CtyI0/src/core.jl:359 [inlined]
 [12] reduced_indices
    @ ~/.julia/packages/AxisArrays/CtyI0/src/core.jl:354 [inlined]
 [13] reducedim_init(f::Function, op::typeof(max), A::AxisMatrix{Float64, Matrix{Float64}, Tuple{Axis{…}, Axis{…}}}, region::Int64)
    @ Base ./reducedim.jl:131
 [14] _mapreduce_dim
    @ Base ./reducedim.jl:371 [inlined]
 [15] mapreduce
    @ Base ./reducedim.jl:357 [inlined]
 [16] _maximum
    @ Base ./reducedim.jl:1039 [inlined]
 [17] _maximum
    @ Base ./reducedim.jl:1038 [inlined]
 [18] #maximum#836
    @ Base ./reducedim.jl:1010 [inlined]
 [19] top-level scope
    @ REPL[6]:1
Some type information was truncated. Use `show(err)` to see complete types.
timholy commented 7 months ago

1.10 might be correct, given https://github.com/JuliaArrays/AxisArrays.jl/blob/35aa6855c698f46f8517ace3048631ab4a568c04/src/core.jl#L404. I suspect we need a more dimensionally-aware way of allocating a range of length 1. It's been a while since I've done much Unitful stuff, care to take a crack at that?

tknopp commented 7 months ago

care to take a crack at that? Thats way beyond my knowledge. My Unitful experience is mostly try and error until things work.

Independent of fixing it: Should we be worried that Julia 1.10 did change behavior? It is totally unclear what has happened here.