https://github.com/JuliaLang/julia
Revision 7e2ce0e5433af4fcaee9f7893f90d80c21316044 authored by Matt Bauman on 02 May 2018, 20:11:34 UTC, committed by GitHub on 02 May 2018, 20:11:34 UTC
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.
1 parent 5a062fa
History
Tip revision: 7e2ce0e5433af4fcaee9f7893f90d80c21316044 authored by Matt Bauman on 02 May 2018, 20:11:34 UTC
RFC: Deprecate implicit scalar broadcasting in setindex! (#26347)
Tip revision: 7e2ce0e
File Mode Size
.circleci
.github
base
contrib
deps
doc
etc
src
stdlib
test
ui
.freebsdci.sh -rwxr-xr-x 1.0 KB
.gitattributes -rw-r--r-- 67 bytes
.gitignore -rw-r--r-- 213 bytes
.mailmap -rw-r--r-- 9.5 KB
.travis.yml -rw-r--r-- 6.4 KB
CONTRIBUTING.md -rw-r--r-- 20.4 KB
DISTRIBUTING.md -rw-r--r-- 23.6 KB
HISTORY.md -rw-r--r-- 144.9 KB
LICENSE.md -rw-r--r-- 5.4 KB
Make.inc -rw-r--r-- 35.3 KB
Makefile -rw-r--r-- 25.0 KB
NEWS.md -rw-r--r-- 78.4 KB
README.arm.md -rw-r--r-- 5.7 KB
README.md -rw-r--r-- 29.5 KB
README.windows.md -rw-r--r-- 13.0 KB
VERSION -rw-r--r-- 10 bytes
Windows.inc -rw-r--r-- 1.5 KB
appveyor.yml -rw-r--r-- 2.2 KB

README.md

back to top