Skip to content

Commit c6b7d1c

Browse files
committed
Workaround inference problem in round.(Int,v)
julia-0.6 doesn't seem to do constant propagation of `Type`s in quite the way which would be required to get good efficiency for broadcasting `round`. Insert a minimal workaround for this particularly common case.
1 parent 715fefe commit c6b7d1c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/broadcast.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ end
111111
end
112112
end
113113

114+
if VERSION < v"0.7.0-DEV"
115+
# Workaround for #329
116+
@inline function Base.broadcast(f, ::Type{T}, a::StaticArray) where {T}
117+
map(x->f(T,x), a)
118+
end
119+
end
114120

115121
################
116122
## broadcast! ##

test/mapreduce.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@
111111

112112
@test_throws DimensionMismatch broadcast(+, v1, @SMatrix [4 3 2 1; 5 6 7 8])
113113

114-
@test @inferred(broadcast(convert, Float64, v1)) == convert(Vector{Float64}, [2,4,6,8])
114+
@test @inferred(broadcast(convert, Float64, v1)) === SVector{4,Float64}(2,4,6,8)
115+
# issue 329
116+
@test @inferred(broadcast(round, Int, SVector(1.0,2.0))) === SVector{2,Int}(1,2)
115117

116118
@test @inferred(broadcast(-, v1)) === map(-, v1)
117119

0 commit comments

Comments
 (0)