This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Conjugate Gradient fails on assert.

Tags: None
(comma "," separated)
joris31
Registered Member
Posts
6
Karma
0

Conjugate Gradient fails on assert.

Tue Jan 24, 2012 2:35 pm
I'm trying to solve something using the Conjugate Gradient method:
Code: Select all
Eigen::ConjugateGradient< Eigen::SparseMatrix<double> > cg;
cg.compute(iA);
iX = cg.solve(iB);


both iX and iB are of type VectorXd

I'm quite confident the sizes of the matrices and vectors match.

The problem I'm facing is I crash on this assert somewhere in the solve method.

assert:
Code: Select all
assertion failed: (i>=0) && ( ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows()) ||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())) in function Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel, true>::Block(XprType&, typename Eigen::internal::traits<Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel, true> >::Index) [with XprType = Eigen::Matrix<double, -0x00000000000000001, 1, 0, -0x00000000000000001, 1>, int BlockRows = 1, int BlockCols = 1, bool InnerPanel = false] at Eigen/Eigen/src/Core/Block.h:293


stacktrace:
Code: Select all
#4   0x00095a3a in Eigen::internal::assert_fail(char const*, char const*, char const*, int) at .../Eigen/Eigen/src/Core/util/Macros.h:208
#5   0x002a0b83 in Eigen::Block<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 1, 1, false, true>::Block(Eigen::Matrix<double, -1, 1, 0, -1, 1>&, int) ()
#6   0x002a0bd3 in Eigen::DenseBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >::row(int) ()
#7   0x002a2b95 in void Eigen::SparseSelfAdjointTimeDenseProduct<Eigen::SparseMatrix<double, 0, int>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, 1>::scaleAndAddTo<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::Matrix<double, -1, 1, 0, -1, 1>&, double) const ()
#8   0x002a2d2f in void Eigen::ProductBase<Eigen::SparseSelfAdjointTimeDenseProduct<Eigen::SparseMatrix<double, 0, int>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, 1>, Eigen::SparseMatrix<double, 0, int>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >::scaleAndAddTo<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::Matrix<double, -1, 1, 0, -1, 1>&, double) const ()
#9   0x002a2d72 in void Eigen::ProductBase<Eigen::SparseSelfAdjointTimeDenseProduct<Eigen::SparseMatrix<double, 0, int>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, 1>, Eigen::SparseMatrix<double, 0, int>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >::evalTo<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::Matrix<double, -1, 1, 0, -1, 1>&) const ()
#10   0x002a2db2 in Eigen::Matrix<double, -1, 1, 0, -1, 1>& Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >::lazyAssign<Eigen::SparseSelfAdjointTimeDenseProduct<Eigen::SparseMatrix<double, 0, int>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, 1>, Eigen::SparseMatrix<double, 0, int>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::ProductBase<Eigen::SparseSelfAdjointTimeDenseProduct<Eigen::SparseMatrix<double, 0, int>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, 1>, Eigen::SparseMatrix<double, 0, int>, Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&) ()
#11   0x002a2e0c in Eigen::Matrix<double, -1, 1, 0, -1, 1>& Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >::lazyAssign<Eigen::SparseSelfAdjointTimeDenseProduct<Eigen::SparseMatrix<double, 0, int>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, 1> >(Eigen::DenseBase<Eigen::SparseSelfAdjointTimeDenseProduct<Eigen::SparseMatrix<double, 0, int>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, 1> > const&) ()
#12   0x002a2e4c in Eigen::internal::assign_selector<Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::SparseSelfAdjointTimeDenseProduct<Eigen::SparseMatrix<double, 0, int>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, 1>, false, false>::run(Eigen::Matrix<double, -1, 1, 0, -1, 1>&, Eigen::SparseSelfAdjointTimeDenseProduct<Eigen::SparseMatrix<double, 0, int>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, 1> const&) ()
#13   0x002a2e8c in Eigen::Matrix<double, -1, 1, 0, -1, 1>& Eigen::NoAlias<Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::MatrixBase>::operator=<Eigen::SparseSelfAdjointTimeDenseProduct<Eigen::SparseMatrix<double, 0, int>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, 1> >(Eigen::MatrixBase<Eigen::SparseSelfAdjointTimeDenseProduct<Eigen::SparseMatrix<double, 0, int>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, 1> > const&) ()
#14   0x002a4b2d in void Eigen::internal::conjugate_gradient<Eigen::SparseSelfAdjointView<Eigen::SparseMatrix<double, 0, int>, 1u>, Eigen::Block<Eigen::Matrix<double, -1, 1, 0, -1, 1> const, -1, 1, true, true>, Eigen::Block<Eigen::Matrix<double, -1, 1, 0, -1, 1>, -1, 1, true, true>, Eigen::DiagonalPreconditioner<double> >(Eigen::SparseSelfAdjointView<Eigen::SparseMatrix<double, 0, int>, 1u> const&, Eigen::Block<Eigen::Matrix<double, -1, 1, 0, -1, 1> const, -1, 1, true, true> const&, Eigen::Block<Eigen::Matrix<double, -1, 1, 0, -1, 1>, -1, 1, true, true>&, Eigen::DiagonalPreconditioner<double> const&, int&, Eigen::Block<Eigen::Matrix<double, -1, 1, 0, -1, 1>, -1, 1, true, true>::RealScalar&) ()
#15   0x002a5236 in void Eigen::ConjugateGradient<Eigen::SparseMatrix<double, 0, int>, 1, Eigen::DiagonalPreconditioner<double> >::_solveWithGuess<Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::Matrix<double, -1, 1, 0, -1, 1> const&, Eigen::Matrix<double, -1, 1, 0, -1, 1>&) const ()
#16   0x002a5350 in void Eigen::ConjugateGradient<Eigen::SparseMatrix<double, 0, int>, 1, Eigen::DiagonalPreconditioner<double> >::_solve<Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::Matrix<double, -1, 1, 0, -1, 1> const&, Eigen::Matrix<double, -1, 1, 0, -1, 1>&) const ()
#17   0x002a5397 in void Eigen::internal::solve_retval<Eigen::ConjugateGradient<Eigen::SparseMatrix<double, 0, int>, 1, Eigen::DiagonalPreconditioner<double> >, Eigen::Matrix<double, -1, 1, 0, -1, 1> >::evalTo<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::Matrix<double, -1, 1, 0, -1, 1>&) const ()
#18   0x002a53c0 in void Eigen::internal::solve_retval_base<Eigen::ConjugateGradient<Eigen::SparseMatrix<double, 0, int>, 1, Eigen::DiagonalPreconditioner<double> >, Eigen::Matrix<double, -1, 1, 0, -1, 1> >::evalTo<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::Matrix<double, -1, 1, 0, -1, 1>&) const ()
#19   0x002a53ea in void Eigen::ReturnByValue<Eigen::internal::solve_retval_base<Eigen::ConjugateGradient<Eigen::SparseMatrix<double, 0, int>, 1, Eigen::DiagonalPreconditioner<double> >, Eigen::Matrix<double, -1, 1, 0, -1, 1> > >::evalTo<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::Matrix<double, -1, 1, 0, -1, 1>&) const ()
#20   0x002a541c in Eigen::Matrix<double, -1, 1, 0, -1, 1>& Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >::operator=<Eigen::internal::solve_retval_base<Eigen::ConjugateGradient<Eigen::SparseMatrix<double, 0, int>, 1, Eigen::DiagonalPreconditioner<double> >, Eigen::Matrix<double, -1, 1, 0, -1, 1> > >(Eigen::ReturnByValue<Eigen::internal::solve_retval_base<Eigen::ConjugateGradient<Eigen::SparseMatrix<double, 0, int>, 1, Eigen::DiagonalPreconditioner<double> >, Eigen::Matrix<double, -1, 1, 0, -1, 1> > > const&) ()
#21   0x002a548b in Eigen::Matrix<double, -1, 1, 0, -1, 1>& Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >::operator=<Eigen::internal::solve_retval_base<Eigen::ConjugateGradient<Eigen::SparseMatrix<double, 0, int>, 1, Eigen::DiagonalPreconditioner<double> >, Eigen::Matrix<double, -1, 1, 0, -1, 1> > >(Eigen::ReturnByValue<Eigen::internal::solve_retval_base<Eigen::ConjugateGradient<Eigen::SparseMatrix<double, 0, int>, 1, Eigen::DiagonalPreconditioner<double> >, Eigen::Matrix<double, -1, 1, 0, -1, 1> > > const&) at .../Eigen/Eigen/src/Core/PlainObjectBase.h:392
#22   0x002a54c0 in Eigen::Matrix<double, -1, 1, 0, -1, 1>& Eigen::Matrix<double, -1, 1, 0, -1, 1>::operator=<Eigen::internal::solve_retval_base<Eigen::ConjugateGradient<Eigen::SparseMatrix<double, 0, int>, 1, Eigen::DiagonalPreconditioner<double> >, Eigen::Matrix<double, -1, 1, 0, -1, 1> > >(Eigen::ReturnByValue<Eigen::internal::solve_retval_base<Eigen::ConjugateGradient<Eigen::SparseMatrix<double, 0, int>, 1, Eigen::DiagonalPreconditioner<double> >, Eigen::Matrix<double, -1, 1, 0, -1, 1> > > const&) at .../Eigen/Eigen/src/Core/Matrix.h:203


Does anybody have an idea what is going wrong?

Thanks a lot
joris31
Registered Member
Posts
6
Karma
0
It only seems to happen when the lower triangle of the A matrix is used. If I explicitly specify to use the upper triangle:
Code: Select all
Eigen::ConjugateGradient< Eigen::SparseMatrix<double>, Eigen::Upper> cg;

the assert isn't fired.

Kind regards
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
How is your matrix? Is it complete, i.e., both the upper and lower parts are stored? only the lower? only the upper?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
either way, I cannot reproduce. Make sure you have the latest development version.

If you still get the issue, could you send us your matrix:

#include <unsupported/Eigen/SparseExtra>

...

saveMarket(iA, "iA.mtx");

and send a gzipped version of the iA.mtx file to me.

thanks
joris31
Registered Member
Posts
6
Karma
0
I'm working with Eigen 3.1.0-alpha1 from the mainpage. Is this the latest version or should I get some version somewhere else. If so, where do I find this version?

The matrix I'm using is completely filled. It is constructed by multiplying the transpose of a SparseMatrix with the SparseMatrix itself.

Thanks
joris31
Registered Member
Posts
6
Karma
0
Solving using SimplicialLDLt does work. But the matrix could grow quite large, so I expect performance issues with this method, which is the reason I would prefer to use the conjugate gradient method.

Regarding a matrix with which I have issues, as I couldn't find your e-mail address immediately and this forums do not allow attachments as far as I know :) I'v copy-pasted the contents of the mtx file here:
Code: Select all
22 22 148
1 1 4.0467060940744698882554075680673122406005859375000000000000000000e+02
1 2 0.0000000000000000000000000000000000000000000000000000000000000000e+00
1 3 -7.6741879471417632885277271270751953125000000000000000000000000000e+01
1 4 2.4666340150362984218190831597894430160522460937500000000000000000e+00
1 19 -2.7636018149649316910654306411743164062500000000000000000000000000e+01
1 20 -3.1328868745033830123247753363102674484252929687500000000000000000e+01
1 21 -6.4424171952960008979971462395042181015014648437500000000000000000e+01
1 22 1.3795308458256652528461927431635558605194091796875000000000000000e+01
2 1 0.0000000000000000000000000000000000000000000000000000000000000000e+00
2 2 4.0467060940744698882554075680673122406005859375000000000000000000e+02
2 3 -2.4666340150362984218190831597894430160522460937500000000000000000e+00
2 4 -7.6741879471417632885277271270751953125000000000000000000000000000e+01
2 19 3.1328868745033830123247753363102674484252929687500000000000000000e+01
2 20 -2.7636018149649316910654306411743164062500000000000000000000000000e+01
2 21 -1.3795308458256652528461927431635558605194091796875000000000000000e+01
2 22 -6.4424171952960008979971462395042181015014648437500000000000000000e+01
3 1 -7.6741879471417632885277271270751953125000000000000000000000000000e+01
3 2 -2.4666340150362984218190831597894430160522460937500000000000000000e+00
3 3 1.4172374091814344865269958972930908203125000000000000000000000000e+02
3 4 0.0000000000000000000000000000000000000000000000000000000000000000e+00
3 5 -6.9238506120225792983546853065490722656250000000000000000000000000e+01
3 6 4.2449276607203678679525182815268635749816894531250000000000000000e+01
3 21 -2.2774146490635754247477962053380906581878662109375000000000000000e+01
3 22 -4.6314247061511501613040309166535735130310058593750000000000000000e+01
4 1 2.4666340150362984218190831597894430160522460937500000000000000000e+00
4 2 -7.6741879471417632885277271270751953125000000000000000000000000000e+01
4 3 0.0000000000000000000000000000000000000000000000000000000000000000e+00
4 4 1.4172374091814344865269958972930908203125000000000000000000000000e+02
4 5 -4.2449276607203678679525182815268635749816894531250000000000000000e+01
4 6 -6.9238506120225792983546853065490722656250000000000000000000000000e+01
4 21 4.6314247061511501613040309166535735130310058593750000000000000000e+01
4 22 -2.2774146490635754247477962053380906581878662109375000000000000000e+01
5 3 -6.9238506120225792983546853065490722656250000000000000000000000000e+01
5 4 -4.2449276607203678679525182815268635749816894531250000000000000000e+01
5 5 1.7166830055246467168217350263148546218872070312500000000000000000e+02
5 6 0.0000000000000000000000000000000000000000000000000000000000000000e+00
5 7 -4.0310680181028146762400865554809570312500000000000000000000000000e+01
5 8 3.0654314605490046830027495161630213260650634765625000000000000000e+01
6 3 4.2449276607203678679525182815268635749816894531250000000000000000e+01
6 4 -6.9238506120225792983546853065490722656250000000000000000000000000e+01
6 5 0.0000000000000000000000000000000000000000000000000000000000000000e+00
6 6 1.7166830055246467168217350263148546218872070312500000000000000000e+02
6 7 -3.0654314605490046830027495161630213260650634765625000000000000000e+01
6 8 -4.0310680181028146762400865554809570312500000000000000000000000000e+01
7 5 -4.0310680181028146762400865554809570312500000000000000000000000000e+01
7 6 -3.0654314605490046830027495161630213260650634765625000000000000000e+01
7 7 9.0122734518631659739185124635696411132812500000000000000000000000e+01
7 8 0.0000000000000000000000000000000000000000000000000000000000000000e+00
7 9 -2.6587549050434976294354783021844923496246337890625000000000000000e+01
7 10 3.2555664462677981418892159126698970794677734375000000000000000000e+01
8 5 3.0654314605490046830027495161630213260650634765625000000000000000e+01
8 6 -4.0310680181028146762400865554809570312500000000000000000000000000e+01
8 7 0.0000000000000000000000000000000000000000000000000000000000000000e+00
8 8 9.0122734518631659739185124635696411132812500000000000000000000000e+01
8 9 -3.2555664462677981418892159126698970794677734375000000000000000000e+01
8 10 -2.6587549050434976294354783021844923496246337890625000000000000000e+01
9 7 -2.6587549050434976294354783021844923496246337890625000000000000000e+01
9 8 -3.2555664462677981418892159126698970794677734375000000000000000000e+01
9 9 1.3994290817955334205180406570434570312500000000000000000000000000e+02
9 10 0.0000000000000000000000000000000000000000000000000000000000000000e+00
9 11 -3.8510392573554767636778706219047307968139648437500000000000000000e+01
9 12 4.3526959458391118573672429192811250686645507812500000000000000000e+01
10 7 3.2555664462677981418892159126698970794677734375000000000000000000e+01
10 8 -2.6587549050434976294354783021844923496246337890625000000000000000e+01
10 9 0.0000000000000000000000000000000000000000000000000000000000000000e+00
10 10 1.3994290817955334205180406570434570312500000000000000000000000000e+02
10 11 -4.3526959458391118573672429192811250686645507812500000000000000000e+01
10 12 -3.8510392573554767636778706219047307968139648437500000000000000000e+01
11 9 -3.8510392573554767636778706219047307968139648437500000000000000000e+01
11 10 -4.3526959458391118573672429192811250686645507812500000000000000000e+01
11 11 1.5436567823478708305628970265388488769531250000000000000000000000e+02
11 12 0.0000000000000000000000000000000000000000000000000000000000000000e+00
11 13 2.3785945574469224084168672561645507812500000000000000000000000000e+01
11 14 5.4928401268043032246168877463787794113159179687500000000000000000e+01
12 9 4.3526959458391118573672429192811250686645507812500000000000000000e+01
12 10 -3.8510392573554767636778706219047307968139648437500000000000000000e+01
12 11 0.0000000000000000000000000000000000000000000000000000000000000000e+00
12 12 1.5436567823478705463458027224987745285034179687500000000000000000e+02
12 13 -5.4928401268043032246168877463787794113159179687500000000000000000e+01
12 14 2.3785945574469224084168672561645507812500000000000000000000000000e+01
13 11 2.3785945574469224084168672561645507812500000000000000000000000000e+01
13 12 -5.4928401268043032246168877463787794113159179687500000000000000000e+01
13 13 3.8771747634530044024359085597097873687744140625000000000000000000e+02
13 14 0.0000000000000000000000000000000000000000000000000000000000000000e+00
13 15 -9.1945043368490601665143913123756647109985351562500000000000000000e+01
13 16 1.4743732717316754587955074384808540344238281250000000000000000000e+02
14 11 5.4928401268043032246168877463787794113159179687500000000000000000e+01
14 12 2.3785945574469224084168672561645507812500000000000000000000000000e+01
14 13 0.0000000000000000000000000000000000000000000000000000000000000000e+00
14 14 3.8771747634530044024359085597097873687744140625000000000000000000e+02
14 15 -1.4743732717316754587955074384808540344238281250000000000000000000e+02
14 16 -9.1945043368490601665143913123756647109985351562500000000000000000e+01
15 13 -9.1945043368490601665143913123756647109985351562500000000000000000e+01
15 14 -1.4743732717316754587955074384808540344238281250000000000000000000e+02
15 15 2.0126110204916042789591301698237657546997070312500000000000000000e+02
15 16 0.0000000000000000000000000000000000000000000000000000000000000000e+00
15 17 -5.2165597644569061230868101119995117187500000000000000000000000000e+01
15 18 1.3673105006512798809126252308487892150878906250000000000000000000e+02
16 13 1.4743732717316754587955074384808540344238281250000000000000000000e+02
16 14 -9.1945043368490601665143913123756647109985351562500000000000000000e+01
16 15 0.0000000000000000000000000000000000000000000000000000000000000000e+00
16 16 2.0126110204916042789591301698237657546997070312500000000000000000e+02
16 17 -1.3673105006512798809126252308487892150878906250000000000000000000e+02
16 18 -5.2165597644569061230868101119995117187500000000000000000000000000e+01
17 15 -5.2165597644569061230868101119995117187500000000000000000000000000e+01
17 16 -1.3673105006512798809126252308487892150878906250000000000000000000e+02
17 17 3.3725618489274347666651010513305664062500000000000000000000000000e+02
17 18 0.0000000000000000000000000000000000000000000000000000000000000000e+00
17 19 -5.9122571500287435242171341087669134140014648437500000000000000000e+01
17 20 5.7057835760936420399502821965143084526062011718750000000000000000e+01
18 15 1.3673105006512798809126252308487892150878906250000000000000000000e+02
18 16 -5.2165597644569061230868101119995117187500000000000000000000000000e+01
18 17 0.0000000000000000000000000000000000000000000000000000000000000000e+00
18 18 3.3725618489274347666651010513305664062500000000000000000000000000e+02
18 19 -5.7057835760936420399502821965143084526062011718750000000000000000e+01
18 20 -5.9122571500287435242171341087669134140014648437500000000000000000e+01
19 1 -2.7636018149649316910654306411743164062500000000000000000000000000e+01
19 2 3.1328868745033830123247753363102674484252929687500000000000000000e+01
19 17 -5.9122571500287435242171341087669134140014648437500000000000000000e+01
19 18 -5.7057835760936420399502821965143084526062011718750000000000000000e+01
19 19 1.9264168421482827397994697093963623046875000000000000000000000000e+02
19 20 0.0000000000000000000000000000000000000000000000000000000000000000e+00
19 21 -5.0503946656313928542658686637878417968750000000000000000000000000e+01
19 22 3.2518938603254845531864702934399247169494628906250000000000000000e+01
20 1 -3.1328868745033830123247753363102674484252929687500000000000000000e+01
20 2 -2.7636018149649316910654306411743164062500000000000000000000000000e+01
20 17 5.7057835760936420399502821965143084526062011718750000000000000000e+01
20 18 -5.9122571500287435242171341087669134140014648437500000000000000000e+01
20 19 0.0000000000000000000000000000000000000000000000000000000000000000e+00
20 20 1.9264168421482827397994697093963623046875000000000000000000000000e+02
20 21 -3.2518938603254845531864702934399247169494628906250000000000000000e+01
20 22 -5.0503946656313928542658686637878417968750000000000000000000000000e+01
21 1 -6.4424171952960008979971462395042181015014648437500000000000000000e+01
21 2 -1.3795308458256652528461927431635558605194091796875000000000000000e+01
21 3 -2.2774146490635754247477962053380906581878662109375000000000000000e+01
21 4 4.6314247061511501613040309166535735130310058593750000000000000000e+01
21 19 -5.0503946656313928542658686637878417968750000000000000000000000000e+01
21 20 -3.2518938603254845531864702934399247169494628906250000000000000000e+01
21 21 1.3770226509990968111196707468479871749877929687500000000000000000e+02
21 22 0.0000000000000000000000000000000000000000000000000000000000000000e+00
22 1 1.3795308458256652528461927431635558605194091796875000000000000000e+01
22 2 -6.4424171952960008979971462395042181015014648437500000000000000000e+01
22 3 -4.6314247061511501613040309166535735130310058593750000000000000000e+01
22 4 -2.2774146490635754247477962053380906581878662109375000000000000000e+01
22 19 3.2518938603254845531864702934399247169494628906250000000000000000e+01
22 20 -5.0503946656313928542658686637878417968750000000000000000000000000e+01
22 21 0.0000000000000000000000000000000000000000000000000000000000000000e+00
22 22 1.3770226509990968111196707468479871749877929687500000000000000000e+02
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
I cannot reproduce, here is the code I used:

Code: Select all

#include <Eigen/Sparse>
#include <unsupported/Eigen/SparseExtra>
using namespace Eigen;

int main()
{
  SparseMatrix<double> M;
  loadMarket(M, "cgsegfaul.mtx");
  VectorXd x(M.cols()), b(M.cols());
  b.setRandom();

  Eigen::ConjugateGradient< Eigen::SparseMatrix<double> > cg;
  cg.compute(M);
  x = cg.solve(b);

  return 0;
}
joris31
Registered Member
Posts
6
Karma
0
mmm, weird.. I do basically the same thing, except my b-vector entries are mostly zeros.

One thing I could think of is that I do something wrong here, which results in an invalid matrix or so:
Code: Select all
// Create iA and iB
// Fill iA and iB
// Need to solve A'Ax = A'b
iB = Eigen::SparseMatrix<double, Eigen::RowMajor>(iA.transpose()) * iB;
iA = Eigen::SparseMatrix<double, Eigen::RowMajor>(iA.transpose()) * iA;
iA.finalize();


Maybe if it would help somehow, I'm on a mac compiling using llvm.

Are there still any changes in the cg code since the 3.1.0-alpha1 release that could maybe explain the difference?

Thanks for your help
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
The default compiler on mac is known to sometime produce invalid piece of codes, you should give a try to gcc 4.6 of macport. Note that you can simply write:

iB = iA.transpose() * iB;
iA = iA.transpose() * iA;
joris31
Registered Member
Posts
6
Karma
0
Thanksm I'll give gcc a try. Do you plan to fix issues with llvm in the future?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
the issues I'm talking about are on apple's side


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]