Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: variadic mapslices #23306

Open
iamed2 opened this issue Aug 17, 2017 · 7 comments
Open

Proposal: variadic mapslices #23306

iamed2 opened this issue Aug 17, 2017 · 7 comments
Labels
domain:arrays [a, r, r, a, y, s]

Comments

@iamed2
Copy link
Contributor

iamed2 commented Aug 17, 2017

There has been some discussion about variadic and dyadic mapslices, such as in #5140 and issues linked therein, as well as on the Julia Slack starting here.

Approaches specifying dims for both arrays have so far been unsuccessful. However, given the abundant functionality for transforming array shapes, I believe a mapslices which only specified one set of dims for all arrays could still be useful.

I propose:

Phase 1 (pre-1.0)

  1. Implement mapslices(f, dims::Tuple, As::A...) where {N,A<:(AbstractArray{T,N} where T)} which returns a single array
  2. Deprecate mapslices(f, A::AbstractArray, dims::Tuple) to mapslices(f, dims, A)

Phase 2 (optionally post-1.0)

  1. Implement an eachslice(A, dims) IteratorsMD function
  2. Reimplement mapslices in terms of eachslice

Unless there are serious concerns I can implement a PR for phase 1.

@ararslan
Copy link
Member

My only problem with this is the argument order; typically the dimensions come after the array. This would make mapslices kind of a weird special case in that regard.

@iamed2
Copy link
Contributor Author

iamed2 commented Aug 17, 2017

Does Julia have any other variadic functions which take dimensions? I think passing in a tuple of arrays would be worse but that's the only alternative I can think of, short of a monstrous generated function.

@tkelman
Copy link
Contributor

tkelman commented Aug 17, 2017

or kwargs for dimensions, which I think a few people would like us to move towards more generally if keyword performance can be fixed soon

@iamed2
Copy link
Contributor Author

iamed2 commented Aug 17, 2017

That would prevent e.g. AxisArrays from dispatching on the type of dims.

@StefanKarpinski
Copy link
Sponsor Member

StefanKarpinski commented Aug 18, 2017

Currently. Keywords based on NamedTuples might fix that though. cc @JeffBezanson – is that a possibility?

@timholy
Copy link
Sponsor Member

timholy commented Aug 19, 2017

We may be closing in on a fast inferrable variant of mapslices that we can post. Struggling a bit with the dimension API, though; my current favorite is to replace dims = [1,3] with dims = (:, *, :) (for a 3d array). The point being that * means "substitute me with an integer" and : means "this is where a colon goes."

CC @Cody-G

@timholy
Copy link
Sponsor Member

timholy commented Aug 24, 2017

There's a package JuliennedArrays which is clever both in its naming and design. It provides arbitrary slice iterators and also turns mapslices into map(f, sliceiterator). The biggest negative of the design is that it doesn't shield the parent array from side effects of f.

Cross-reference #14491.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:arrays [a, r, r, a, y, s]
Projects
None yet
Development

No branches or pull requests

6 participants