Description
openedon Sep 12, 2018
After some discussion on discourse it was proposed to "feature request" a version of mapslices
in Julia Base that does not allocate slices. Naively I would think the behavior and syntax should be identical to mapslices
except that it iterates views rather than slices of the original array (mapviews
is a tentative name). I think it'd be useful for all cases where one wants to apply mapslices
with a function with no side effects (or that doesn't mutate the original array) and avoid the extra allocations. A typical use case is for example summing with some filtering condition along some dimension:
mapviews(v -> sum(Iterators.filter(!isnan, v)), M, dims=2)
for which I don't think there's an easy efficient solution in Base Julia right now.
It was pointed out that similar ideas have been implemented in the package JuliennedArrays and there was some discussion of moving some of that to Base, see this comment.