Hello I have tried to use the SparseModule with MPFR C++, but I have an error that I cannot understand. I don't know whether the problem comes from Eigen or from MPFR C++. My code runs correctly when the numerical type of the matrix is double but does not work when the type is mpreal in Sparse Module. Can you give me some hint about this error ? Thank you for your answer. Bertrand To reproduce my bug, you can use this code //////////////////////////////////////////////////////////////////////// #include <Eigen/MPRealSupport> #include "mpreal.h" #include <Eigen/Core> #include <Eigen/LU> #include <Eigen/Dense> #include <Eigen/Sparse> #include <Eigen/SparseExtra> using namespace mpfr; using namespace std; template<class U> void Test(Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> A ,Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> B){ Eigen::Matrix<U,Eigen::Dynamic,Eigen::Dynamic> T_A_; Eigen::Matrix<U,Eigen::Dynamic,Eigen::Dynamic> T_B_; T_A_.resize(A.rows (),A.cols()); T_B_.resize(B.rows (),B.cols()); for(unsigned int r=0;r<A.rows ();r=r+1) for(unsigned int c=0;c<A.cols();c=c+1) T_A_.coeffRef(r,c)=A.coeffRef(r,c); for(unsigned int r=0;r<B.rows ();r=r+1) for(unsigned int c=0;c<B.cols();c=c+1) T_B_.coeffRef(r,c)=B.coeffRef(r,c); Eigen::Matrix<U,Eigen::Dynamic,Eigen::Dynamic> T_X_; Eigen::LDLT< Eigen::Matrix<U,Eigen::Dynamic,Eigen::Dynamic> > ldlt(T_A_); T_X_=T_B_; ldlt.solveInPlace(T_X_); std::cout << "relative error: " << (T_A_*T_X_ - T_B_).norm() / T_B_.norm() << std::endl; Eigen::DynamicSparseMatrix<U> T_A ; Eigen::Matrix<U,Eigen::Dynamic,Eigen::Dynamic> T_B(B.rows (),B.cols()) ; T_A.resize(A.rows (),A.cols()); for(unsigned int i=0;i<100;i=i+1){ for(unsigned int j=0;j<100;j=j+1) T_A.coeffRef(i,j)=T_A_.coeffRef(i,j); T_B.coeffRef(i,0)=T_B_.coeffRef(i,0); } Eigen::Matrix<U,Eigen::Dynamic,Eigen::Dynamic> T_X=T_B; Eigen::SparseLDLT< Eigen::SparseMatrix<U,Eigen::Upper|Eigen::SelfAdjoint> > llt(T_A); if (llt.succeeded()){ llt.solveInPlace(T_X); } else{ std::cout<<"error"<<std::endl; } std::cout << "relative error: " << (T_A*T_X - T_B).norm() / T_B.norm() << std::endl; }; int main(int argc,char**argv) { Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> A = Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>::Random(100,100); Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> B = Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>::Random(100,1); mpreal::set_default_prec(256); Test<double>(A,B); Test<mpreal>(A,B); return(0); } ///////////////////////////////////////////////////////////////////////// relative error: 18.1509 relative error: 22.196 relative error: 18.1509 Error ////////////////////////////////////////////////////////////////////////
On the page of MPFR++ http://www.holoborodko.com/pavel/?page_id=12 I have seen this post, so maybe it can help you to find my bug ? %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% JamesHH Posted September 18, 2009 at 1:36 pm | Permalink Simon, What do you mean “seems to work”? Sure, Eigen compiles fine with MPFR C++, but at least for me it crashes when the ~Matrix() destructor is called. Pavel, unless you can point me to some working example of Eigen with MPFR C++, then I think it is false advertising to put Eigen in your “Software using MPFR C++”. If it really does work, I would appreciate a pointer to some more information. Thanks. Reply * Pavel Holoborodko Posted July 21, 2010 at 11:22 am | Permalink As for July 15, 2010, Eigen developers have fixed these bug. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
gdb backtrace: Starting program: relative error: 18.1509 relative error: 22.196 relative error: 18.1509 Program received signal SIGABRT, Aborted. 0xb7fe2430 in __kernel_vsyscall () (gdb) bt #0 0xb7fe2430 in __kernel_vsyscall () #1 0xb7d09651 in *__GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64 #2 0xb7d0ca82 in *__GI_abort () at abort.c:92 #3 0x080fa60f in dlfree (mem=0x82353d8) at ./mpfrc++/dlmalloc.c:4828 #4 0x080fc6dd in mpfr::mpreal::mpreal_free (ptr=0x82353d8, size=542003396) at ./mpfrc++/mpreal.cpp:486 #5 0xb7f7d8a8 in mpfr_clear () from /usr/lib/libmpfr.so.1 #6 0x080fb055 in ~mpreal (this=0x8164fc4, __in_chrg=<value optimised out>) at ./mpfrc++/mpreal.cpp:187 #7 0x080d5c7f in Eigen::CompressedStorage<mpfr::mpreal, int>::reallocate (this=0x8163388, size=14) at /usr/local/include/eigen3/Eigen/src/Sparse/CompressedStorage.h:224 #8 0x080d04db in Eigen::CompressedStorage<mpfr::mpreal, int>::resize (this=0x8163388, size=7, reserveSizeFactor=1) at /usr/local/include/eigen3/Eigen/src/Sparse/CompressedStorage.h:99 #9 0x080cc46e in Eigen::CompressedStorage<mpfr::mpreal, int>::atWithInsertion (this=0x8163388, key=6, defaultValue=...) at /usr/local/include/eigen3/Eigen/src/Sparse/CompressedStorage.h:185 #10 0x080ca36f in Eigen::DynamicSparseMatrix<mpfr::mpreal, 0, int>::coeffRef (this=0xbffff120, row=6, col=0) at /usr/local/include/eigen3/Eigen/src/Sparse/DynamicSparseMatrix.h:117 #11 0x080c8cae in Test<mpfr::mpreal> (A=..., B=...) at ./mpreal_eigen_test.cpp:41 #12 0x080c65ee in main (argc=1, argv=0xbffff364) at ./mpreal_eigen_test.cpp:64
Created attachment 42 [details] MPFR C++ without dlmalloc
Try to use MPFR C++ without dlmalloc (see attached file for that version). Bug reported by JamesHH on September 18, 2009 has been fixed.
Hi I have just tried your patch but I have always the same problem. The bug report by JamesHH concerned the plain matrix, but I use sparse matrix. The code with plain matrix and double works The same code with plain matrix and real works The same code with sparse matrix and double works but the same code with sparse matrix and real doesn't Whith your patch the back trace of gdb are : #0 0xb7d498da in malloc_consolidate (av=<value optimised out>) at malloc.c:5144 #1 0xb7d4bafd in _int_malloc (av=<value optimised out>, bytes=<value optimised out>) at malloc.c:4372 #2 0xb7d4df9c in *__GI___libc_malloc (bytes=2020) at malloc.c:3660 #3 0xb7f3bc07 in operator new(unsigned int) () from /usr/lib/libstdc++.so.6 #4 0xb7f3bd3d in operator new[](unsigned int) () from /usr/lib/libstdc++.so.6 #5 0x080d5559 in Eigen::CompressedStorage<mpfr::mpreal, int>::reallocate (this=0x8225708, size=126) at /usr/local/include/eigen3/Eigen/src/Sparse/CompressedStorage.h:217 #6 0x080cfedb in Eigen::CompressedStorage<mpfr::mpreal, int>::resize (this=0x8225708, size=63, reserveSizeFactor=1) at /usr/local/include/eigen3/Eigen/src/Sparse/CompressedStorage.h:99 #7 0x080cbe6e in Eigen::CompressedStorage<mpfr::mpreal, int>::atWithInsertion (this=0x8225708, key=62, defaultValue=...) at /usr/local/include/eigen3/Eigen/src/Sparse/CompressedStorage.h:185 #8 0x080c9d6f in Eigen::DynamicSparseMatrix<mpfr::mpreal, 0, int>::coeffRef (this=0xbffff110, row=62, col=0) at /usr/local/include/eigen3/Eigen/src/Sparse/DynamicSparseMatrix.h:117 #9 0x080c86ae in Test<mpfr::mpreal> (A=..., B=...) at /home/bcannelle/Programmation/Developpements/Temporaire/eigenmpfr_patch/mpreal_eigen_test.cpp:41 #10 0x080c5fee in main (argc=1, argv=0xbffff354) at /home/bcannelle/Programmation/Developpements/Temporaire/eigenmpfr_patch/mpreal_eigen_test.cpp:64
This bug has been resolved but I do not know when. The code available in the branch on August 26 that the code works Thanks for all Bertrand
-- GitLab Migration Automatic Message -- This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/116.