根据我的问题,我想跟进并从 spqr 过程的输出以(内存)有效的方式计算 Q 矩阵。到目前为止,似乎只实现了 matrix() 。但是,我只需要稀疏格式的 Q 矩阵,没有足够的内存稍后将其转换为稀疏矩阵:
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)
输出:
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)
不幸的是,我在标准库中找不到执行 Matrix(FQ) 的例程,否则我可以自己用稀疏的方式替换它。
最好的,
五。