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

Remove broadcast_elwise_op and deprecate promote_eltype_op #19814

Merged
merged 2 commits into from
Jan 4, 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: 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...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems bad to have a type-unstable implementation, even if deprecated.

_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