Skip to content

Commit 33a2c2b

Browse files
jagotdlfivefifty
authored andcommitted
Support complex QR/QL properly (fixes #35) (#36)
1 parent 473fa5a commit 33a2c2b

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

src/blockskylineqr.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ _qrf!(::AbstractColumnMajor,::AbstractStridedLayout,A::AbstractMatrix{T},τ::Abs
33
LAPACK.geqrf!(A,τ)
44
_apply_qr!(::AbstractColumnMajor, ::AbstractStridedLayout, ::AbstractStridedLayout, A::AbstractMatrix{T}, τ::AbstractVector{T}, B::AbstractVecOrMat{T}) where T<:BlasReal =
55
LAPACK.ormqr!('L','T',A,τ,B)
6+
_apply_qr!(::AbstractColumnMajor, ::AbstractStridedLayout, ::AbstractStridedLayout, A::AbstractMatrix{T}, τ::AbstractVector{T}, B::AbstractVecOrMat{T}) where T<:BlasComplex =
7+
LAPACK.ormqr!('L','C',A,τ,B)
68
apply_qr!(A, τ, B) = _apply_qr!(MemoryLayout(A), MemoryLayout(τ), MemoryLayout(B), A, τ, B)
79

810
qlf!(A,τ) = _qlf!(MemoryLayout(A),MemoryLayout(τ),A,τ)
911
_qlf!(::AbstractColumnMajor,::AbstractStridedLayout,A::AbstractMatrix{T}::AbstractVector{T}) where T<:BlasFloat =
1012
LAPACK.geqlf!(A,τ)
1113
_apply_ql!(::AbstractColumnMajor, ::AbstractStridedLayout, ::AbstractStridedLayout, A::AbstractMatrix{T}, τ::AbstractVector{T}, B::AbstractVecOrMat{T}) where T<:BlasReal =
1214
LAPACK.ormql!('L','T',A,τ,B)
15+
_apply_ql!(::AbstractColumnMajor, ::AbstractStridedLayout, ::AbstractStridedLayout, A::AbstractMatrix{T}, τ::AbstractVector{T}, B::AbstractVecOrMat{T}) where T<:BlasComplex =
16+
LAPACK.ormql!('L','C',A,τ,B)
1317
apply_ql!(A, τ, B) = _apply_ql!(MemoryLayout(A), MemoryLayout(τ), MemoryLayout(B), A, τ, B)
1418

1519
function qr!(A::BlockBandedMatrix{T}) where T

test/test_blockskylineqr.jl

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ using BlockBandedMatrices, LinearAlgebra, MatrixFactorizations
1414
Q̃,R̃ = qr(Matrix(A))
1515
@test R
1616
@test Q
17-
17+
1818
b = randn(size(A,1))
1919
@test Q'b 'b
2020
@test Q*b *b
21-
21+
2222
@test F\b ldiv!(F, copy(b)) Matrix(A)\b A\b
2323
end
2424

@@ -35,13 +35,13 @@ using BlockBandedMatrices, LinearAlgebra, MatrixFactorizations
3535
Q̃,R̃ = qr(Matrix(A))
3636
@test R
3737
@test Q
38-
38+
3939
b = randn(size(A,1))
4040
@test Q'b 'b
4141
@test Q*b *b
4242

4343
@test Q'b lmul!(Q', copy(b)) '*b
44-
44+
4545
@test F\b ldiv!(F, copy(b))[1:15] Matrix(A)\b A\b
4646
end
4747

@@ -58,13 +58,13 @@ using BlockBandedMatrices, LinearAlgebra, MatrixFactorizations
5858
Q̃,R̃ = qr(Matrix(A))
5959
@test R
6060
@test Q
61-
61+
6262
b = randn(size(A,1))
6363
@test Q'b 'b
6464
@test Q*b *b
6565
Q'b
6666
# @test_broken DimensionMismatch ldiv!(F, copy(b))
67-
67+
6868
@test_broken F\b ldiv!(F, copy(b)) Matrix(A)\b A\b
6969
end
7070

@@ -81,7 +81,7 @@ using BlockBandedMatrices, LinearAlgebra, MatrixFactorizations
8181
Q̃,L̃ = ql(Matrix(A))
8282
@test L
8383
@test Q
84-
84+
8585
b = randn(size(A,1))
8686
@test Q'b 'b
8787
@test Q*b *b
@@ -103,7 +103,7 @@ using BlockBandedMatrices, LinearAlgebra, MatrixFactorizations
103103
# Q̃,L̃ = ql(Matrix(A))
104104
# @test L ≈ L̃
105105
# @test Q ≈ Q̃
106-
106+
107107
# b = randn(size(A,1))
108108
# @test Q'b ≈ Q̃'b
109109
# @test Q*b ≈ Q̃*b
@@ -120,13 +120,31 @@ using BlockBandedMatrices, LinearAlgebra, MatrixFactorizations
120120
@test_throws ArgumentError ql(A)
121121
end
122122

123-
@testset "Complex QR" begin
124-
A=BlockBandedMatrix{Float64}(I, ([1,1],[1,1]), (0,0))
125-
Af=qr(A)
126-
B=BlockBandedMatrix{ComplexF64}(I, ([1,1],[1,1]), (0,0))
127-
Bf=qr(B)
128-
@test Af.factors == Bf.factors
129-
@test Af.τ == Bf.τ
123+
@testset "Complex QR/QL" begin
124+
@testset "Simple" begin
125+
A=BlockBandedMatrix{Float64}(I, ([1,1],[1,1]), (0,0))
126+
Af=qr(A)
127+
B=BlockBandedMatrix{ComplexF64}(I, ([1,1],[1,1]), (0,0))
128+
Bf=qr(B)
129+
@test Af.factors == Bf.factors
130+
@test Af.τ == Bf.τ
131+
end
132+
133+
@testset "Off-diagonals" begin
134+
for qrl in [qr,ql]
135+
for T in [Float64, ComplexF64]
136+
A = BlockBandedMatrix{T}(undef, ([3,2,1,3],[3,2,1,3]), (1,1))
137+
A.data .= rand(T, size(A.data))
138+
Af = qrl(A)
139+
@test Af.factors isa BlockBandedMatrix
140+
141+
Am = Matrix(A)
142+
Amf = qrl(Am)
143+
144+
@test Af.factors Amf.factors
145+
end
146+
end
147+
end
130148
end
131149
end
132150

@@ -138,4 +156,3 @@ end
138156
# @time F = qr(A); # 11s
139157
# b = randn(size(A,1));
140158
# @time F\b; # 0.6s
141-

0 commit comments

Comments
 (0)