Skip to content

Commit df4a58d

Browse files
committed
default dotview to getindex, using view only for AbstractArray
1 parent 46ffc87 commit df4a58d

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

base/broadcast.jl

+7-12
Original file line numberDiff line numberDiff line change
@@ -443,25 +443,20 @@ end
443443
############################################################
444444

445445
# x[...] .= f.(y...) ---> broadcast!(f, dotview(x, ...), y...).
446-
# The dotview function defaults to view, but we override it in
446+
# The dotview function defaults to getindex, but we override it in
447447
# a few cases to get the expected in-place behavior without affecting
448448
# explicit calls to view. (All of this can go away if slices
449449
# are changed to generate views by default.)
450450

451-
dotview(args...) = view(args...)
451+
dotview(args...) = getindex(args...)
452+
dotview(A::AbstractArray, args...) = view(A, args...)
452453
# avoid splatting penalty in common cases:
453454
for nargs = 0:5
454455
args = Symbol[Symbol("x",i) for i = 1:nargs]
455-
eval(Expr(:(=), Expr(:call, :dotview, args...), Expr(:call, :view, args...)))
456+
eval(Expr(:(=), Expr(:call, :dotview, args...),
457+
Expr(:call, :getindex, args...)))
458+
eval(Expr(:(=), Expr(:call, :dotview, :(A::AbstractArray), args...),
459+
Expr(:call, :view, :A, args...)))
456460
end
457461

458-
# for a[i...] .= ... where a is an array-of-arrays, just pass a[i...] directly
459-
# to broadcast!
460-
dotview{T<:AbstractArray,N,I<:Integer}(a::AbstractArray{T,N}, i::Vararg{I,N}) =
461-
a[i...]
462-
463-
# dict[k] .= ... should work if dict[k] is an array
464-
dotview(a::Associative, k) = a[k]
465-
dotview(a::Associative, k1, k2, ks...) = a[tuple(k1,k2,ks...)]
466-
467462
end # module

doc/manual/functions.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ calls do not allocate new arrays over and over again for the results
660660
except that, as above, the ``broadcast!`` loop is fused with any nested
661661
"dot" calls. For example, ``X .= sin.(Y)`` is equivalent to
662662
``broadcast!(sin, X, Y)``, overwriting ``X`` with ``sin.(Y)`` in-place.
663-
If the left-hand side is a ``getindex`` expression, e.g.
663+
If the left-hand side is an array-indexing expression, e.g.
664664
``X[2:end] .= sin.(Y)``, then it translates to ``broadcast!`` on a ``view``,
665665
e.g. ``broadcast!(sin, view(X, 2:endof(X)), Y)``, so that the left-hand
666666
side is updated in-place.

0 commit comments

Comments
 (0)