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
4 changes: 2 additions & 2 deletions src/abstractq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ QRPackedQ(factors::AbstractMatrix{T}, τ::AbstractVector{T}) where {T} =
QRPackedQ{T,typeof(factors),typeof(τ)}(factors, τ)
QRPackedQ{T}(factors::AbstractMatrix, τ::AbstractVector) where {T} =
QRPackedQ(convert(AbstractMatrix{T}, factors), convert(AbstractVector{T}, τ))
QRPackedQ{T}(Q::QRPackedQ) where {T} = QRPackedQ{T}(Q.factors, Q.τ)
# backwards-compatible constructors (remove with Julia 2.0)
@deprecate(QRPackedQ{T,S}(factors::AbstractMatrix{T}, τ::AbstractVector{T}) where {T,S},
QRPackedQ{T,S,typeof(τ)}(factors, τ), false)
Expand All @@ -300,12 +301,11 @@ QRCompactWYQ(factors::AbstractMatrix{S}, T::AbstractMatrix{S}) where {S} =
QRCompactWYQ{S,typeof(factors),typeof(T)}(factors, T)
QRCompactWYQ{S}(factors::AbstractMatrix, T::AbstractMatrix) where {S} =
QRCompactWYQ(convert(AbstractMatrix{S}, factors), convert(AbstractMatrix{S}, T))
QRCompactWYQ{S}(Q::QRCompactWYQ) where {S} = QRCompactWYQ{S}(Q.factors, Q.T)
# backwards-compatible constructors (remove with Julia 2.0)
@deprecate(QRCompactWYQ{S,M}(factors::AbstractMatrix{S}, T::AbstractMatrix{S}) where {S,M},
QRCompactWYQ{S,M,typeof(T)}(factors, T), false)

QRPackedQ{T}(Q::QRPackedQ) where {T} = QRPackedQ(convert(AbstractMatrix{T}, Q.factors), convert(AbstractVector{T}, Q.τ))
QRCompactWYQ{S}(Q::QRCompactWYQ) where {S} = QRCompactWYQ(convert(AbstractMatrix{S}, Q.factors), convert(AbstractMatrix{S}, Q.T))

# override generic square fallback
Matrix{T}(Q::Union{QRCompactWYQ{S},QRPackedQ{S}}) where {T,S} =
Expand Down
4 changes: 4 additions & 0 deletions test/abstractq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ n = 5
F = qr(A)
Q = MyQ(F.Q)
@test ndims(Q) == 2
@test eltype([A, Q]) == Union{AbstractQ{T}, AbstractMatrix{T}} # promotion
T <: Real && @test transpose(Q) == adjoint(Q)
T <: Complex && @test_throws ErrorException transpose(Q)
@test convert(AbstractQ{complex(T)}, Q) isa MyQ{complex(T)}
@test convert(AbstractQ{complex(T)}, Q') isa AdjointQ{<:complex(T),<:MyQ{complex(T)}}
@test Q == Matrix(Q) == Q
@test Q ≈ Matrix(Q) ≈ Q
@test *(Q) == Q
@test Q*I ≈ Q.Q*I rtol=2eps(real(T))
@test Q'*I ≈ Q.Q'*I rtol=2eps(real(T))
Expand All @@ -47,6 +50,7 @@ n = 5
@test (Q')^2 ≈ Q'*Q'
@test abs(det(Q)) ≈ 1
@test logabsdet(Q)[1] ≈ 0 atol=2n*eps(real(T))
@test logdet(Q) ≈ log(sign(det(Q)))
y = rand(T, n)
@test Q * y ≈ Q.Q * y ≈ Q' \ y ≈ ldiv!(Q', copy(y)) ≈ ldiv!(zero(y), Q', y)
@test Q'y ≈ Q.Q' * y ≈ Q \ y ≈ ldiv!(Q, copy(y)) ≈ ldiv!(zero(y), Q, y)
Expand Down
8 changes: 8 additions & 0 deletions test/hessenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,12 @@ end
end
end

@testset "Hessenberg factorization of Q" begin
for T in (Float32, Float64, ComplexF32, ComplexF64)
Q1, H1 = hessenberg(randn(T,5,5))
Q2, H2 = hessenberg(Q1)
@test Q2'Q2 ≈ I
end
end

end # module TestHessenberg
9 changes: 9 additions & 0 deletions test/lq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,13 @@ end

end

@testset "LQ factorization of Q" begin
for T in (Float32, Float64, ComplexF32, ComplexF64)
L1, Q1 = lq(randn(T, 5, 5))
L2, Q2 = lq(Q1)
@test Matrix(Q1) ≈ Matrix(Q2)
@test L2 ≈ I
end
end

end # module TestLQ
Loading