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

Update arrays.md for element-wise assignment #29167

Merged
merged 1 commit into from Nov 19, 2018
Merged

Update arrays.md for element-wise assignment #29167

merged 1 commit into from Nov 19, 2018

Conversation

ghost
Copy link

@ghost ghost commented Sep 13, 2018

When assigning a scalar to multiple array values, the .= operator is required. The Assignment section is updated to reflect this.

When assigning a scalar to multiple array values, the `.=` operator is required. The **Assignment** section is updated to reflect this.
@fredrikekre fredrikekre requested a review from mbauman September 13, 2018 13:09
@fredrikekre fredrikekre added the docs This change adds or pertains to documentation label Sep 13, 2018
@mbauman
Copy link
Member

mbauman commented Sep 13, 2018

Oh, wonderful catch, thank you! Yes, this needs to be changed. The tricky thing about describing this behavior in this section is that it depends upon the broadcasting shape of both sides of the .=, but I think what you have here is concise and accurate enough.

@@ -424,8 +424,12 @@ subsections, and arrays of booleans to select elements at their `true` indices.

If `X` is an array, it must have the same number of elements as the product of the lengths of
Copy link
Member

@mbauman mbauman Sep 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also invert the If-clause here and tighten up this description while we're at it. Maybe something like:

If any index I_k selects more than one location, then the right hand side X must be an array with the same shape* as the result of indexing A[I_1, I_2, ..., I_n] or a vector with the same number of elements.

This could lead to a slightly different wording than what you proposed:

The dotted assignment operator .= can be used to broadcast the assignment of fewer elements in X across a compatible shape selected by the indices [I_1, I_2, …, I_n].

What do you think? Edit: I actually think what you first wrote about broadcasting might be better.

* That's still not quite true as we also allow adding or removing singleton dimensions to make the shapes match, but this is definitely more accurate than what was there before and I find that extra condition quite confusing to explain.

@KristofferC KristofferC mentioned this pull request Sep 17, 2018
@KristofferC KristofferC mentioned this pull request Nov 12, 2018
61 tasks
@KristofferC
Copy link
Member

Can we merge this as an incremental improvement? @mbauman

@mbauman
Copy link
Member

mbauman commented Nov 19, 2018

Definitely an improvement! Thanks @anders-dc.

@mbauman mbauman merged commit 1952bec into JuliaLang:master Nov 19, 2018
mbauman added a commit that referenced this pull request Nov 19, 2018
More carefully explain the scalar case, and lead with the shape of the indices to drive the discussion
@ghost ghost deleted the patch-1 branch November 20, 2018 10:02
mbauman added a commit that referenced this pull request Dec 6, 2018
* Followup to #29167.

More carefully explain the scalar case, and lead with the shape of the indices to drive the discussion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants