I am trying to construct a sparse matrix L of the form
我正在尝试构造一个表格的稀疏矩阵L.
L
and Hi
are respectively a very sparse matrix and row vector. The final L matrix should have a density of around 1 % .
L和Hi分别是非常稀疏的矩阵和行向量。最终的L矩阵应具有约1%的密度。
Armadillo provides a arma::sp_mat
class that seems to suit my needs. The assembly of L
then looks like this
Armadillo提供了一个似乎符合我需求的arma :: sp_mat类。然后L的组装看起来像这样
arma::sp_mat L(N,N);
arma::sp_mat Hi(1,N);
for (int i = 0; i < p; ++ i){
// The non-zero terms in Hi are populated here
L += Hi.t() * Hi;
}
The number of non-zero elements in Hi
is constant with i
. I do not have much experience with sparse matrices but I was expecting the incremental assembly of L
to be relatively constant in speed.
Hi中的非零元素数量与i不变。我对稀疏矩阵没有多少经验,但我期望L的增量装配速度相对恒定。
Yet, it seems that the speed at which Hi.t() * Hi
is added to L
decreases over time. Am I doing something wrong in the way I assemble L
? Should I preconstruct L
by specifying which of its components I know will not be zero?
然而,似乎Hi.t()* Hi加到L的速度随着时间的推移而降低。我组装L的方式有问题吗?我应该通过指定我知道哪些组件不会为零来预构建L?
1 个解决方案
#1
0
It seems that L
is not initialized so that it effectively changes size when incremented with Hi.t() * Hi
. This was likely the cause for the decrease in the speed.
似乎L未初始化,因此当使用Hi.t()* Hi递增时它会有效地改变大小。这可能是速度下降的原因。
#1
0
It seems that L
is not initialized so that it effectively changes size when incremented with Hi.t() * Hi
. This was likely the cause for the decrease in the speed.
似乎L未初始化,因此当使用Hi.t()* Hi递增时它会有效地改变大小。这可能是速度下降的原因。