Skip to content

Commit 121bcbf

Browse files
authored
Allow non-zero fill! if all the entries are in bands (#479)
* Allow non-zero fill! if all the entries are in bands * v1.9.4
1 parent a7cf917 commit 121bcbf

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BandedMatrices"
22
uuid = "aae01518-5342-5314-be14-df237901396f"
3-
version = "1.9.3"
3+
version = "1.9.4"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/banded/BandedMatrix.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,8 +857,19 @@ svdvals(A::BandedMatrix) = svdvals!(copy(A))
857857

858858
## ALgebra and other functions
859859

860+
"""
861+
allinbands(A)
862+
863+
returns true if there are no entries outside the bands.
864+
"""
865+
function allinbands(A)
866+
m,n = size(A)
867+
l,u = bandwidths(A)
868+
m l+1 && n u+1
869+
end
870+
860871
function fill!(A::BandedMatrix, x)
861-
iszero(x) || throw(BandError(A))
872+
iszero(x) || allinbands(A) || throw(BandError(A))
862873
fill!(A.data, x)
863874
A
864875
end

test/test_banded.jl

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -253,23 +253,30 @@ include("mymatrix.jl")
253253
end
254254

255255
@testset "BandedMatrix interface" begin
256-
# check that col/rowstop is ≥ 0
257-
let A = brand(3,4,-2,2)
258-
@test BandedMatrices.colstop(A, 1) == BandedMatrices.colstop(A, 2) == 0
259-
@test BandedMatrices.colstop(A, 3) == 1
260-
end
256+
@testset "check that col/rowstop is ≥ 0" begin
257+
let A = brand(3,4,-2,2)
258+
@test BandedMatrices.colstop(A, 1) == BandedMatrices.colstop(A, 2) == 0
259+
@test BandedMatrices.colstop(A, 3) == 1
260+
end
261261

262-
let A = brand(3,4,2,-2)
263-
@test BandedMatrices.rowstop(A, 1) == BandedMatrices.rowstop(A, 2) == 0
264-
@test BandedMatrices.rowstop(A, 3) == 1
262+
let A = brand(3,4,2,-2)
263+
@test BandedMatrices.rowstop(A, 1) == BandedMatrices.rowstop(A, 2) == 0
264+
@test BandedMatrices.rowstop(A, 3) == 1
265+
end
265266
end
266267

267-
# Test fill!
268-
let B = brand(10,10,1,4)
269-
@test_throws BandError fill!(B, 1.0)
270-
@test_throws BandError fill!(B, 1)
271-
fill!(B, 0)
272-
@test Matrix(B) == zeros(10,10)
268+
@testset "fill!" begin
269+
let B = brand(10,10,1,4)
270+
@test_throws BandError fill!(B, 1.0)
271+
@test_throws BandError fill!(B, 1)
272+
fill!(B, 0)
273+
@test Matrix(B) == zeros(10,10)
274+
end
275+
276+
let B = brand(2,3,1,4)
277+
fill!(B, 1)
278+
@test Matrix(B) == ones(2,3)
279+
end
273280
end
274281
end
275282

0 commit comments

Comments
 (0)