Skip to content

Add applyqr! for non-BLAS types #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 16, 2021
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "BlockBandedMatrices"
uuid = "ffab5731-97b5-5995-9138-79e8c1846df0"
version = "0.11"
version = "0.11.1"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand All @@ -17,7 +17,7 @@ ArrayLayouts = "0.7"
BandedMatrices = "0.16.8"
BlockArrays = "0.16.6"
FillArrays = "0.11, 0.12"
MatrixFactorizations = "0.7.1, 0.8"
MatrixFactorizations = "0.8.5"
julia = "1.6"

[extras]
Expand Down
8 changes: 3 additions & 5 deletions src/blockskylineqr.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
qrf!(A,τ) = _qrf!(MemoryLayout(A),MemoryLayout(τ),A,τ)
_qrf!(::AbstractColumnMajor,::AbstractStridedLayout,A::AbstractMatrix{T},τ::AbstractVector{T}) where T<:BlasFloat =
LAPACK.geqrf!(A,τ)
_apply_qr!(::AbstractColumnMajor, ::AbstractStridedLayout, ::AbstractStridedLayout, A::AbstractMatrix{T}, τ::AbstractVector{T}, B::AbstractVecOrMat{T}) where T<:BlasReal =
LAPACK.ormqr!('L','T',A,τ,B)
_apply_qr!(::AbstractColumnMajor, ::AbstractStridedLayout, ::AbstractStridedLayout, A::AbstractMatrix{T}, τ::AbstractVector{T}, B::AbstractVecOrMat{T}) where T<:BlasComplex =
LAPACK.ormqr!('L','C',A,τ,B)
_apply_qr!(_, _, _, A::AbstractMatrix, τ::AbstractVector, B::AbstractVecOrMat) = lmul!(MatrixFactorizations.QRPackedQ(A, τ)', B)
apply_qr!(A, τ, B) = _apply_qr!(MemoryLayout(A), MemoryLayout(τ), MemoryLayout(B), A, τ, B)

qlf!(A,τ) = _qlf!(MemoryLayout(A),MemoryLayout(τ),A,τ)
Expand All @@ -30,7 +28,7 @@ function _blockbanded_qr!(A::AbstractMatrix, τ::AbstractVector, NCOLS::Block{1}
KR = K:min(K+l,M)
V = view(A,KR,K)
t = view(τ,K)
qrf!(V,t)
MatrixFactorizations.qrfactUnblocked!(V,t)
for J = K+1:min(K+u,N)
apply_qr!(V, t, view(A,KR,J))
end
Expand All @@ -41,7 +39,7 @@ end
function qr!(A::BlockBandedMatrix{T}) where T
M,N = blocksize(A)
ax1 = M < N ? axes(A,1) : axes(A,2)
_blockbanded_qr!(A, PseudoBlockVector{T}(undef, (ax1,)))
_blockbanded_qr!(A, PseudoBlockVector(zeros(T,length(ax1)), (ax1,)))
end

function ql!(A::BlockBandedMatrix{T}) where T
Expand Down
9 changes: 9 additions & 0 deletions test/test_blockskylineqr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ import BlockBandedMatrices: blockcolsupport
B = [Matrix(I,2,2); zeros(size(T,1)-2,2)]
@test ((T - z*I)\b)[1] ≈ (F\b)[1] ≈ (F \ B)[1,1] ≈ ((T - z*I)\B)[1,1] ≈ -0.1309123477325813 + 0.28471699370329884im
end

@testset "BigFloat QR" begin
N = 5
A = BlockBandedMatrix{BigFloat}(undef, 1:N,1:N, (2,1))
A.data .= randn.()
@test qr(A).Q ≈ qr(Float64.(A)).Q
b = randn(size(A,1))
@test qr(A .+ 0im)\b ≈ qr(A)\b ≈ A\b
end
end


Expand Down