Motivation: I want an orthonormal basis for the support of a matrix, and a basis for the perpendicular space. The surrounding code looks like this:
q = qr(mat, Val(true))
take = [norm(x) >= tol for x in eachrow(q.R)]
qQ = Array(q.Q)
resize!(take, size(qQ)[2])
support = qQ[:,take]
perp = qQ[:,.!take]
It works if I don’t cast q.Q to an Array, but the indexing operations are then very slow.
The Q matrix is not stored explicitly in a QR decomposition. It is in a form (a set of elementary reflectors, also called Householder transformations) in which it is easy to compute Q times an array or Q’ times an array. If you really want the whole Q to create a basis, as you say, you may find that just multiplying Q by the identity is the easiest approach.
It seems to me that julia could do better here by improving support for Array(qr.Q) and qr.Q * I. I think I’ll file a bug report. Thanks for the hints.