From a6c87bcaee281cde3362769df3c7e829fa291821 Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Mon, 15 Mar 2021 22:26:46 +0000 Subject: [PATCH 1/2] Suport SubTridiagonalLayout --- Project.toml | 2 +- src/interfaceimpl.jl | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index bd779e05..1b1a1258 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "BandedMatrices" uuid = "aae01518-5342-5314-be14-df237901396f" -version = "0.16.8" +version = "0.16.9" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/src/interfaceimpl.jl b/src/interfaceimpl.jl index ce4f8a6b..5cb4309a 100644 --- a/src/interfaceimpl.jl +++ b/src/interfaceimpl.jl @@ -51,8 +51,30 @@ inbands_setindex!(J::SymTridiagonal, v, k::Integer, j::Integer) = isbanded(::Tridiagonal) = true bandwidths(::Tridiagonal) = (1,1) +struct SubTridiagonalLayout <: AbstractBandedLayout end + sublayout(::AbstractTridiagonalLayout, ::Type{<:Tuple{AbstractUnitRange{Int},AbstractUnitRange{Int}}}) = - BandedLayout() + SubTridiagonalLayout() + +function _BandedMatrix(::SubTridiagonalLayout, V::AbstractMatrix{T}) where T + A = parent(V) + kr,jr = parentindices(V) + m,n = size(V) + dat = Matrix{T}(undef, 3, n) + + c,a,b = supdiagonaldata(A), diagonaldata(A), supdiagonaldata(A) + if first(jr) == 1 + copyto!(view(dat, 1, 2:n), view(c, jr[2:end] .- 1)) + else + copyto!(view(dat, 1, :), view(c, jr .- 1)) + end + copyto!(view(dat, 2, :), view(a, jr)) + copyto!(view(dat, 3, :), view(b, jr)) + + sh = first(kr)-first(jr) + _BandedMatrix(dat, m, 1-sh, 1+sh) +end + ### # rot180 From 8b0ae6cdeb215f7b2fe989f49a53bb9e9a91055b Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Tue, 23 Mar 2021 08:32:04 +0000 Subject: [PATCH 2/2] Update interfaceimpl.jl --- src/interfaceimpl.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interfaceimpl.jl b/src/interfaceimpl.jl index 5cb4309a..e1e115c6 100644 --- a/src/interfaceimpl.jl +++ b/src/interfaceimpl.jl @@ -62,7 +62,7 @@ function _BandedMatrix(::SubTridiagonalLayout, V::AbstractMatrix{T}) where T m,n = size(V) dat = Matrix{T}(undef, 3, n) - c,a,b = supdiagonaldata(A), diagonaldata(A), supdiagonaldata(A) + c,a,b = subdiagonaldata(A), diagonaldata(A), supdiagonaldata(A) if first(jr) == 1 copyto!(view(dat, 1, 2:n), view(c, jr[2:end] .- 1)) else