A ^ T *稀疏产品,结果存储在密集矩阵/ Eigen Lib中

时间:2015-05-31 16:55:42

标签: c++ eigen eigen3

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

如果我想将结果存储到Dense矩阵中。 DATA = ...,它返回非常奇怪的修剪功能错误。

  1. 小问题:
  2. 如果我在动态分配中只将.triangularView<Lower>();这个商店用在(ATA OR DATA)的堆n/2+n个元素中?

    LOG:

    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 ****
    

1 个答案:

答案 0 :(得分:1)

为了将来参考,如果你准备一个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;
}