Skip to content

Commit d3d3144

Browse files
committed
Refine column ranges in _isbanded_impl
1 parent ae5385b commit d3d3144

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
@@ -1500,7 +1500,9 @@ function _isbanded_impl(A, kl, ku)
15001500
last_col_nonemptybottomrows = size(A,1) + kl - 1 # empty bottom rows after this column
15011501

15021502
colrange_onlybottomrows = firstindex(A,2):min(last_col_nonemptybottomrows, last_col_emptytoprows)
1503-
colrange_topbottomrows = max(last_col_emptytoprows, last(colrange_onlybottomrows))+1:last_col_nonzeroblocks
1503+
col_topbotrows_start = max(last_col_emptytoprows, last(colrange_onlybottomrows))+1
1504+
col_topbotrows_end = min(last_col_nonemptybottomrows, last_col_nonzeroblocks)
1505+
colrange_topbottomrows = col_topbotrows_start:col_topbotrows_end
15041506
colrange_onlytoprows_nonzero = last(colrange_topbottomrows)+1:last_col_nonzeroblocks
15051507
colrange_zero_block = last_col_nonzeroblocks+1:lastindex(A,2)
15061508

test/generic.jl

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

535535
@testset "generic functions for checking whether matrices have banded structure" begin
536536
pentadiag = [1 2 3; 4 5 6; 7 8 9]
537-
tridiag = [1 2 0; 4 5 6; 0 8 9]
538-
tridiagG = GenericArray([1 2 0; 4 5 6; 0 8 9])
537+
tridiag = diagm(-1=>1:6, 1=>1:6)
538+
tridiagG = GenericArray(tridiag)
539539
Tridiag = Tridiagonal(tridiag)
540540
ubidiag = [1 2 0; 0 5 6; 0 0 9]
541-
ubidiagG = GenericArray([1 2 0; 0 5 6; 0 0 9])
541+
ubidiagG = GenericArray(ubidiag)
542542
uBidiag = Bidiagonal(ubidiag, :U)
543543
lbidiag = [1 0 0; 4 5 0; 0 8 9]
544-
lbidiagG = GenericArray([1 0 0; 4 5 0; 0 8 9])
544+
lbidiagG = GenericArray(lbidiag)
545545
lBidiag = Bidiagonal(lbidiag, :L)
546546
adiag = [1 0 0; 0 5 0; 0 0 9]
547-
adiagG = GenericArray([1 0 0; 0 5 0; 0 0 9])
547+
adiagG = GenericArray(adiag)
548548
aDiag = Diagonal(adiag)
549549
@testset "istriu" begin
550550
@test !istriu(pentadiag)
@@ -638,6 +638,17 @@ end
638638
end
639639
end
640640
end
641+
642+
tridiag = diagm(-1=>1:6, 1=>1:6)
643+
A = [tridiag zeros(size(tridiag,1), 2)]
644+
G = GenericArray(A)
645+
@testset for (kl,ku) in Iterators.product(-10:10, -10:10)
646+
@test isbanded(A, kl, ku) == isbanded(G, kl, ku)
647+
end
648+
@testset for k in -10:10
649+
@test istriu(A,k) == istriu(G,k)
650+
@test istril(A,k) == istril(G,k)
651+
end
641652
end
642653

643654
@testset "missing values" begin

0 commit comments

Comments
 (0)