From 29fe0d7313af2beaf4bf136d120a71b92345432a Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Tue, 5 Dec 2023 16:20:23 +0000 Subject: [PATCH] correct blockcolsupport when past block range (#176) * correct blockcolsupport when past block range * v0.12.9 * Update test_adjtransblockbanded.jl * Update test_adjtransblockbanded.jl --- Project.toml | 2 +- src/AbstractBlockBandedMatrix.jl | 14 ++++++++++--- test/test_adjtransblockbanded.jl | 34 +++++++++++++++++++++++--------- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/Project.toml b/Project.toml index b80d6c3..e971dc1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "BlockBandedMatrices" uuid = "ffab5731-97b5-5995-9138-79e8c1846df0" -version = "0.12.8" +version = "0.12.9" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/src/AbstractBlockBandedMatrix.jl b/src/AbstractBlockBandedMatrix.jl index 61c0b91..6c19e72 100644 --- a/src/AbstractBlockBandedMatrix.jl +++ b/src/AbstractBlockBandedMatrix.jl @@ -152,7 +152,7 @@ end bs = blockcolstart(A,findblock(axes(A,2),i)) if isempty(axes(A,1)) 1 - elseif Int(bs) ≤ blocksize(A, 2) + elseif Int(bs) ≤ blocksize(A, 1) first(axes(A,1)[bs]) else size(A,1)+1 @@ -165,8 +165,16 @@ end last(axes(A,1)[CS]) end -@inline blockbanded_rowstart(A, i::Integer) = - first(axes(A,2)[blockrowstart(A,findblock(axes(A,1),i))]) +@inline function blockbanded_rowstart(A, i::Integer) + bs = blockrowstart(A,findblock(axes(A,1),i)) + if isempty(axes(A,2)) + 1 + elseif Int(bs) ≤ blocksize(A, 2) + first(axes(A,2)[bs]) + else + size(A,2)+1 + end +end @inline function blockbanded_rowstop(A, i::Integer) CS = blockrowstop(A,findblock(axes(A,1),i)) diff --git a/test/test_adjtransblockbanded.jl b/test/test_adjtransblockbanded.jl index f80d130..beea7b3 100644 --- a/test/test_adjtransblockbanded.jl +++ b/test/test_adjtransblockbanded.jl @@ -1,12 +1,7 @@ -using ArrayLayouts -using BlockBandedMatrices -using Test - -import BlockBandedMatrices: BandedBlockBandedRowMajor, - BandedBlockBandedRows, - BandedBlockBandedColumns, - BlockBandedRows, - BlockBandedColumns +using ArrayLayouts, BlockBandedMatrices, Test +import BlockBandedMatrices: BandedBlockBandedRowMajor, BandedBlockBandedRows, + BandedBlockBandedColumns, BlockBandedRows, + BlockBandedColumns, blockcolsupport, blockrowsupport @testset "Adj/Trans" begin @testset "BandedBlockBanded" begin @@ -45,4 +40,25 @@ import BlockBandedMatrices: BandedBlockBandedRowMajor, @test BlockBandedMatrix(A') == A' @test BlockBandedMatrix(transpose(A)) == transpose(A) end + + @testset "blockcolsupport" begin + D_y = BandedBlockBandedMatrix{Float64}(undef, Fill(2,81), [3; Fill(2,79)], (0,0), (0,1)) + @test colsupport(D_y, 161) == 159:160 + @test rowsupport(D_y, 162) == 162:161 + @test colsupport(D_y', 162) == 162:161 + @test rowsupport(D_y', 161) == 159:160 + + @test blockcolsupport(D_y, Block(80)) == Block.(80:80) + @test blockrowsupport(D_y, Block(81)) == Block.(81:80) + @test blockcolsupport(D_y', Block(81)) == Block.(81:80) + @test blockrowsupport(D_y', Block(80)) == Block.(80:80) + + E1 = BandedBlockBandedMatrix{Float64}(undef, Int[], [1], (0,0), (0,1)) + @test colsupport(E1, 1) == 1:0 + @test rowsupport(E1', 1) == 1:0 + + E2 = BandedBlockBandedMatrix{Float64}(undef, [1], Int[], (0,0), (0,1)) + @test rowsupport(E2, 1) == 1:0 + @test colsupport(E2', 1) == 1:0 + end end