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

RFC: Deprecate implicit scalar broadcasting in setindex! #26347

Merged
merged 2 commits into from May 2, 2018

Commits on Apr 26, 2018

  1. Deprecate implicit scalar broadcasting in setindex!

    The current `setindex!` function (the `A[i] = b` syntax) does three very different operations:
    * Given an index `i` that refers to only one location (scalar indexing), `A[i] = b` modifies `A` in that location to hold `b`.
    * Given an index `I` that refers to more than one location (non-scalar indexing), `A[I] = b` can mean one of two things:
        * If `b` is an AbstractArray (multi-value), assign the values it contains to those locations `I` in `A`. That is, essentially, `[A[i] = bᵢ for (i, bᵢ) in zip(I, b)]`.
        * If `b` is not an AbstractArray (scalar-value), then broadcast its value to every location selected by `I` in `A`.
    
    These two different behaviors in the non-scalar indexing case basically make using this function in a generic way impossible.  If you want to _always_ set the value `b` to many indices of `A`, you _cannot_ use this syntax because `b` might happen to be an array in some cases, radically changing the meaning of the expression.  You need to manually iterate over the indices, using scalar setindex methods.  But we now also have the new `broadcast!` syntax, `A[I] .= B`, which uses the usual broadcasting semantics to determine how `B` should fill into the values of `A`.
    
    This PR deprecates the implicit broadcasting of scalar values in non-scalar indexing in favor of an explicit `.=` broadcast syntax, leaving multi-value non-scalar indexing intact.  This is the _exact opposite_ of PR #24368.
    mbauman committed Apr 26, 2018
    Configuration menu
    Copy the full SHA
    8ecfdb4 View commit details
    Browse the repository at this point in the history

Commits on Apr 27, 2018

  1. Add NEWS.md

    mbauman committed Apr 27, 2018
    Configuration menu
    Copy the full SHA
    4a9c1ff View commit details
    Browse the repository at this point in the history