eigs.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // Inputs:
  16. // A #A by #A symmetric matrix
  17. // B #A by #A symmetric positive-definite matrix
  18. // k number of eigen pairs to compute
  19. // Outputs:
  20. // sU #A by k list of sorted eigen vectors (descending)
  21. // sS k list of sorted eigen values (descending)
  22. //
  23. // Known issues:
  24. // - only one pair per eigen value is found (no multiples)
  25. // - only the 'sm' small magnitude eigen values are well supported
  26. //
  27. enum EigsType
  28. {
  29. EIGS_TYPE_SM = 0,
  30. EIGS_TYPE_LM = 1,
  31. NUM_EIGS_TYPES = 2
  32. };
  33. template <
  34. typename Atype,
  35. typename Btype,
  36. typename DerivedU,
  37. typename DerivedS>
  38. IGL_INLINE bool eigs(
  39. const Eigen::SparseMatrix<Atype> & A,
  40. const Eigen::SparseMatrix<Btype> & B,
  41. const size_t k,
  42. const EigsType type,
  43. Eigen::PlainObjectBase<DerivedU> & sU,
  44. Eigen::PlainObjectBase<DerivedS> & sS);
  45. }
  46. #ifndef IGL_STATIC_LIBRARY
  47. #include "eigs.cpp"
  48. #endif
  49. #endif