Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/FastAlmostBandedMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ function _almostbanded_qr(_, A)
# Expand the bandsize for the QR factorization
## Bypass the safety checks in `AlmostBandedMatrix`
return almostbanded_qr!(
AlmostBandedMatrix{eltype(A)}(BandedMatrix(copy(B), (l, l + u)), copy(L)), Val(true)
AlmostBandedMatrix{eltype(A)}(BandedMatrix(copy(B), (l, l + u)), Matrix(L)), Val(true)
)
end

Expand Down Expand Up @@ -641,7 +641,8 @@ end

@views function _almostbanded_qr!(A::AbstractMatrix, τ::AbstractVector, ncols::Int)
T = eltype(A)
B, L = bandpart(A), fillpart(A)
B = bandpart(A)
L = convert(Matrix{T}, fillpart(A))
l, u = bandwidths(B)
m, n = size(A)
mf = size(L, 1)
Expand Down
28 changes: 28 additions & 0 deletions test/core_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,31 @@ end
fill!(A1, BigFloat(0.0))
@test length(A1.fill.nzval) == 2
end

@safetestset "QR with a sparse boundary block" begin
using FastAlmostBandedMatrices, LinearAlgebra, SparseArrays

for T in (Float64, ComplexF64), m in (40, 48), storage in (Matrix, sparse)
n = 40
B = BandedMatrix(randn(T, m, n), (3, 2))
B[band(0)] .+= 10
L = zeros(T, 3, n)
L[:, 1:3] = 10Matrix{T}(I, 3, 3)
L[:, (n - 2):n] = randn(T, 3, 3)
A = AlmostBandedMatrix(B, storage(L))
reference = Matrix(A)
b = randn(T, m)
for factorize in (qr, qr!)
F = factorize(copy(A))
U, V = fillpart(F.factors).A, fillpart(F.factors).B
@test U isa Matrix{T}
@test V isa Matrix{T}
@test typeof(F) === typeof(FastAlmostBandedMatrices.ArrayInterface.qr_instance(A))
@test F \ b ≈ reference \ b
@test Matrix(A) == reference
end
F = qr(A)
@test Matrix(A) == reference # non-mutating QR must preserve its input
@test F \ b ≈ reference \ b
end
end
Loading