Skip to content

Commit

Permalink
Broadcast for Bidiagonal/Tridiagonal/SymTridiaognal (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Sep 5, 2024
1 parent 4f757e7 commit 643a2fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/infarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ for typ in (:Ones, :Zeros, :Fill)
end
end

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

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

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

BroadcastStyle(::Type{<:Diagonal{<:Any,<:AbstractInfUnitRange}}) = LazyArrayStyle{2}()
for M in (:Diagonal, :Bidiagonal, :Tridiagonal, :SymTridiagonal)
@eval BroadcastStyle(::Type{<:$M{<:Any,<:AbstractInfUnitRange}}) = LazyArrayStyle{2}()
end
sub_materialize(::AbstractBandedLayout, V, ::Tuple{InfAxes,InfAxes}) = V
sub_materialize(::AbstractBandedLayout, V, ::Tuple{OneTo{Int},InfAxes}) = V
sub_materialize(::AbstractBandedLayout, V, ::Tuple{InfAxes,OneTo{Int}}) = V
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,16 @@ end
@test c[1:6] == a[r[2:7]]
@test Base.BroadcastStyle(typeof(c)) isa LazyArrayStyle
end

@testset "structured matrices" begin
r = 1:
f = Fill(2, ∞)
for B in (Bidiagonal(r, r, :U), Tridiagonal(r, r, r), SymTridiagonal(r, r),
Bidiagonal(f, f, :U), Tridiagonal(f, f, f), SymTridiagonal(f, f))
B2 = B .+ B
@test B2[1:10, 1:10] == 2B[1:10, 1:10]
end
end
end

@testset "Cumsum and diff" begin
Expand Down

0 comments on commit 643a2fb

Please sign in to comment.