Skip to content

Commit

Permalink
Merge pull request JuliaLang#4741 from simonster/broadcast-workaround
Browse files Browse the repository at this point in the history
Incomplete fix/workaround for broadcast static type inference (JuliaLang#4673)
  • Loading branch information
JeffBezanson committed Nov 8, 2013
2 parents f6e29aa + 5bb9fd6 commit f81aa2a
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@ export broadcast_getindex, broadcast_setindex!

## Broadcasting utilities ##

droparg1(a, args...) = args

longer_tuple(x::(), retx::Tuple, y::(), rety::Tuple) = retx
longer_tuple(x::(), retx::Tuple, y::Tuple, rety::Tuple) = rety
longer_tuple(x::Tuple, retx::Tuple, y::(), rety::Tuple) = retx
longer_tuple(x::Tuple, retx::Tuple, y::Tuple, rety::Tuple) =
longer_tuple(droparg1(x...), retx, droparg1(y...), rety)
longer_tuple(x::Tuple, y::Tuple) = longer_tuple(x, x, y, y)

longer_size(x::AbstractArray) = size(x)
longer_size(x::AbstractArray, y::AbstractArray...) =
longer_tuple(size(x), longer_size(y...))

# Calculate the broadcast shape of the arguments, or error if incompatible
broadcast_shape() = ()
function broadcast_shape(As::AbstractArray...)
nd = ndims(As[1])
for i = 2:length(As)
nd = max(nd, ndims(As[i]))
end
sz = longer_size(As...)
nd = length(sz)
bshape = ones(Int, nd)
for A in As
for d = 1:ndims(A)
Expand All @@ -28,7 +39,7 @@ function broadcast_shape(As::AbstractArray...)
end
end
end
return tuple(bshape...)
return tuple(bshape...)::typeof(sz)
end

# Check that all arguments are broadcast compatible with shape
Expand Down Expand Up @@ -180,7 +191,7 @@ function code_broadcasts(name::String, op)
end

function $fname(As::StridedArray...)
$fname_T(promote_type([eltype(A) for A in As]...), As...)
$fname_T(Base.promote_eltype(As...), As...)
end

function $fname{T}(As::StridedArray{T}...)
Expand Down

0 comments on commit f81aa2a

Please sign in to comment.