Skip to content

Commit fd8a2ee

Browse files
authored
LU with empty matrices (#263)
* LU with empty matrices * Add \ tests
1 parent 59f8620 commit fd8a2ee

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
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 = "0.17.3"
3+
version = "0.17.4"
44

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

src/banded/BandedLU.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ function lu!(A::BandedMatrix{T}, pivot::Union{Val{false}, Val{true}} = Val(true)
8484
end
8585
m= size(A,1)
8686
l,u = bandwidths(A) # l of the bands are ignored and overwritten
87-
_, ipiv = LAPACK.gbtrf!(l, u-l, m, bandeddata(A))
87+
if !iszero(m)
88+
_, ipiv = LAPACK.gbtrf!(l, u-l, m, bandeddata(A))
89+
else
90+
ipiv = Int[]
91+
end
8892
return BandedLU{T,typeof(A)}(A, ipiv, zero(BlasInt))
8993
end
9094

src/banded/linalg.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ function ldiv!(A::BandedLU{T,<:BandedMatrix}, B::StridedVecOrMat{T}) where {T<:B
2525
m = size(A.factors,1)
2626
l,u = bandwidths(A.factors)
2727
data = bandeddata(A.factors)
28-
LAPACK.gbtrs!('N', l, u-l, m, data, A.ipiv, B)
28+
iszero(m) || LAPACK.gbtrs!('N', l, u-l, m, data, A.ipiv, B)
29+
B
2930
end
3031

3132
function ldiv!(A::BandedLU{T}, B::AbstractVecOrMat{Complex{T}}) where T<:Real

test/test_bandedlu.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,13 @@ struct _foo <: Number end
151151
@test_throws BoundsError size(BLU, -1)
152152
@test_throws BoundsError size(BLU, 0)
153153
end
154+
155+
@testset "zero matrix" begin
156+
for A in (BandedMatrix{Float64}(undef, 0,0, 1,1),
157+
BandedMatrix{Float64}(undef, 0,3, 1,1),
158+
BandedMatrix{Float64}(undef, 0,0, -1,-2))
159+
@test lu(A).factors == zeros(size(A)...)
160+
@test lu(A) \ zeros(0) == zeros(0)
161+
end
162+
end
154163
end

0 commit comments

Comments
 (0)