Skip to content

Commit d4a0e27

Browse files
authored
Merge pull request #23939 from JuliaLang/teh/extensible_broadcast
Rework the broadcast API and document it
2 parents 3c1e9d0 + 776139b commit d4a0e27

File tree

11 files changed

+885
-340
lines changed

11 files changed

+885
-340
lines changed

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ This section lists changes that do not have deprecation warnings.
290290
Its return value has been removed. Use the `process_running` function
291291
to determine if a process has already exited.
292292

293+
* Broadcasting has been redesigned with an extensible public interface. The new API is
294+
documented at https://docs.julialang.org/en/latest/manual/interfaces/#Interfaces-1.
295+
`AbstractArray` types that specialized broadcasting using the old internal API will
296+
need to switch to the new API. ([#20740])
297+
293298
Library improvements
294299
--------------------
295300

@@ -1490,6 +1495,7 @@ Command-line option changes
14901495
[#20549]: https://github.com/JuliaLang/julia/issues/20549
14911496
[#20575]: https://github.com/JuliaLang/julia/issues/20575
14921497
[#20609]: https://github.com/JuliaLang/julia/issues/20609
1498+
[#20740]: https://github.com/JuliaLang/julia/issues/20740
14931499
[#20816]: https://github.com/JuliaLang/julia/issues/20816
14941500
[#20889]: https://github.com/JuliaLang/julia/issues/20889
14951501
[#20912]: https://github.com/JuliaLang/julia/issues/20912

base/broadcast.jl

Lines changed: 459 additions & 190 deletions
Large diffs are not rendered by default.

base/cartesian.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ end
4141

4242
function _nloops(N::Int, itersym::Symbol, arraysym::Symbol, args::Expr...)
4343
@gensym d
44-
_nloops(N, itersym, :($d->indices($arraysym, $d)), args...)
44+
_nloops(N, itersym, :($d->Base.indices($arraysym, $d)), args...)
4545
end
4646

4747
function _nloops(N::Int, itersym::Symbol, rangeexpr::Expr, args::Expr...)

base/deprecated.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,17 @@ end
21192119
finalizer(f::Ptr{Void}, o::Ptr{Void}) = invoke(finalizer, Tuple{Ptr{Void}, Any}, f, o)
21202120
finalizer(f::Ptr{Void}, o::Function) = invoke(finalizer, Tuple{Ptr{Void}, Any}, f, o)
21212121

2122+
# Broadcast extension API (#23939)
2123+
@eval Broadcast begin
2124+
Base.@deprecate_binding containertype combine_styles false
2125+
Base.@deprecate_binding _containertype BroadcastStyle false
2126+
Base.@deprecate_binding promote_containertype BroadcastStyle false
2127+
Base.@deprecate_binding broadcast_c! broadcast! false ", broadcast_c!(f, ::Type, ::Type, C, As...) should become broadcast!(f, C, As...) (see the manual chapter Interfaces)"
2128+
Base.@deprecate_binding broadcast_c broadcast false ", `broadcast_c(f, ::Type{C}, As...)` should become `broadcast(f, C, nothing, nothing, As...))` (see the manual chapter Interfaces)"
2129+
Base.@deprecate_binding broadcast_t broadcast false ", broadcast_t(f, ::Type{ElType}, shape, iter, As...)` should become `broadcast(f, Broadcast.DefaultArrayStyle{N}(), ElType, shape, As...))` (see the manual chapter Interfaces)"
2130+
end
2131+
2132+
21222133
# END 0.7 deprecations
21232134

21242135
# BEGIN 1.0 deprecations

base/exports.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export
1818
Threads,
1919
Iterators,
2020
Distributed,
21+
Broadcast,
2122

2223
# Types
2324
AbstractChannel,

base/linalg/uniformscaling.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ for (t1, t2) in ((:UnitUpperTriangular, :UpperTriangular),
9999
($op)(UL::$t2, J::UniformScaling) = ($t2)(($op)(UL.data, J))
100100

101101
function ($op)(UL::$t1, J::UniformScaling)
102-
ULnew = copy_oftype(UL.data, Base.Broadcast._broadcast_eltype($op, UL, J))
102+
ULnew = copy_oftype(UL.data, Broadcast.combine_eltypes($op, UL, J))
103103
for i = 1:size(ULnew, 1)
104104
ULnew[i,i] = ($op)(1, J.λ)
105105
end
@@ -110,7 +110,7 @@ for (t1, t2) in ((:UnitUpperTriangular, :UpperTriangular),
110110
end
111111

112112
function (-)(J::UniformScaling, UL::Union{UpperTriangular,UnitUpperTriangular})
113-
ULnew = similar(parent(UL), Base.Broadcast._broadcast_eltype(-, J, UL))
113+
ULnew = similar(parent(UL), Broadcast.combine_eltypes(-, J, UL))
114114
n = size(ULnew, 1)
115115
ULold = UL.data
116116
for j = 1:n
@@ -126,7 +126,7 @@ function (-)(J::UniformScaling, UL::Union{UpperTriangular,UnitUpperTriangular})
126126
return UpperTriangular(ULnew)
127127
end
128128
function (-)(J::UniformScaling, UL::Union{LowerTriangular,UnitLowerTriangular})
129-
ULnew = similar(parent(UL), Base.Broadcast._broadcast_eltype(-, J, UL))
129+
ULnew = similar(parent(UL), Broadcast.combine_eltypes(-, J, UL))
130130
n = size(ULnew, 1)
131131
ULold = UL.data
132132
for j = 1:n
@@ -144,7 +144,7 @@ end
144144

145145
function (+)(A::AbstractMatrix, J::UniformScaling)
146146
n = checksquare(A)
147-
B = similar(A, Base.Broadcast._broadcast_eltype(+, A, J))
147+
B = similar(A, Broadcast.combine_eltypes(+, A, J))
148148
copy!(B,A)
149149
@inbounds for i = 1:n
150150
B[i,i] += J.λ
@@ -154,7 +154,7 @@ end
154154

155155
function (-)(A::AbstractMatrix, J::UniformScaling)
156156
n = checksquare(A)
157-
B = similar(A, Base.Broadcast._broadcast_eltype(-, A, J))
157+
B = similar(A, Broadcast.combine_eltypes(-, A, J))
158158
copy!(B, A)
159159
@inbounds for i = 1:n
160160
B[i,i] -= J.λ
@@ -163,7 +163,7 @@ function (-)(A::AbstractMatrix, J::UniformScaling)
163163
end
164164
function (-)(J::UniformScaling, A::AbstractMatrix)
165165
n = checksquare(A)
166-
B = convert(AbstractMatrix{Base.Broadcast._broadcast_eltype(-, J, A)}, -A)
166+
B = convert(AbstractMatrix{Broadcast.combine_eltypes(-, J, A)}, -A)
167167
@inbounds for j = 1:n
168168
B[j,j] += J.λ
169169
end

0 commit comments

Comments
 (0)