Skip to content

Commit

Permalink
Merge pull request #252 from JuliaArrays/inplace-broadcast-array-fix
Browse files Browse the repository at this point in the history
Fix broadcast! with non-static arrays
  • Loading branch information
c42f committed Jul 25, 2017
2 parents 8047757 + a61d193 commit 0a73072
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ end
## broadcast! ##
################

@inline function broadcast_c!(f, ::Type{StaticArray}, ::Type, dest, as...)
# TODO: This signature could be relaxed to (::Any, ::Type{StaticArray}, ::Type, ...), though
# we'd need to rework how _broadcast!() and broadcast_sizes() interact with normal AbstractArray.
@inline function broadcast_c!(f, ::Type{StaticArray}, ::Type{StaticArray}, dest, as...)
_broadcast!(f, Size(dest), dest, broadcast_sizes(as...), as...)
end

Expand Down
5 changes: 5 additions & 0 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ end
A = @MMatrix([1 0]); @test @inferred(broadcast!(+, A, A, 2)) == @MMatrix [3 2]
end

@testset "broadcast! with mixtures of SArray and Array" begin
a = zeros(MVector{2}); @test @inferred(broadcast!(+, a, [1,2])) == [1,2]
a = zeros(MMatrix{2,3}); @test @inferred(broadcast!(+, a, [1,2])) == [1 1 1; 2 2 2]
end

@testset "eltype after broadcast" begin
# test cases issue #198
let a = SVector{4, Number}(2, 2.0, 4//2, 2+0im)
Expand Down

0 comments on commit 0a73072

Please sign in to comment.