Skip to content

Commit 85e6d55

Browse files
authored
Support new ArrayLayouts (#127)
* Update Project.toml * Update blockaxis.jl * Update Project.toml * fix elsize * broadcasting for FillArrays * Update Project.toml * Update test_blockarrayinterface.jl * Add tests * Tests pass * Update Project.toml
1 parent 99d1530 commit 85e6d55

File tree

8 files changed

+35
-8
lines changed

8 files changed

+35
-8
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
name = "BlockArrays"
22
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
3-
version = "0.12.11"
3+
version = "0.12.12"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
77
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
8+
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
89
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
910

1011
[compat]
11-
ArrayLayouts = "0.3.8"
12+
ArrayLayouts = "0.4.1"
1213
Compat = "2.2, 3"
14+
FillArrays = "0.9.2"
1315
julia = "1.1"
1416

1517
[extras]

src/BlockArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module BlockArrays
22
using Base.Cartesian
3-
using LinearAlgebra, ArrayLayouts
3+
using LinearAlgebra, ArrayLayouts, FillArrays
44

55
# AbstractBlockArray interface exports
66
export AbstractBlockArray, AbstractBlockMatrix, AbstractBlockVector, AbstractBlockVecOrMat

src/blockarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ convert(::Type{BlockArray{T1}}, A::AbstractArray{T2, N}) where {T1,T2,N} =
313313
convert(::Type{BlockArray}, A::AbstractArray{T, N}) where {T,N} =
314314
convert(BlockArray{T, N}, A)
315315

316-
copy(A::BlockArray) = _BlockArray(copy.(A.blocks), A.axes)
316+
copy(A::BlockArray) = _BlockArray(map(copy,A.blocks), A.axes)
317317

318318
################################
319319
# AbstractBlockArray Interface #

src/blockaxis.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ julia> blockaxes(A)[1]
100100
```
101101
"""
102102
blockaxes(b::BlockedUnitRange) = (Block.(axes(b.lasts,1)),)
103-
blockaxes(b::AbstractArray{<:Any,N}) where N = blockaxes.(axes(b), 1)
103+
blockaxes(b) = blockaxes.(axes(b), 1)
104104

105105
"""
106106
blockaxes(A, d)

src/blockbroadcast.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,23 @@ _blocktype(::Type{<:BlockArray{<:Any,N,<:AbstractArray{R,N}}}) where {N,R} = R
231231
BroadcastStyle(::Type{<:SubArray{T,N,Arr,<:NTuple{N,BlockSlice1},false}}) where {T,N,Arr<:BlockArray} =
232232
BroadcastStyle(_blocktype(Arr))
233233
BroadcastStyle(::Type{<:SubArray{T,N,Arr,<:NTuple{N,BlockSlice{BlockRange{1,Tuple{II}}}},false}}) where {T,N,Arr<:BlockArray,II} =
234-
BroadcastStyle(Arr)
234+
BroadcastStyle(Arr)
235+
236+
237+
###
238+
# Fill
239+
###
240+
241+
for op in (:*, :/)
242+
@eval begin
243+
broadcasted(::AbstractBlockStyle, ::typeof($op), a::Zeros, b::AbstractArray) = FillArrays._broadcasted_zeros(a, b)
244+
broadcasted(::AbstractBlockStyle, ::typeof($op), a::Ones{T}, b::AbstractArray{V}) where {T,V} = LinearAlgebra.copy_oftype(b, Base.promote_op(*, T, V))
245+
end
246+
end
247+
248+
for op in (:*, :\)
249+
@eval begin
250+
broadcasted(::AbstractBlockStyle, ::typeof($op), a::AbstractArray, b::Zeros) = FillArrays._broadcasted_zeros(a, b)
251+
broadcasted(::AbstractBlockStyle, ::typeof($op), a::AbstractArray{T}, b::Ones{V}) where {T,V} = LinearAlgebra.copy_oftype(a, Base.promote_op(*, T, V))
252+
end
253+
end

src/pseudo_blockarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ Base.stride(A::PseudoBlockArray, i::Integer) = stride(A.blocks, i)
323323
Base.unsafe_convert(::Type{Ptr{T}}, A::PseudoBlockArray) where T = Base.unsafe_convert(Ptr{T}, A.blocks)
324324

325325
if VERSION  v"1.5"
326-
Base.elsize(::Type{<:PseudoBlockArray{T}}) where {T} = Base.aligned_sizeof(T)
326+
Base.elsize(::Type{<:PseudoBlockArray{T,N,R}}) where {T,N,R} = Base.elsize(R)
327327
end
328328

329329
###

test/test_blockarrayinterface.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ end
137137
U = UpperTriangular(Ones((blockedrange([1,2]),blockedrange([2,1]))))
138138

139139
if VERSION  v"1.2"
140-
@test stringmime("text/plain", A) == "5-element Fill{Int64,1,Tuple{BlockedUnitRange{Array{Int64,1}}}} with indices 1:1:5:\n 2\n\n 2\n 2\n\n 2\n 2"
140+
@test stringmime("text/plain", A) == "5-element Fill{Int64,1,Tuple{BlockedUnitRange{Array{Int64,1}}}} with indices 1:1:5: entries equal to 2"
141141
@test stringmime("text/plain", B) == "3×3 Diagonal{Float64,Ones{Float64,1,Tuple{BlockedUnitRange{Array{Int64,1}}}}} with indices 1:1:3×1:1:3:\n 1.0 │ ⋅ ⋅ \n ─────┼──────────\n ⋅ │ 1.0 ⋅ \n ⋅ │ ⋅ 1.0"
142142
@test stringmime("text/plain", U) == "3×3 UpperTriangular{Float64,Ones{Float64,2,Tuple{BlockedUnitRange{Array{Int64,1}},BlockedUnitRange{Array{Int64,1}}}}} with indices 1:1:3×1:1:3:\n 1.0 1.0 │ 1.0\n ──────────┼─────\n ⋅ 1.0 │ 1.0\n ⋅ ⋅ │ 1.0"
143143
end

test/test_blockbroadcast.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,10 @@ using BlockArrays, FillArrays, Test
131131
@test -V isa BlockArray
132132
@test -V == -A[Block.(2:3)]
133133
end
134+
135+
@testset "Fill broadcast" begin
136+
A = BlockArray(randn(6), 1:3)
137+
@test blockisequal(axes(A .* Zeros(6)), axes(A .* zeros(6)))
138+
@test blockisequal(axes(A .* Ones(6)), axes(A .* ones(6)))
139+
end
134140
end

0 commit comments

Comments
 (0)