rafaqz / DimensionalData.jl

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

`mapslices` on `DimStack` #749

Open haakon-e opened 1 week ago

haakon-e commented 1 week ago

It would be cool if you could do something like

# Setup
x, y = X(1:3), Y(10:13)
P = ones(x,y, name="P")
sp = ones(x, name="sp")
stack = DimStack(P,sp)

# new code
mapslices(stack, dims=X) do x
    # some calculation

    # assign output to each layer with some reasonable syntax
    (; sp = out1, P = out2)
end

the motivation for this is that I have some expensive function that operates on slices on some data I have, but the function outputs both a vector and a scalar (think eigenvalue/eigenvector pair), and it would be neat to apply a map-like method to assign the output to each layer.

haakon-e commented 1 week ago

err, maybe I can achieve this with eachslice, which I see is supported.

rafaqz commented 1 week ago

We could support mapslices too if you want to add it. But I think each slide is favoured these days?

felixcremer commented 1 day ago

You might want to have a look at the mapCube function YAXArrays where you can define inputs and outputs qiite freely. This should work on AbstractDimArrays and could be made working on DimStacks.