Skip to content

Equivalent of mapslices with views? #29146

Closed

Description

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions