问题描述
对于多个相同的矩阵matA,例如
In the case of multiple of same matrix matA, like
matA.transpose()*matA,
您不必计算所有结果乘积,因为结果矩阵是对称的(因此仅当m> n时),在我的特定情况下始终是对称的!正方形.
You don't have to compute all result product, because the result matrix is symmetric(so only if the m>n), in my specific case is always symmetric! square.
因此仅用于计算就足够了.前任.下三角部分,其余部分仅复制.....,因为第二和第三行的结果分别是col,类似于第三和第二行.....等等....
So its enough the compute only for. ex. lower triangular part and rest only copy..... because the results of the multiple 2nd and 3rd row, resp.col, is the same like 3rd and 2nd.....And etc....
所以我的问题是,存在方式如何告诉Eigen,只计算下部.并有选择地仅将产品保存到较低的trinaguler部分?
So my question is , exist way how to tell Eigen, to compute only lower part. and optionally save to only lower trinaguler part the product?
DATA = SparseMatrix<double>((SparseMatrix<double>(matA.transpose()) * matA).pruned()).toDense();
推荐答案
根据文档,您可以使用以下方法评估矩阵的下三角:
According to the documentation, you can evaluate the lower triangle of a matrix with:
m1.triangularView<Eigen::Lower>() = m2 + m3;
或您的情况:
m1.triangularView<Eigen::Lower>() = matA.transpose()*matA;
(其中写着写到特定的三角形部分:(仅评估引用的三角形部分)").否则,在您写的那一行中本征将计算整个稀疏矩阵matA.transpose()*matA
.
(where it says "Writing to a specific triangular part: (only the referenced triangular part is evaluated)"). Otherwise, in the line you've writtenEigen will calculate the entire sparse matrix matA.transpose()*matA
.
关于保存生成的m1
矩阵,与保存其类型的任何矩阵(Eigen::MatrixXt
或Eigen::SparseMatrix<t>
)相同.如果m1
是稀疏的,则它仅是简单的matA.transpose()*matA
的一半.如果m1
是密集的,则它将是完整的方矩阵.
Regarding saving the resulting m1
matrix, it is the same as saving whatever type of matrix it is (Eigen::MatrixXt
or Eigen::SparseMatrix<t>
). If m1
is sparse, then it will be only half the size of a straightforward matA.transpose()*matA
. If m1
is dense, then it will be the full square matrix.
这篇关于本征库中的稀疏积A ^ T * A最优的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!