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

Rework the broadcast API and document it #23939

Merged
merged 3 commits into from
Nov 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ This section lists changes that do not have deprecation warnings.
Its return value has been removed. Use the `process_running` function
to determine if a process has already exited.

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

Library improvements
--------------------

Expand Down Expand Up @@ -1490,6 +1495,7 @@ Command-line option changes
[#20549]: https://github.com/JuliaLang/julia/issues/20549
[#20575]: https://github.com/JuliaLang/julia/issues/20575
[#20609]: https://github.com/JuliaLang/julia/issues/20609
[#20740]: https://github.com/JuliaLang/julia/issues/20740
[#20816]: https://github.com/JuliaLang/julia/issues/20816
[#20889]: https://github.com/JuliaLang/julia/issues/20889
[#20912]: https://github.com/JuliaLang/julia/issues/20912
Expand Down
649 changes: 459 additions & 190 deletions base/broadcast.jl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion base/cartesian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ end

function _nloops(N::Int, itersym::Symbol, arraysym::Symbol, args::Expr...)
@gensym d
_nloops(N, itersym, :($d->indices($arraysym, $d)), args...)
_nloops(N, itersym, :($d->Base.indices($arraysym, $d)), args...)
end

function _nloops(N::Int, itersym::Symbol, rangeexpr::Expr, args::Expr...)
Expand Down
11 changes: 11 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,17 @@ end
finalizer(f::Ptr{Void}, o::Ptr{Void}) = invoke(finalizer, Tuple{Ptr{Void}, Any}, f, o)
finalizer(f::Ptr{Void}, o::Function) = invoke(finalizer, Tuple{Ptr{Void}, Any}, f, o)

# Broadcast extension API (#23939)
@eval Broadcast begin
Base.@deprecate_binding containertype combine_styles false
Base.@deprecate_binding _containertype BroadcastStyle false
Base.@deprecate_binding promote_containertype BroadcastStyle false
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)"
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)"
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)"
end


# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export
Threads,
Iterators,
Distributed,
Broadcast,

# Types
AbstractChannel,
Expand Down
12 changes: 6 additions & 6 deletions base/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ for (t1, t2) in ((:UnitUpperTriangular, :UpperTriangular),
($op)(UL::$t2, J::UniformScaling) = ($t2)(($op)(UL.data, J))

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

function (-)(J::UniformScaling, UL::Union{UpperTriangular,UnitUpperTriangular})
ULnew = similar(parent(UL), Base.Broadcast._broadcast_eltype(-, J, UL))
ULnew = similar(parent(UL), Broadcast.combine_eltypes(-, J, UL))
n = size(ULnew, 1)
ULold = UL.data
for j = 1:n
Expand All @@ -126,7 +126,7 @@ function (-)(J::UniformScaling, UL::Union{UpperTriangular,UnitUpperTriangular})
return UpperTriangular(ULnew)
end
function (-)(J::UniformScaling, UL::Union{LowerTriangular,UnitLowerTriangular})
ULnew = similar(parent(UL), Base.Broadcast._broadcast_eltype(-, J, UL))
ULnew = similar(parent(UL), Broadcast.combine_eltypes(-, J, UL))
n = size(ULnew, 1)
ULold = UL.data
for j = 1:n
Expand All @@ -144,7 +144,7 @@ end

function (+)(A::AbstractMatrix, J::UniformScaling)
n = checksquare(A)
B = similar(A, Base.Broadcast._broadcast_eltype(+, A, J))
B = similar(A, Broadcast.combine_eltypes(+, A, J))
copy!(B,A)
@inbounds for i = 1:n
B[i,i] += J.λ
Expand All @@ -154,7 +154,7 @@ end

function (-)(A::AbstractMatrix, J::UniformScaling)
n = checksquare(A)
B = similar(A, Base.Broadcast._broadcast_eltype(-, A, J))
B = similar(A, Broadcast.combine_eltypes(-, A, J))
copy!(B, A)
@inbounds for i = 1:n
B[i,i] -= J.λ
Expand All @@ -163,7 +163,7 @@ function (-)(A::AbstractMatrix, J::UniformScaling)
end
function (-)(J::UniformScaling, A::AbstractMatrix)
n = checksquare(A)
B = convert(AbstractMatrix{Base.Broadcast._broadcast_eltype(-, J, A)}, -A)
B = convert(AbstractMatrix{Broadcast.combine_eltypes(-, J, A)}, -A)
@inbounds for j = 1:n
B[j,j] += J.λ
end
Expand Down
Loading