123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- #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 <Eigen/Sparse>
- #include <Eigen/SparseExtra>
- using namespace Eigen;
- #include <cstdio>
- #include <iostream>
- using namespace std;
- #include <igl/print_ijv.h>
- using namespace igl;
- void wrong_sparsematrix_inner_iterator_type()
- {
-
- SparseMatrix<double> 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=["<<endl;print_ijv(A,1);cout<<endl<<"];"<<endl<<
- "A=sparse(AIJV(:,1),AIJV(:,2),AIJV(:,3),"<<
- A.rows()<<","<<A.cols()<<");"<<endl;
-
- for(int k = 0;k<A.outerSize();k++)
- {
-
-
- for (SparseMatrix<int>::InnerIterator it(A,k); it; ++it)
- {
- printf("A(%d,%d) = %d\n",it.row(),it.col(),it.value());
- }
- }
- }
- void sparsematrix_transpose_in_rhs_aliasing()
- {
- SparseMatrix<double> 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=["<<endl;print_ijv(A,1);cout<<endl<<"];"<<endl<<
- "A=sparse(AIJV(:,1),AIJV(:,2),AIJV(:,3),"<<
- A.rows()<<","<<A.cols()<<");"<<endl;
- SparseMatrix<double> 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=["<<endl;print_ijv(B,1);cout<<endl<<"];"<<endl<<
- "B=sparse(BIJV(:,1),BIJV(:,2),BIJV(:,3),"<<
- B.rows()<<","<<B.cols()<<");"<<endl;
- SparseMatrix<double> C;
-
- C = A-B.transpose();
- cout<<"C = A - B.transpose();"<<endl;
- cout<<"CIJV=["<<endl;print_ijv(C,1);cout<<endl<<"];"<<endl<<
- "C=sparse(CIJV(:,1),CIJV(:,2),CIJV(:,3),"<<
- C.rows()<<","<<C.cols()<<");"<<endl;
-
- C = A-B.transpose().eval();
- cout<<"C = A - B.transpose().eval();"<<endl;
- cout<<"CIJV=["<<endl;print_ijv(C,1);cout<<endl<<"];"<<endl<<
- "C=sparse(CIJV(:,1),CIJV(:,2),CIJV(:,3),"<<
- C.rows()<<","<<C.cols()<<");"<<endl;
-
- SparseMatrix<double> BT = B.transpose();
- C = A-BT;
- cout<<"C = A - BT;"<<endl;
- cout<<"CIJV=["<<endl;print_ijv(C,1);cout<<endl<<"];"<<endl<<
- "C=sparse(CIJV(:,1),CIJV(:,2),CIJV(:,3),"<<
- C.rows()<<","<<C.cols()<<");"<<endl;
- }
- void sparsellt_needs_triangular_view()
- {
-
- SparseMatrix<double> 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=["<<endl;print_ijv(A,1);cout<<endl<<"];"<<endl<<
- "A=sparse(AIJV(:,1),AIJV(:,2),AIJV(:,3),"<<
- A.rows()<<","<<A.cols()<<");"<<endl;
- SparseLLT<SparseMatrix<double> > A_LLT(A.triangularView<Eigen::Lower>());
- SparseMatrix<double> A_L = A_LLT.matrixL();
- cout<<"A_LIJV=["<<endl;print_ijv(A_L,1);cout<<endl<<"];"<<endl<<
- "A_L=sparse(A_LIJV(:,1),A_LIJV(:,2),A_LIJV(:,3),"<<
- A_L.rows()<<","<<A_L.cols()<<");"<<endl;
-
- SparseMatrix<double> 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=["<<endl;print_ijv(B,1);cout<<endl<<"];"<<endl<<
- "B=sparse(BIJV(:,1),BIJV(:,2),BIJV(:,3),"<<
- B.rows()<<","<<B.cols()<<");"<<endl;
- SparseLLT<SparseMatrix<double> > B_LLT(B);
- }
- void sparsematrix_nonzeros_after_expression()
- {
- SparseMatrix<double> 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=["<<endl;print_ijv(A,1);cout<<endl<<"];"<<endl<<
- "A=sparse(AIJV(:,1),AIJV(:,2),AIJV(:,3),"<<
- A.rows()<<","<<A.cols()<<");"<<endl;
-
- SparseMatrix<double> AmA = A-A;
- cout<<"(AmA).nonZeros(): "<<AmA.nonZeros()<<endl;
-
- cout<<"(A-A).eval().nonZeros(): "<<(A-A).eval().nonZeros()<<endl;
-
- cout<<"(A-A).nonZeros(): "<<(A-A).nonZeros()<<endl;
- }
- void sparsellt_succeeded_is_meaningless()
- {
-
- SparseMatrix<double> 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=["<<endl;print_ijv(A,1);cout<<endl<<"];"<<endl<<
- "A=sparse(AIJV(:,1),AIJV(:,2),AIJV(:,3),"<<
- A.rows()<<","<<A.cols()<<");"<<endl;
- SparseLLT<SparseMatrix<double> > A_LLT(A.triangularView<Eigen::Lower>());
- cout<<"A_LLT.succeeded(): "<<(A_LLT.succeeded()?"TRUE":"FALSE")<<endl;
- SparseMatrix<double> A_L = A_LLT.matrixL();
-
- cout<<"(A_L*0).eval().nonZeros(): "<<(A_L*0).eval().nonZeros()<<endl;
- cout<<"A_LIJV=["<<endl;print_ijv(A_L,1);cout<<endl<<"];"<<endl<<
- "A_L=sparse(A_LIJV(:,1),A_LIJV(:,2),A_LIJV(:,3),"<<
- A_L.rows()<<","<<A_L.cols()<<");"<<endl;
-
- SparseMatrix<double> 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=["<<endl;print_ijv(B,1);cout<<endl<<"];"<<endl<<
- "B=sparse(BIJV(:,1),BIJV(:,2),BIJV(:,3),"<<
- B.rows()<<","<<B.cols()<<");"<<endl;
- SparseLLT<SparseMatrix<double> > B_LLT(B.triangularView<Eigen::Lower>());
- cout<<"B_LLT.succeeded(): "<<(B_LLT.succeeded()?"TRUE":"FALSE")<<endl;
- SparseMatrix<double> B_L = B_LLT.matrixL();
-
- cout<<"(B_L*0).eval().nonZeros(): "<<(B_L*0).eval().nonZeros()<<endl;
- cout<<"B_LIJV=["<<endl;print_ijv(B_L,1);cout<<endl<<"];"<<endl<<
- "B_L=sparse(B_LIJV(:,1),B_LIJV(:,2),B_LIJV(:,3),"<<
- B_L.rows()<<","<<B_L.cols()<<");"<<endl;
- }
- int main(int argc, char * argv[])
- {
-
-
-
-
-
- return 0;
- }
|