eigs.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef IGL_EIGS_H
  2. #define IGL_EIGS_H
  3. #include "igl_inline.h"
  4. #include <Eigen/Core>
  5. #include <Eigen/Sparse>
  6. namespace igl
  7. {
  8. // Act like MATLAB's eigs function. Compute the first/last k eigen pairs of
  9. // the generalized eigen value problem:
  10. //
  11. // A u = s B u
  12. //
  13. // Solutions are approximate and sorted.
  14. //
  15. // Ideally one should use ARPACK and the Eigen unsupported ARPACK module.
  16. // This implementation does simple, naive power iterations.
  17. //
  18. // Inputs:
  19. // A #A by #A symmetric matrix
  20. // B #A by #A symmetric positive-definite matrix
  21. // k number of eigen pairs to compute
  22. // Outputs:
  23. // sU #A by k list of sorted eigen vectors (descending)
  24. // sS k list of sorted eigen values (descending)
  25. //
  26. // Known issues:
  27. // - only one pair per eigen value is found (no multiples)
  28. // - only the 'sm' small magnitude eigen values are well supported
  29. //
  30. enum EigsType
  31. {
  32. EIGS_TYPE_SM = 0,
  33. EIGS_TYPE_LM = 1,
  34. NUM_EIGS_TYPES = 2
  35. };
  36. template <
  37. typename Atype,
  38. typename Btype,
  39. typename DerivedU,
  40. typename DerivedS>
  41. IGL_INLINE bool eigs(
  42. const Eigen::SparseMatrix<Atype> & A,
  43. const Eigen::SparseMatrix<Btype> & B,
  44. const size_t k,
  45. const EigsType type,
  46. Eigen::PlainObjectBase<DerivedU> & sU,
  47. Eigen::PlainObjectBase<DerivedS> & sS);
  48. }
  49. #ifndef IGL_STATIC_LIBRARY
  50. #include "eigs.cpp"
  51. #endif
  52. #endif