example.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <Eigen/Dense>
  2. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  3. #define EIGEN_IM_MAD_AS_HELL_AND_IM_NOT_GOING_TO_TAKE_IT_ANYMORE
  4. #include <Eigen/Sparse>
  5. using namespace Eigen;
  6. #include <cstdio>
  7. #include <iostream>
  8. using namespace std;
  9. #include <igl/slice.h>
  10. #include <igl/speye.h>
  11. #include <igl/print_ijv.h>
  12. using namespace igl;
  13. int main(int argc, char * argv[])
  14. {
  15. // Dense
  16. MatrixXd A = MatrixXd::Identity(5,5);
  17. cout<<"A=["<<endl<<A<<endl<<"];"<<endl;
  18. // Row and column indices
  19. MatrixXi R(6,1);
  20. R<<0,1,2,4,4,0;
  21. cout<<"R=["<<endl<<R<<endl<<"];"<<endl;
  22. MatrixXi C(4,1);
  23. C<<2,2,4,0;
  24. cout<<"C=["<<endl<<C<<endl<<"];"<<endl;
  25. MatrixXd B;
  26. cout<<"B=A(R,C);"<<endl;
  27. slice(A,R,C,B);
  28. cout<<"B=["<<endl<<B<<endl<<"];"<<endl;
  29. cout<<endl;
  30. //SparseMatrix
  31. SparseMatrix<double> spA;
  32. speye(5,5,spA);
  33. cout<<"spA_IJV=["<<endl;print_ijv(spA,1);cout<<endl<<"];"<<endl;
  34. cout<<"spA=sparse(spA_IJV(:,1),spA_IJV(:,2),spA_IJV(:,3));"<<endl;
  35. SparseMatrix<double> spB;
  36. cout<<"spB=spA(R,C);"<<endl;
  37. slice(spA,R,C,spB);
  38. cout<<"spB_IJV=["<<endl;print_ijv(spB,1);cout<<endl<<"];"<<endl;
  39. cout<<"spB=sparse(spB_IJV(:,1),spB_IJV(:,2),spB_IJV(:,3));"<<endl;
  40. return 0;
  41. }