【发布时间】:2023-03-23 22:49:01
【问题描述】:
从我的question 开始,我想跟进并从 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(F.Q) 的例程,否则我可以自己用稀疏的方式替换它。
最好的,
诉
【问题讨论】:
标签: julia sparse-matrix linear-algebra suitesparse