Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "BlockArrays"
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
version = "1.9.3"
version = "1.9.4"


[deps]
Expand Down
1 change: 1 addition & 0 deletions src/abstractblockarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ end

getindex(A::Adjoint{<:Any,<:LayoutMatrix}, kr::BlockRange{1}, jr::BlockRange{1}) = parent(A)[jr,kr]'
getindex(A::Transpose{<:Any,<:LayoutMatrix}, kr::BlockRange{1}, jr::BlockRange{1}) = transpose(parent(A)[jr,kr])
getindex(A::AdjOrTrans{<:Any,<:LayoutVector}, kr::BlockRange{1}, jr::BlockRange{1}) = ArrayLayouts.layout_getindex(A, kr, jr)

###
# permutedims
Expand Down
9 changes: 6 additions & 3 deletions src/blockbroadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,13 @@ function _generic_blockbroadcast_copyto!(dest::AbstractArray,

bc = Broadcast.flatten(bc1)
NArgs = length(bc.args)

bs = axes(bc)

if !all(a -> !(a isa AbstractArray) || size(a) == size(dest), bc.args)
# code below assumes only scalars and matching sizes. We therefore go back to default.
return copyto!(dest, Broadcasted{DefaultArrayStyle{NDims}}(bc.f, bc.args, bs))
end

if !blockisequal(axes(dest), bs)
copyto!(BlockedArray(dest, bs), bc)
return dest
Expand Down Expand Up @@ -267,14 +272,12 @@ BroadcastStyle(::Type{<:SubArray{<:Any,N,<:BlockedArray,I}}) where {N,I<:Tuple{A
for op in (:*, :/)
@eval begin
broadcasted(::AbstractBlockStyle, ::typeof($op), a::Zeros, b::AbstractArray) = FillArrays._broadcasted_zeros($op, a, b)
broadcasted(::AbstractBlockStyle, ::typeof($op), a::Ones{T}, b::AbstractArray{V}) where {T,V} = LinearAlgebra.copy_oftype(b, Base.promote_op(*, T, V))
end
end

for op in (:*, :\)
@eval begin
broadcasted(::AbstractBlockStyle, ::typeof($op), a::AbstractArray, b::Zeros) = FillArrays._broadcasted_zeros($op, a, b)
broadcasted(::AbstractBlockStyle, ::typeof($op), a::AbstractArray{T}, b::Ones{V}) where {T,V} = LinearAlgebra.copy_oftype(a, Base.promote_op(*, T, V))
end
end

Expand Down
3 changes: 3 additions & 0 deletions test/test_blockarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,9 @@ end
@test (a')[:,Block.(1:2)] == transpose(a)[:,Block.(1:2)] == [1 2 3]
@test (a')[:,Block.(1:2)] isa Adjoint
@test transpose(a)[:,Block.(1:2)] isa Transpose

@test a'[Block.(1:1), Block.(2:3)] == a'[Block.(1:1), 3:4] == a'[Block(1), Block.(2:3)] == a'[Block(1)[1:1], Block.(2:3)] == [3 4]
@test a'[Block.(1:1), Block(2)[1:1]] == a'[Block(1), Block(2)[1:1]] == [3;;]
end

@testset "empty blocklengths" begin
Expand Down
6 changes: 6 additions & 0 deletions test/test_blockbroadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ using StaticArrays
@test issorted(w)
@test w == reverse(v)
end

@testset "Ones bug" begin
a = Ones((blockedrange([1,2]),))
b = BlockArray([1 2 3], [1], [2,1])
@test a .* b == Vector(a) .* b == a .* Matrix(b) == Vector(a) .* Matrix(b) == b .* a == Matrix(b) .* a == b .* Vector(a)
end
end

end # module
Loading