Skip to content

Commit 175e70e

Browse files
committed
Refine column ranges in _isbanded_impl
1 parent 925acef commit 175e70e

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/generic.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,9 @@ function _isbanded_impl(A, kl, ku)
14931493
last_col_nonemptybottomrows = size(A,1) + kl - 1 # empty bottom rows after this column
14941494

14951495
colrange_onlybottomrows = firstindex(A,2):min(last_col_nonemptybottomrows, last_col_emptytoprows)
1496-
colrange_topbottomrows = max(last_col_emptytoprows, last(colrange_onlybottomrows))+1:last_col_nonzeroblocks
1496+
col_topbotrows_start = max(last_col_emptytoprows, last(colrange_onlybottomrows))+1
1497+
col_topbotrows_end = min(last_col_nonemptybottomrows, last_col_nonzeroblocks)
1498+
colrange_topbottomrows = col_topbotrows_start:col_topbotrows_end
14971499
colrange_onlytoprows_nonzero = last(colrange_topbottomrows)+1:last_col_nonzeroblocks
14981500
colrange_zero_block = last_col_nonzeroblocks+1:lastindex(A,2)
14991501

test/generic.jl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,17 +514,17 @@ end
514514

515515
@testset "generic functions for checking whether matrices have banded structure" begin
516516
pentadiag = [1 2 3; 4 5 6; 7 8 9]
517-
tridiag = [1 2 0; 4 5 6; 0 8 9]
518-
tridiagG = GenericArray([1 2 0; 4 5 6; 0 8 9])
517+
tridiag = diagm(-1=>1:6, 1=>1:6)
518+
tridiagG = GenericArray(tridiag)
519519
Tridiag = Tridiagonal(tridiag)
520520
ubidiag = [1 2 0; 0 5 6; 0 0 9]
521-
ubidiagG = GenericArray([1 2 0; 0 5 6; 0 0 9])
521+
ubidiagG = GenericArray(ubidiag)
522522
uBidiag = Bidiagonal(ubidiag, :U)
523523
lbidiag = [1 0 0; 4 5 0; 0 8 9]
524-
lbidiagG = GenericArray([1 0 0; 4 5 0; 0 8 9])
524+
lbidiagG = GenericArray(lbidiag)
525525
lBidiag = Bidiagonal(lbidiag, :L)
526526
adiag = [1 0 0; 0 5 0; 0 0 9]
527-
adiagG = GenericArray([1 0 0; 0 5 0; 0 0 9])
527+
adiagG = GenericArray(adiag)
528528
aDiag = Diagonal(adiag)
529529
@testset "istriu" begin
530530
@test !istriu(pentadiag)
@@ -618,6 +618,17 @@ end
618618
end
619619
end
620620
end
621+
622+
tridiag = diagm(-1=>1:6, 1=>1:6)
623+
A = [tridiag zeros(size(tridiag,1), 2)]
624+
G = GenericArray(A)
625+
@testset for (kl,ku) in Iterators.product(-10:10, -10:10)
626+
@test isbanded(A, kl, ku) == isbanded(G, kl, ku)
627+
end
628+
@testset for k in -10:10
629+
@test istriu(A,k) == istriu(G,k)
630+
@test istril(A,k) == istril(G,k)
631+
end
621632
end
622633

623634
@testset "missing values" begin

0 commit comments

Comments
 (0)