Skip to content

Commit 023cba0

Browse files
committed
Add special casing for broadcasting a scalar to fix #104.
1 parent 89384d9 commit 023cba0

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/LoopVectorization.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ include("add_stores.jl")
4545
include("add_compute.jl")
4646
include("add_constants.jl")
4747
include("add_ifelse.jl")
48-
include("broadcast.jl")
4948
include("determinestrategy.jl")
5049
include("lower_compute.jl")
5150
include("lower_constant.jl")
@@ -59,6 +58,7 @@ include("reconstruct_loopset.jl")
5958
include("constructors.jl")
6059
include("user_api_conveniences.jl")
6160
include("mapreduce.jl")
61+
include("broadcast.jl")
6262

6363
"""
6464
LoopVectorization provides macros and functions that combine SIMD vectorization and

src/broadcast.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,25 @@ end
289289
q
290290
# ls
291291
end
292+
function vmaterialize!(
293+
dest::StridedArray{T}, bc::Broadcasted{Base.Broadcast.DefaultArrayStyle{0},Nothing,typeof(identity),Tuple{T2}}, ::Val{Mod}
294+
) where {T <: NativeTypes, T2 <: Number, Mod}
295+
arg = T(first(bc.args))
296+
@avx for i eachindex(dest)
297+
dest[i] = arg
298+
end
299+
dest
300+
end
301+
function vmaterialize!(
302+
dest′::Union{Adjoint{T,A},Transpose{T,A}}, bc::Broadcasted{Base.Broadcast.DefaultArrayStyle{0},Nothing,typeof(identity),Tuple{T2}}, ::Val{Mod}
303+
) where {T <: NativeTypes, A <: StridedArray{T}, T2 <: Number, Mod}
304+
arg = T(first(bc.args))
305+
dest = parent(dest′)
306+
@avx for i eachindex(dest)
307+
dest[i] = arg
308+
end
309+
dest′
310+
end
292311

293312
@inline function vmaterialize(bc::Broadcasted, ::Val{Mod}) where {Mod}
294313
ElType = Base.Broadcast.combine_eltypes(bc.f, bc.args)

0 commit comments

Comments
 (0)