diff --git a/Project.toml b/Project.toml index 1935c38a..52504125 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "BlockArrays" uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e" -version = "1.7.0" +version = "1.7.1" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/src/blockbroadcast.jl b/src/blockbroadcast.jl index b936a80b..e06c91e9 100644 --- a/src/blockbroadcast.jl +++ b/src/blockbroadcast.jl @@ -138,9 +138,10 @@ end end function _generic_blockbroadcast_copyto!(dest::AbstractArray, - bc::Broadcasted{<:AbstractBlockStyle{NDims}, <:Any, <:Any, Args}) where {NDims, Args <: Tuple} + bc1::Broadcasted{<:AbstractBlockStyle{NDims}}) where {NDims} - NArgs = fieldcount(Args) + bc = Broadcast.flatten(bc1) + NArgs = length(bc.args) bs = axes(bc) if !blockisequal(axes(dest), bs) diff --git a/test/test_blockbroadcast.jl b/test/test_blockbroadcast.jl index 5ed43a4f..b9a826df 100644 --- a/test/test_blockbroadcast.jl +++ b/test/test_blockbroadcast.jl @@ -67,10 +67,26 @@ using StaticArrays @test A .+ 1 .+ B == Vector(A) .+ 1 .+ B == Vector(A) .+ 1 .+ Matrix(B) @testset "preserve structure" begin - x = BlockedArray(1:6, Fill(3,2)) - @test x + x isa BlockedVector{Int,<:AbstractRange} - @test 2x + x isa BlockedVector{Int,<:AbstractRange} - @test 2 .* (x .+ 1) isa BlockedVector{Int,<:AbstractRange} + x = BlockedArray(1:6, Fill(3,2)) + @test x + x isa BlockedVector{Int,<:AbstractRange} + @test 2x + x isa BlockedVector{Int,<:AbstractRange} + @test 2 .* (x .+ 1) isa BlockedVector{Int,<:AbstractRange} + end + + @testset "nested in-place broadcast" begin + x = BlockedVector(randn(4), [2, 2]) + y = BlockedVector(randn(4), [2, 2]) + dest = copy(x) + dest .+= 2 .* y + @test dest ≈ x + 2y + end + + @testset "0-dim nested in-place broadcast" begin + x = BlockedArray(randn(())) + y = BlockedArray(randn(())) + dest = copy(x) + dest .+= 2 .* y + @test dest ≈ x + 2y end end