RFC: Dyadic mapslices with broadcasting #13317
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
An open issue is to make
mapslices
accept two inputs and allow broadcasting. See #10928, #5140. There are aspects of the interface of mapslices which make straight generalization difficult. The result of the provided function applied to the slices is arranged along the unsliced dimensions, so for exampleFurther the result of
f
has to fit dimensionally into the slices, so that the resulting array has the same number of dimensions as the original. This behaviour does not generalize well to two arguments (what should the shape ofmapslices(f, A, Adims, B, Bdims)
be?).The function
mapranked(f, A, r, B, s)
here follows APL and J and appliesf
only to the leading subarrays of given rank: For example, if r is 2 and A is 4-dimensional and s is 1 and B is 3-dimensional, then f is called on (A[:,:,i,j], B[:, i,j]) for all i and j. The results are concatenated along the remaining dimensions. The function broadcasts the arguments to a common size by expanding singleton dimensions. This more restrictive API makes the function conceptually much simpler. While it is meant to generalizemapslices
to the dyadic case, to prevent confusion it should perhaps have a different name. Here I went withmapranked
following the notion of changing the rank of a function/verb in APL (other suggestions?).Some usage:
Ping @andreasnoack