AxisArrays.jl
AxisArrays.jl copied to clipboard
Inference failures on 0.7
Indexing: Error During Test
Test threw an exception of type ErrorException
Expression: @inferred(D[1, 1, 1, :]) == @inferred(D[1, 1, 1, 1:1]) == @inferred(D[1, 1, 1, [1]]) == AxisArray([10], Axis{:dim_4}(Base.OneTo(1)))
return type AxisArrays.AxisArray{Int64,1,Array{Int64,1},Tuple{AxisArrays.Axis{:dim_4,Base.OneTo{Int64}}}} does not match inferred return type AxisArrays.AxisArray{Int64,1,Array{Int64,1},_} where _
There are others but this one is the simplest (found by running AxisArrays master tests on JuliaLang master).
@vtjnash has given me a tentative "won't fix" but pointed me to some examples on how this issue was fixed in Base.
I've taken a brief look and the collector argument newaxes in _make_axes_match seems to be the problem. (And handling of such collector arguments is what likely won't be changed in the inference algorithm.) It's relatively easy to avoid using it, except for
@inline _make_axes_match(newaxes, axs::Tuple{}, nidxs::Tuple) =
_make_axes_match((newaxes..., _nextaxistype(newaxes)(Base.OneTo(1))), (), tail(nidxs))
where it is, in fact, more than just a collector argument. Is there a way to write the generation of the singleton dimensions in a back-to-front manner, so that (only) a shrinking (instead of a growing) Tuple is passed?
EDIT: Similar situation for _default_axes and its axs argument.