EachRow/EachCol types (see #32310)
Obviously still needs JuliaLang/julia#32310 to be merged, but this is just to show we can monkey-patch the aliases to support older versions of Julia.
cc: @nalimilan
Could we also define Compat.AbstractSlices as part of this to "backport" Base.AbstractSlices (see https://github.com/JuliaLang/julia/pull/32310#issuecomment-1124631069)? This will allow packages like JuliennedArrays.jl, ArraysOfArrays.jl to extend that type without depending on non-LTS Julia versions.
We could also add
const EachSlice{A,I} = Base.Generator{I,<:(typeof(eachslice(ones(Int32,2,2), dims = 1).f).name.wrapper){A}}
Base.parent(x::EachSlice) = x.f.A
to add support for "legacy" eachslice, in addition to "legacy" eachrow and eachcol. Seems to work fine:
julia> parent(eachslice(rand(3,4,5,6), dims = 3))
3×4×5×6 Array{Float64, 4}:
#...
With https://github.com/JuliaLang/julia/pull/32310 finally merged, this could now be picked up again if there is still interest.
I think we should definitely do this. Ideally with AbstractSlices and EachSlice as well?
Adding AbstractSlices in the spirit of this PR isn't possible AFAICT as on Julia < 1.9 eachrow and eachcol return Generator objects, which cannot be made to inherit from AbstractSlices. What can be done is adding unexported eachrow, eachcol and eachslice functions that would be copies of what has been added at https://github.com/JuliaLang/julia/pull/32310, i.e returning EachSlice <: AbstractSlices objects.
Probably the best would be to implement both approaches. The former is useful for packages that want to use a special method when users call f(eachcol(x)) on any Julia version. The latter is useful if they want to dispatch on AbstractSlices, and/or call Compat.eachslice themselves.
Adding AbstractSlices in the spirit of this PR isn't possible AFAICT
Ah - I don't want to add it to have eachrow and eachcol as subtypes - that's not possible, I agree. But I think it's important to add it in Compat so that packages like ArraysOfArrays.jl and JuliennedArrays.jl can make their types subtypes of AbstractSlices while still supporting Julia LTS. And so we can do something like
@static if isdefined(Base, :Slices)
const SlicedArrayLike = AbstractSlices
else
const SlicedArrayLike = Union{EachRow,EachCol,EachSlice,AbstractSlices}
end
in ArrayInterfaceCore (prototyping this here). That will then allow code that can take advantage of slices array to dispatch on SlicedArrayLike, which will cover the legacy eachrow and eachcol, as well as the Julia v1.9 Slices and subtypes of AbstractSlices.
For that to work, we need an AbstractSlices that's available from Julia v1.6 on, via Compat.
1.9alpha is out. What's the plan here?
Bump - is there support for adding this to Compat?