eigs.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Alec Jacobson <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_EIGS_H
  9. #define IGL_EIGS_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <Eigen/Sparse>
  13. namespace igl
  14. {
  15. /// Type of eigen values to extract
  16. enum EigsType
  17. {
  18. /// Smallest magnitude eigen values
  19. EIGS_TYPE_SM = 0,
  20. /// Largest magnitude eigen values
  21. EIGS_TYPE_LM = 1,
  22. /// Total number of types
  23. NUM_EIGS_TYPES = 2
  24. };
  25. /// Compute the first/last k eigen pairs of
  26. /// the generalized eigen value problem:
  27. ///
  28. /// A u = s B u
  29. ///
  30. /// Solutions are approximate and sorted.
  31. ///
  32. /// \note Ideally one should use ARPACK and the Eigen unsupported ARPACK module.
  33. /// This implementation does simple, naive power iterations.
  34. ///
  35. /// \see spectra::eigs
  36. ///
  37. /// @param[in] A #A by #A symmetric matrix
  38. /// @param[in] B #A by #A symmetric positive-definite matrix
  39. /// @param[in] k number of eigen pairs to compute
  40. /// @param[in] type whether to extract from the high or low end
  41. /// @param[out] sU #A by k list of sorted eigen vectors (descending)
  42. /// @param[out] sS k list of sorted eigen values (descending)
  43. ///
  44. /// \warning only the 'sm' small magnitude eigen values are well supported
  45. ///
  46. template <
  47. typename Atype,
  48. typename Btype,
  49. typename DerivedU,
  50. typename DerivedS>
  51. IGL_INLINE bool eigs(
  52. const Eigen::SparseMatrix<Atype> & A,
  53. const Eigen::SparseMatrix<Btype> & B,
  54. const size_t k,
  55. const EigsType type,
  56. Eigen::PlainObjectBase<DerivedU> & sU,
  57. Eigen::PlainObjectBase<DerivedS> & sS);
  58. }
  59. #ifndef IGL_STATIC_LIBRARY
  60. #include "eigs.cpp"
  61. #endif
  62. #endif