From d8e44fcc1c4fe98f4b87668d498575f303813701 Mon Sep 17 00:00:00 2001 From: Dhairya Gandhi Date: Wed, 4 Mar 2020 18:22:45 +0530 Subject: [PATCH] correct broadcasting for addition --- src/utils.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index 6ad410b3..5e8eb270 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -247,7 +247,7 @@ Base.collect(xs::Zeros{T,N}) where {T,N} = fill(zero(T), size(xs)) # Define basic ops for f in (:+, :-) - @eval function $f(a::Union{AbstractArray{<:Number}, Zeros}, b::Zeros) + @eval @inline function $f(a::Union{AbstractArray{<:Number}, Zeros}, b::Zeros) @assert size(a) == size(b) throw(DimensionMismatch("dimensions must match")) a end @@ -261,7 +261,9 @@ Base.copy(xs::Zeros{T,N}) where {T,N} = xs # Define broadcasting behaviour for op in (:+, :-) @eval function broadcasted(::typeof($op), a::AbstractArray, b::Zeros) - sz = similar(a, Broadcast.broadcast_shape(size(a), size(b))) + bs = Broadcast.broadcast_shape(size(a), size(b)) + size(a) == bs && return a + sz = similar(a, bs) sz .= a end end