Skip to content

Commit 1da9118

Browse files
committed
Ensure that colstop/rowstop are ≥ 0
1 parent 3f92b6f commit 1da9118

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/BandedMatrices.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,14 @@ end
372372

373373
# start/stop indices of the i-th column/row, bounded by actual matrix size
374374
@inline colstart(A, i::Integer) = max(i-bandwidth(A,2), 1)
375-
@inline colstop(A, i::Integer) = min(i+bandwidth(A,1), size(A, 1))
375+
@inline colstop(A, i::Integer) = max(min(i+bandwidth(A,1), size(A, 1)), 0)
376376
@inline rowstart(A, i::Integer) = max(i-bandwidth(A,1), 1)
377-
@inline rowstop(A, i::Integer) = min(i+bandwidth(A,2), size(A, 2))
377+
@inline rowstop(A, i::Integer) = max(min(i+bandwidth(A,2), size(A, 2)), 0)
378378

379379
@inline colstart(A::BandedMatrix, i::Integer) = max(i-A.u, 1)
380-
@inline colstop(A::BandedMatrix, i::Integer) = min(i+A.l, size(A, 1))
380+
@inline colstop(A::BandedMatrix, i::Integer) = max(min(i+A.l, size(A, 1)), 0)
381381
@inline rowstart(A::BandedMatrix, i::Integer) = max(i-A.l, 1)
382-
@inline rowstop(A::BandedMatrix, i::Integer) = min(i+A.u, size(A, 2))
382+
@inline rowstop(A::BandedMatrix, i::Integer) = max(min(i+A.u, size(A, 2)), 0)
383383

384384
@inline colrange(A, i::Integer) = colstart(A,i):colstop(A,i)
385385
@inline rowrange(A, i::Integer) = rowstart(A,i):rowstop(A,i)

test/runtests.jl

+8-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ for S in (view(A,:,:),view(B,1:10,:),view(C,:,1:10),view(D,1:10,1:10),
391391
end
392392

393393

394-
# negative bands
394+
## negative bands
395395

396396
for A in (brand(3,4,-1,2),brand(5,4,-1,2),
397397
brand(3,4,2,-1),brand(5,4,2,-1))
@@ -405,7 +405,14 @@ for A in (brand(3,4,1,2),brand(3,4,-1,2),brand(3,4,2,-1)),
405405
@test_approx_eq A*B full(A)*full(B)
406406
end
407407

408+
# check that col/rowstop is ≥ 0
409+
A = brand(3,4,-2,2)
410+
@test BandedMatrices.colstop(A, 1) == BandedMatrices.colstop(A, 2) == 0
411+
@test BandedMatrices.colstop(A, 3) == 1
408412

413+
A = brand(3,4,2,-2)
414+
@test BandedMatrices.rowstop(A, 1) == BandedMatrices.rowstop(A, 2) == 0
415+
@test BandedMatrices.rowstop(A, 3) == 1
409416

410417
# test trivial convert routines
411418

0 commit comments

Comments
 (0)