// Make an effort to verify bugs/gotchas for column and row major //#define EIGEN_DEFAULT_TO_ROW_MAJOR #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET #define EIGEN_IM_MAD_AS_HELL_AND_IM_NOT_GOING_TO_TAKE_IT_ANYMORE #include #include using namespace Eigen; #include #include using namespace std; #include using namespace igl; // Eigen fails to notice at compile time that the inneriterator used to loop // over the contents of a sparsematrix of type T is a different type // // http://www.alecjacobson.com/weblog/?p=2216 void wrong_sparsematrix_inner_iterator_type() { // Fill 10 by 10 matrix with 0.5*(1:10) along the diagonal SparseMatrix A(10,10); A.reserve(10); for(int i = 0;i<10;i++) { A.insert(i,i) = (double)i/2.0; } A.finalize(); cout<<"AIJV=["<::InnerIterator it(A,k); it; ++it) { printf("A(%d,%d) = %d\n",it.row(),it.col(),it.value()); } } } // Eigen can't handle .transpose within expression on right hand side of = // operator // // Temporary solution: Never use Something.transpose() in expression. Always // first compute Something into a matrix: // SparseMatrix S = Something; // then compute tranpose // SparseMatrix ST = Something.transpose(); // then continue void sparsematrix_transpose_in_rhs_aliasing() { SparseMatrix A(7,2); A.reserve(4); A.insert(0,0) = -0.5; A.insert(2,0) = -0.5; A.insert(4,1) = -0.5; A.insert(6,1) = -0.5; A.finalize(); cout<<"AIJV=["< B(2,7); B.reserve(4); B.insert(0,0) = -0.5; B.insert(0,2) = -0.5; B.insert(1,4) = -0.5; B.insert(1,6) = -0.5; B.finalize(); cout<<"BIJV=["< C; // Should be empty but isn't C = A-B.transpose(); cout<<"C = A - B.transpose();"< BT = B.transpose(); C = A-BT; cout<<"C = A - BT;"< > A_LLT(A); // with: // SparseLLT > A_LLT(A.template triangularView()); // void sparsellt_needs_triangular_view() { // Succeeds SparseMatrix A(2,2); A.reserve(4); A.insert(0,0) = 1; A.insert(0,1) = -0.5; A.insert(1,0) = -0.5; A.insert(1,1) = 1; A.finalize(); cout<<"AIJV=["< > A_LLT(A.triangularView()); SparseMatrix A_L = A_LLT.matrixL(); cout<<"A_LIJV=["< B(2,2); B.reserve(4); B.insert(0,0) = 1; B.insert(0,1) = -0.5; B.insert(1,0) = -0.5; B.insert(1,1) = 1; B.finalize(); cout<<"BIJV=["< > B_LLT(B); } void sparsematrix_nonzeros_after_expression() { SparseMatrix A(2,2); A.reserve(4); A.insert(0,0) = 1; A.insert(0,1) = -0.5; A.insert(1,0) = -0.5; A.insert(1,1) = 1; A.finalize(); cout<<"AIJV=["< AmA = A-A; cout<<"(AmA).nonZeros(): "< A(2,2); A.reserve(4); A.insert(0,0) = 1; A.insert(0,1) = -0.5; A.insert(1,0) = -0.5; A.insert(1,1) = 1; A.finalize(); cout<<"AIJV=["< > A_LLT(A.triangularView()); cout<<"A_LLT.succeeded(): "<<(A_LLT.succeeded()?"TRUE":"FALSE")< A_L = A_LLT.matrixL(); // See sparsematrix_nonzeros_after_expression cout<<"(A_L*0).eval().nonZeros(): "<<(A_L*0).eval().nonZeros()< B(2,2); B.reserve(4); B.insert(0,0) = -1; B.insert(0,1) = 0.5; B.insert(1,0) = 0.5; B.insert(1,1) = -1; B.finalize(); cout<<"BIJV=["< > B_LLT(B.triangularView()); cout<<"B_LLT.succeeded(): "<<(B_LLT.succeeded()?"TRUE":"FALSE")< B_L = B_LLT.matrixL(); // See sparsematrix_nonzeros_after_expression cout<<"(B_L*0).eval().nonZeros(): "<<(B_L*0).eval().nonZeros()<