Skip to content

Commit 643a2fb

Browse files
authored
Broadcast for Bidiagonal/Tridiagonal/SymTridiaognal (#194)
1 parent 4f757e7 commit 643a2fb

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/infarrays.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ for typ in (:Ones, :Zeros, :Fill)
173173
end
174174
end
175175

176-
BroadcastStyle(::Type{<:Diagonal{T,<:AbstractFill{T,1,Tuple{OneToInf{I}}}}}) where {T,I} = LazyArrayStyle{2}()
176+
for M in (:Diagonal, :Bidiagonal, :Tridiagonal, :SymTridiagonal)
177+
@eval BroadcastStyle(::Type{<:$M{T,<:AbstractFill{T,1,Tuple{OneToInf{I}}}}}) where {T,I} = LazyArrayStyle{2}()
178+
end
177179

178180
## Support broadcast(*, ::AbstractFill, A)
179181

@@ -285,7 +287,9 @@ end
285287
one(D::Diagonal{T,<:AbstractFill{T,1,Tuple{OneToInf{Int}}}}) where T = Eye{T}(size(D,1))
286288
copy(D::Diagonal{T,<:AbstractFill{T,1,Tuple{OneToInf{Int}}}}) where T = D
287289

288-
BroadcastStyle(::Type{<:Diagonal{<:Any,<:AbstractInfUnitRange}}) = LazyArrayStyle{2}()
290+
for M in (:Diagonal, :Bidiagonal, :Tridiagonal, :SymTridiagonal)
291+
@eval BroadcastStyle(::Type{<:$M{<:Any,<:AbstractInfUnitRange}}) = LazyArrayStyle{2}()
292+
end
289293
sub_materialize(::AbstractBandedLayout, V, ::Tuple{InfAxes,InfAxes}) = V
290294
sub_materialize(::AbstractBandedLayout, V, ::Tuple{OneTo{Int},InfAxes}) = V
291295
sub_materialize(::AbstractBandedLayout, V, ::Tuple{InfAxes,OneTo{Int}}) = V

test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,16 @@ end
912912
@test c[1:6] == a[r[2:7]]
913913
@test Base.BroadcastStyle(typeof(c)) isa LazyArrayStyle
914914
end
915+
916+
@testset "structured matrices" begin
917+
r = 1:
918+
f = Fill(2, ∞)
919+
for B in (Bidiagonal(r, r, :U), Tridiagonal(r, r, r), SymTridiagonal(r, r),
920+
Bidiagonal(f, f, :U), Tridiagonal(f, f, f), SymTridiagonal(f, f))
921+
B2 = B .+ B
922+
@test B2[1:10, 1:10] == 2B[1:10, 1:10]
923+
end
924+
end
915925
end
916926

917927
@testset "Cumsum and diff" begin

0 commit comments

Comments
 (0)