A^T*A 稀疏积,结果存储在密集矩阵/特征库中

A^T*A sparse product, results Store in Dense Matrix / Eigen Lib

SparseMatrix<double> matA(rows, cols);
SparseMatrix<double> ATA(rows, cols);
...
ATA = (SparseMatrix<double>(matA.transpose()) * matA).pruned();
//.triangularView<Lower>();

如果我想将结果存储到 ex 的密集矩阵中。 DATA = ...,它 returns 非常奇怪的修剪函数错误。

  1. 小问题:

如果我在动态分配中仅使用 .triangularView<Lower>(); 堆中的 n/2+n 个元素(ATA OR DATA)?

日志:

jni/Eigen/src/SparseCore/SparseSparseProductWithPruning.h: In function 'void Eigen::internal::sparse_sparse_product_with_pruning_impl(const Lhs&, const Rhs&, ResultType&, const typename ResultType::RealScalar&) [with Lhs = Eigen::SparseMatrix<double>, Rhs = Eigen::SparseMatrix<double>, ResultType = Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>, typename ResultType::RealScalar = double]':
jni/Eigen/src/SparseCore/SparseSparseProductWithPruning.h:91:5:   instantiated from 'static void Eigen::internal::sparse_sparse_product_with_pruning_selector<Lhs, Rhs, ResultType, 0, 0, 0>::run(const Lhs&, const Rhs&, ResultType&, const RealScalar&) [with Lhs = Eigen::SparseMatrix<double>, Rhs = Eigen::SparseMatrix<double>, ResultType = Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>, Eigen::internal::sparse_sparse_product_with_pruning_selector<Lhs, Rhs, ResultType, 0, 0, 0>::RealScalar = double]'
jni/Eigen/src/SparseCore/SparseProduct.h:121:9:   instantiated from 'void Eigen::SparseSparseProduct<Lhs, Rhs>::evalTo(Dest&) const [with Dest = Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>, LhsNested = Eigen::SparseMatrix<double>, RhsNested = const Eigen::SparseMatrix<double>&]'
jni/Eigen/src/Core/Assign.h:522:101:   instantiated from 'static Derived& Eigen::internal::assign_selector<Derived, OtherDerived, false, false>::evalTo(ActualDerived&, const ActualOtherDerived&) [with ActualDerived = Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>, ActualOtherDerived = Eigen::SparseSparseProduct<Eigen::SparseMatrix<double>, const Eigen::SparseMatrix<double>&>, Derived = Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>, OtherDerived = Eigen::SparseSparseProduct<Eigen::SparseMatrix<double>, const Eigen::SparseMatrix<double>&>]'
jni/Eigen/src/Core/Assign.h:571:98:   instantiated from 'Derived& Eigen::MatrixBase<Derived>::operator=(const Eigen::EigenBase<OtherDerived>&) [with OtherDerived = Eigen::SparseSparseProduct<Eigen::SparseMatrix<double>, const Eigen::SparseMatrix<double>&>, Derived = Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>]'
jni/Eigen/src/Core/PlainObjectBase.h:453:7:   instantiated from 'Derived& Eigen::PlainObjectBase<Derived>::operator=(const Eigen::EigenBase<OtherDerived>&) [with OtherDerived = Eigen::SparseSparseProduct<Eigen::SparseMatrix<double>, const Eigen::SparseMatrix<double>&>, Derived = Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>]'
jni/Eigen/src/Core/Matrix.h:184:35:   instantiated from 'Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::operator=(const Eigen::EigenBase<OtherDerived>&) [with OtherDerived = Eigen::SparseSparseProduct<Eigen::SparseMatrix<double>, const Eigen::SparseMatrix<double>&>, _Scalar = double, int _Rows = -0x00000000000000001, int _Cols = -0x00000000000000001, int _Options = 0, int _MaxRows = -0x00000000000000001, int _MaxCols = -0x00000000000000001, Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> = Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>]'
jni/After.cpp:429:36:   instantiated from here
jni/Eigen/src/SparseCore/SparseSparseProductWithPruning.h:50:3: error: 'class Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>' has no member named 'reserve'
jni/Eigen/src/SparseCore/SparseSparseProductWithPruning.h:69:5: error: 'class Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>' has no member named 'startVec'
jni/Eigen/src/SparseCore/SparseSparseProductWithPruning.h:71:7: error: 'class Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>' has no member named 'insertBackByOuterInner'
jni/Eigen/src/SparseCore/SparseSparseProductWithPruning.h:73:3: error: 'class Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>' has no member named 'finalize'
make.exe: *** [obj/local/armeabi-v7a/objs/com_jp_algi_CoreC/After.o] Error 1

**** Build Finished ****

为了将来参考,如果您准备好我在下面所做的 Minimal, Complete, and Verifiable example,人们会更容易帮助您(以及您帮助自己)。对我来说,它帮助我理解了你想问的问题。对你来说,它会帮助你更好地理解你的问题,甚至可能解决它。

int main(int argc, char *argv[])
{
    SparseMatrix<double> a(3,3), ata;
    a.coeffRef(1,2) = 0.;
    a.coeffRef(1,1) = 2.;
    a.coeffRef(1,0) = 6.;
    a.coeffRef(0,1) = 1.;
    cout << a << endl;
    ata = (a.transpose() * a).pruned();
    cout << ata << endl;
    ata = (SparseMatrix<double>(a.transpose()) * a).pruned();
    cout << ata << endl;
    MatrixXd dense = ata.toDense();
    cout << dense << endl;
    /*****************************************************/
    // Everything works fine until this point
    /*****************************************************/

    //dense = (SparseMatrix<double>(a.transpose()) * a).pruned(); // Doesn't compile

    // Would compile if written as the following line
    dense = SparseMatrix<double>((SparseMatrix<double>(a.transpose()) * a).pruned()).toDense(); // Works
    cout << dense << endl;
    return 0;
}