I’m trying to understand whether there is a non-allocating equivalent of mapslices. I often end up needing to reduce sliced views, for example:
mapslices(sum, m, dims = n)
And I would like to figure out a way that does not allocate all the intermediate slices. This is somewhat trivial for sum as one can do sum(m, dims = ...) directly, but there are many cases where mapslices is needed. For example, if we want to sum and skip missing values, I think one would do:
mapslices(sum∘skipmissing, m, dims = n)
But again, I think this allocates much more than it would be necessary for this usecase.
In the case where the reduction is pairwise, for example:
mapslices(v -> reduce(+, v), m, dims = n)
one can obviate this with reduce(+, m, dims = n), but that again doesn’t work as soon as we need to filter, for example:
mapslices(v -> reduce(+, skipmissing(v)), m, dims = n)
Is there some function like mapslices that obviates this problems?