Skip to content

Commit

Permalink
missing tests for qr and lq
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt authored and KristofferC committed Apr 11, 2020
1 parent 82542a9 commit 32b1733
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions stdlib/LinearAlgebra/test/lq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ rectangularQ(Q::LinearAlgebra.LQPackedQ) = convert(Array, Q)
@test sprint(show,MIME"text/plain"(),lqa) == "$(typeof(lqa)) with factors L and Q:\n$lstring\n$qstring"
@test LinearAlgebra.Factorization{eltya}(lqa) === lqa
@test Matrix{eltya}(q) isa Matrix{eltya}
# test Array{T}(LQPackedQ{T})
@test Array{eltya}(q) Matrix(q)
end
@testset "Binary ops" begin
@test a*x b rtol=3000ε
Expand Down
29 changes: 29 additions & 0 deletions stdlib/LinearAlgebra/test/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ rectangularQ(Q::LinearAlgebra.AbstractQ) = convert(Array, Q)
rstring = sprint((t, s) -> show(t, "text/plain", s), r)
qstring = sprint((t, s) -> show(t, "text/plain", s), q)
@test qrstring == "$(summary(qra))\nQ factor:\n$qstring\nR factor:\n$rstring"
# iterate
q, r = qra
@test q*r a
# property names
@test Base.propertynames(qra) == (:R, :Q)
end
@testset "Thin QR decomposition (without pivoting)" begin
qra = @inferred qr(a[:, 1:n1], Val(false))
Expand All @@ -82,13 +87,21 @@ rectangularQ(Q::LinearAlgebra.AbstractQ) = convert(Array, Q)
@test q*r a[:, 1:n1]
@test q*b[1:n1] rectangularQ(q)*b[1:n1] atol=100ε
@test q*b squareQ(q)*b atol=100ε
if eltya != Int
@test Array{eltya}(q) Matrix(q)
end
@test_throws DimensionMismatch q*b[1:n1 + 1]
@test_throws DimensionMismatch b[1:n1 + 1]*q'
sq = size(q.factors, 2)
@test *(UpperTriangular(Matrix{eltyb}(I, sq, sq)), adjoint(q))*squareQ(q) Matrix(I, n1, a_1) atol=5000ε
if eltya != Int
@test Matrix{eltyb}(I, a_1, a_1)*q convert(AbstractMatrix{tab},q)
end
# iterate
q, r = qra
@test q*r a[:, 1:n1]
# property names
@test Base.propertynames(qra) == (:R, :Q)
end
@testset "(Automatic) Fat (pivoted) QR decomposition" begin
@inferred qr(a, Val(true))
Expand All @@ -106,11 +119,19 @@ rectangularQ(Q::LinearAlgebra.AbstractQ) = convert(Array, Q)
@test q*r*transpose(qrpa.P) a[1:n1,:]
@test a[1:n1,:]*(qrpa\b[1:n1]) b[1:n1] atol=5000ε
@test Array(qrpa) a[1:5,:]
if eltya != Int
@test Array{eltya}(q) Matrix(q)
end
@test_throws DimensionMismatch q*b[1:n1+1]
@test_throws DimensionMismatch b[1:n1+1]*q'
if eltya != Int
@test Matrix{eltyb}(I, n1, n1)*q convert(AbstractMatrix{tab},q)
end
# iterate
q, r, p = qrpa
@test q*r[:,invperm(p)] a[1:n1,:]
# property names
@test Base.propertynames(qrpa) == (:R, :Q, :p, :P)
end
@testset "(Automatic) Thin (pivoted) QR decomposition" begin
qrpa = factorize(a[:,1:n1])
Expand All @@ -122,6 +143,9 @@ rectangularQ(Q::LinearAlgebra.AbstractQ) = convert(Array, Q)
@test q*r a[:,p]
@test q*r[:,invperm(p)] a[:,1:n1]
@test Array(qrpa) a[:,1:5]
if eltya != Int
@test Array{eltya}(q) Matrix(q)
end
@test_throws DimensionMismatch q*b[1:n1+1]
@test_throws DimensionMismatch b[1:n1+1]*q'
sq = size(q.factors, 2)
Expand All @@ -134,6 +158,11 @@ rectangularQ(Q::LinearAlgebra.AbstractQ) = convert(Array, Q)
qstring = sprint((t, s) -> show(t, "text/plain", s), q)
pstring = sprint((t, s) -> show(t, "text/plain", s), p)
@test qrstring == "$(summary(qrpa))\nQ factor:\n$qstring\nR factor:\n$rstring\npermutation:\n$pstring"
# iterate
q, r, p = qrpa
@test q*r[:,invperm(p)] a[:,1:n1]
# property names
@test Base.propertynames(qrpa) == (:R, :Q, :p, :P)
end
end
if eltya != Int
Expand Down

0 comments on commit 32b1733

Please sign in to comment.