Skip to content

Commit 4a7b1df

Browse files
authored
Specialize blockedrange BroadcastStyle for LazyArrayStyle (#384)
* Specialize blockedrange BroadcastStyle for LazyArrayStyle * Add compat for LazyArrays
1 parent 94e7ca3 commit 4a7b1df

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

Project.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@ version = "1.0.0-dev"
55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
77
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
8+
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
89
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
910

11+
[weakdeps]
12+
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
13+
14+
[extensions]
15+
BlockArraysLazyArraysExt = "LazyArrays"
16+
1017
[compat]
1118
Aqua = "0.8"
1219
ArrayLayouts = "1.0.8"
1320
Documenter = "1"
1421
FillArrays = "1"
1522
InfiniteArrays = "0.13"
23+
LazyArrays = "1"
1624
LinearAlgebra = "1.6"
1725
OffsetArrays = "1"
1826
Random = "1.6"

ext/BlockArraysLazyArraysExt.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module BlockArraysLazyArraysExt
2+
3+
import BlockArrays
4+
import LazyArrays
5+
6+
BlockArrays._broadcaststyle(S::LazyArrays.LazyArrayStyle{1}) = S
7+
8+
end

src/BlockArrays.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ include("blockarrayinterface.jl")
7474
@deprecate getblock!(X, A::AbstractBlockArray{T,N}, I::Vararg{Integer, N}) where {T,N} copyto!(X, view(A, Block(I)))
7575
@deprecate setblock!(A::AbstractBlockArray{T,N}, v, I::Vararg{Integer, N}) where {T,N} (A[Block(I...)] = v)
7676

77-
77+
if !isdefined(Base, :get_extension)
78+
include("../ext/BlockArraysLazyArraysExt.jl")
79+
end
7880

7981
end # module

src/blockaxis.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,8 @@ blockaxes(S::Base.Slice) = blockaxes(S.indices)
535535

536536

537537
# This supports broadcasting with infinite block arrays
538-
Base.BroadcastStyle(::Type{<:AbstractBlockedUnitRange{<:Any,R}}) where R = Base.BroadcastStyle(R)
538+
_broadcaststyle(_) = Broadcast.DefaultArrayStyle{1}()
539+
Base.BroadcastStyle(::Type{<:AbstractBlockedUnitRange{<:Any,R}}) where R = _broadcaststyle(Base.BroadcastStyle(R))
539540

540541

541542
###

test/test_blockbroadcast.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using BlockArrays, FillArrays, Test
22
import BlockArrays: SubBlockIterator, BlockIndexRange, Diagonal
33
import InfiniteArrays
4+
using StaticArrays
45

56
@testset "broadcast" begin
67
@testset "BlockArray" begin
@@ -129,6 +130,9 @@ import InfiniteArrays
129130
for i in 1:10
130131
@test b2[Block(i)] == b[Block(i)] + b[Block(i)]
131132
end
133+
134+
b = blockedrange(SVector{2}([1,2]))
135+
@test b .+ b == 2:2:6
132136
end
133137

134138
@testset "Special broadcast" begin

0 commit comments

Comments
 (0)