Skip to content

Commit

Permalink
Remove broadcast_elwise_op and deprecate promote_eltype_op (#19814)
Browse files Browse the repository at this point in the history
* Remove broadcast_elwise_op and deprecate promote_eltype_op

* Fix typo in comment
  • Loading branch information
martinholters authored and tkelman committed Jan 4, 2017
1 parent 5d2e538 commit 2e08102
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
6 changes: 0 additions & 6 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1790,12 +1790,6 @@ function mapslices(f, A::AbstractArray, dims::AbstractVector)
return R
end

# These are needed because map(eltype, As) is not inferrable
promote_eltype_op(::Any) = Any
promote_eltype_op(op, A) = (@_inline_meta; promote_op(op, eltype(A)))
promote_eltype_op(op, A, B) = (@_inline_meta; promote_op(op, eltype(A), eltype(B)))
promote_eltype_op(op, A, B, C, D...) = (@_inline_meta; promote_eltype_op(op, eltype(A), promote_eltype_op(op, B, C, D...)))

## 1 argument

function map!{F}(f::F, dest::AbstractArray, A::AbstractArray)
Expand Down
7 changes: 1 addition & 6 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Broadcast

using Base.Cartesian
using Base: promote_eltype_op, linearindices, tail, OneTo, to_shape,
using Base: linearindices, tail, OneTo, to_shape,
_msk_end, unsafe_bitgetindex, bitcache_chunks, bitcache_size, dumpbitcache,
nullable_returntype, null_safe_eltype_op, hasvalue
import Base: broadcast, broadcast!
Expand Down Expand Up @@ -267,11 +267,6 @@ function broadcast_t(f, ::Type{Bool}, shape, iter, As...)
return B
end

# broadcast method that uses inference to find the type, but preserves abstract
# container types when possible (used by binary elementwise operators)
@inline broadcast_elwise_op(f, As...) =
broadcast!(f, similar(Array{promote_eltype_op(f, As...)}, broadcast_indices(As...)), As...)

eltypestuple(a) = (Base.@_pure_meta; Tuple{eltype(a)})
eltypestuple(T::Type) = (Base.@_pure_meta; Tuple{Type{T}})
eltypestuple(a, b...) = (Base.@_pure_meta; Tuple{eltypestuple(a).types..., eltypestuple(b...).types...})
Expand Down
5 changes: 4 additions & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ for (Bsig, A1sig, A2sig, gbb, funcname) in
end # let broadcast_cache
end
_broadcast_zpreserving!(args...) = broadcast!(args...)
_broadcast_zpreserving(args...) = Base.Broadcast.broadcast_elwise_op(args...)
_broadcast_zpreserving(f, As...) = broadcast!(f, similar(Array{promote_op(f, map(eltype, As)...)}, Base.Broadcast.broadcast_indices(As...)), As...)
_broadcast_zpreserving{Tv1,Ti1,Tv2,Ti2}(f::Function, A_1::SparseMatrixCSC{Tv1,Ti1}, A_2::SparseMatrixCSC{Tv2,Ti2}) =
_broadcast_zpreserving!(f, spzeros(promote_type(Tv1, Tv2), promote_type(Ti1, Ti2), Base.to_shape(Base.Broadcast.broadcast_indices(A_1, A_2))), A_1, A_2)
_broadcast_zpreserving{Tv,Ti}(f::Function, A_1::SparseMatrixCSC{Tv,Ti}, A_2::Union{Array,BitArray,Number}) =
Expand Down Expand Up @@ -1470,4 +1470,7 @@ end
@deprecate (|)(A::AbstractArray, b::Number) A .| b
@deprecate (|)(A::AbstractArray, B::AbstractArray) A .| B

# Calling promote_op is likely a bad idea, so deprecate its convenience wrapper promote_eltype_op
@deprecate promote_eltype_op(op, As...) promote_op(op, map(eltype, As)...)

# End deprecations scheduled for 0.6

0 comments on commit 2e08102

Please sign in to comment.