rafaqz / DimensionalData.jl

Named dimensions and indexing for julia arrays and other data
https://rafaqz.github.io/DimensionalData.jl/stable/
MIT License
280 stars 41 forks source link

Use a StackSlices object for eachslice on stacks, or collect the generator #484

Closed rafaqz closed 8 months ago

rafaqz commented 1 year ago

@sethaxen I just noticed on 1.9 now we have a Slices <: AbstractArray object returned from arrays, but a generator returned for stacks - so we have to special case them a little.

Could we add a StackSlices object, or something? I'm not sure it makes sense but thought I would make a note.

rafaqz commented 1 year ago

We could actually define DimSlices so the Slices object still has dimensions. It could then also hold DimStack.

This is basically RasterSeries in Rasters.jl, it already does this with the slice method.

sethaxen commented 1 year ago

I wonder though if we might run into problems of eachslice doesn't return a Slices wrapped in an AbstractDimArray. In principle, base methods in the future might specialize on Slices, and if our generic implementations already forward that function to the underlying Slices, then we would hit these specialized methods. But if we define our own DimSlices object, then we wouldn't hit that.

Have you run into instances where eachslice for AbstractDimStack returning an iterator is inconvenient? Product is nice in that it is an iterator with a size that collects or maps to an array.

rafaqz commented 1 year ago

Ahh good point. AbstractSlices could be useful then.

The inconvenience is having to collect the generator to index, but not having to collect Slices. So the most efficient code is not generic for both arrays and stacks. Slices is also an Abstact array so you can wrap it with a DimArray.

I have some if blocks for this in Rasters.jl.

rafaqz commented 8 months ago

DimSlices is now implemented and used for AbstractDimStack in eachslice, as well as being how groupby works underneath.