JuliaLang/julia — pull request #7888 by timholy (2014-08-07 09:57:51+00:00)
Title: Speed up A_ldiv_B! for QR factorizations

This partially fixes #7887, approximately doubling the performance. For matrices of size 10x3, now `A_ldiv_B!` is not slower than computing the factorization in the first place (although they're still in the same ballpark, unfortunately). It will get much faster yet with better array views (sub is now by far the major bottleneck).

The major benefit is from eliminating calls to `cat`, however I noticed that the type instability of `A[:Q]` was also a noteworthy problem. Hence the `getq` method. An alternative would be to introduce a new type
```
immutable FactorizationComponent{S} end
```
and use it this way:
```julia
julia> A = rand(10,3); F = qrfact(A);

julia> immutable FactorizationComponent{S} end

julia> import Base.LinAlg: QRCompactWY, QRCompactWYQ

julia> import Base: getindex

julia> getindex(A::QRCompactWY, ::Type{FactorizationComponent{:Q}}) = QRCompactWYQ(A.factors,A.T)
getindex (generic function with 171 methods)

julia> i = FactorizationComponent{:Q}
FactorizationComponent{:Q} (constructor with 1 method)

julia> Base.return_types(getindex, typeof((F, :Q)))
1-element Array{Any,1}:
Union(QRCompactWYQ{Float64},Array{Float64,2})

julia> Base.return_types(getindex, typeof((F, i)))
1-element Array{Any,1}:
QRCompactWYQ{Float64}
```