Recovering Q from packed Q (spqr, in a sparse way)

78 views Asked by At

following from my question I would like to follow up and calculate the Q matrix in an (memory) efficient way from the output of the spqr procedure. Up to now, only matrix() seems to be implemented. However, I only need the Q matrix in a sparse format, there is not enough memory to convert it to a sparse matrix later:

using LinearAlgebra, SparseArrays
N  = 500
ns = 3
d = 0.0001
A = sprand(N,N-ns,d)
H = A*A'
println("eigen")
@time eigen(Matrix(H))
println("qr")
@time F = qr(H)
println("Matrix(F.Q)")
@time Q = Matrix(F.Q)
println("sparse(Q)")
@time sparse(Q)
println("sparse(F.Q)")
@time sparse(F.Q)

Output:

eigen
  0.046383 seconds (22 allocations: 7.810 MiB)
qr
  0.000479 seconds (649 allocations: 125.533 KiB)
Matrix(F.Q)
  0.000454 seconds (508 allocations: 1.931 MiB)
sparse(Q)
  0.000371 seconds (9 allocations: 12.406 KiB)
sparse(F.Q)
  1.355230 seconds (1.50 M allocations: 1.982 GiB, 33.47% gc time)

Unfortunatelly I could not find the routine in the standard library which performs Matrix(F.Q), otherwise I could replace it in a sparse way by myself.

Best,

v.

1

There are 1 answers

0
Andreas Noack On

Generally, Q won't be sparse so I don't think neither we nor SuiteSparse provide such a function. You might able to write one based on the sparse reflectors in the Q struct.