RFC: Mapslices for nonscalar arguments #5177
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.
Because of #5140 I took a detailed look at mapslices and how it arranges the results of
f(s)
, wheres
denotes the slices along dimensionsslicedims
of arrayA
, into a new arrayR = [f(s)]
.I should just explain it here for anyone interested.
As stated in the documentation, the
f(s)
are concatenated along the sliced dimensions.The new array inherits the number of dimensions of
A
, and the length of the dimensions not sliced over stays the same. The length of then
first dimensions inslicedims
get modified to accomodate ther
's.In fact, for the result
R
has the shapesizeR
withFor example if
f
is scalarand the following nonscalar
f
centers the columns versus the rows.The implementation doesn't handle A which is 3-dimensional,
because in line https://github.com/JuliaLang/julia/blob/master/base/abstractarray.jl#L1628
the left and right side differ by dimensions of length 1
A possible fix is to assign elementwise if ndims(r) > 1.