Skip to content

Commit

Permalink
Merge pull request JuliaLang#11240 from JuliaLang/teh/qrfact
Browse files Browse the repository at this point in the history
Make qrfact and qrfact! type-stable
  • Loading branch information
andreasnoack committed May 12, 2015
2 parents e528bc0 + f01a63d commit a44b31c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion base/linalg/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ function qrfact!{T}(A::AbstractMatrix{T}, pivot::Union(Type{Val{false}}, Type{Va
end
QR(A, τ)
end
qrfact!{T<:BlasFloat}(A::StridedMatrix{T}, pivot::Union(Type{Val{false}}, Type{Val{true}})=Val{false}) = pivot==Val{true} ? QRPivoted(LAPACK.geqp3!(A)...) : QRCompactWY(LAPACK.geqrt!(A, min(minimum(size(A)), 36))...)
qrfact!{T<:BlasFloat}(A::StridedMatrix{T}, pivot::Type{Val{false}} = Val{false}) = QRCompactWY(LAPACK.geqrt!(A, min(minimum(size(A)), 36))...)
qrfact!{T<:BlasFloat}(A::StridedMatrix{T}, pivot::Type{Val{true}}) = QRPivoted(LAPACK.geqp3!(A)...)
qrfact{T<:BlasFloat}(A::StridedMatrix{T}, pivot::Union(Type{Val{false}}, Type{Val{true}})=Val{false}) = qrfact!(copy(A), pivot)
copy_oftype{T}(A::StridedMatrix{T}, ::Type{T}) = copy(A)
copy_oftype{T,S}(A::StridedMatrix{T}, ::Type{S}) = convert(AbstractMatrix{S}, A)
Expand Down
8 changes: 6 additions & 2 deletions test/linalg1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ debug && println("Bunch-Kaufman factors of a pos-def matrix")
debug && println("QR decomposition (without pivoting)")
for i = 1:2
let a = i == 1 ? a : sub(a, 1:n - 1, 1:n - 1), b = i == 1 ? b : sub(b, 1:n - 1), n = i == 1 ? n : n - 1
qra = qrfact(a, Val{false})
@inferred qrfact(a)
if eltya <: BlasFloat
@inferred qrfact(a, Val{true})
end
qra = @inferred qrfact(a, Val{false})
q, r = qra[:Q], qra[:R]
@test_throws KeyError qra[:Z]
@test_approx_eq q'*full(q, thin = false) eye(n)
Expand All @@ -69,7 +73,7 @@ debug && println("QR decomposition (without pivoting)")
@test_approx_eq full(qra) a

debug && println("Thin QR decomposition (without pivoting)")
qra = qrfact(a[:,1:n1], Val{false})
qra = @inferred qrfact(a[:,1:n1], Val{false})
q,r = qra[:Q], qra[:R]
@test_throws KeyError qra[:Z]
@test_approx_eq q'*full(q, thin=false) eye(n)
Expand Down

0 comments on commit a44b31c

Please sign in to comment.