eigs.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Alec Jacobson <alecjacobson@gmail.com>
  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. // Act like MATLAB's eigs function. Compute the first/last k eigen pairs of
  16. // the generalized eigen value problem:
  17. //
  18. // A u = s B u
  19. //
  20. // Solutions are approximate and sorted.
  21. //
  22. // Ideally one should use ARPACK and the Eigen unsupported ARPACK module.
  23. // This implementation does simple, naive power iterations.
  24. //
  25. // Inputs:
  26. // A #A by #A symmetric matrix
  27. // B #A by #A symmetric positive-definite matrix
  28. // k number of eigen pairs to compute
  29. // type whether to extract from the high or low end
  30. // Outputs:
  31. // sU #A by k list of sorted eigen vectors (descending)
  32. // sS k list of sorted eigen values (descending)
  33. //
  34. // Known issues:
  35. // - only the 'sm' small magnitude eigen values are well supported
  36. //
  37. enum EigsType
  38. {
  39. EIGS_TYPE_SM = 0,
  40. EIGS_TYPE_LM = 1,
  41. NUM_EIGS_TYPES = 2
  42. };
  43. template <
  44. typename Atype,
  45. typename Btype,
  46. typename DerivedU,
  47. typename DerivedS>
  48. IGL_INLINE bool eigs(
  49. const Eigen::SparseMatrix<Atype> & A,
  50. const Eigen::SparseMatrix<Btype> & B,
  51. const size_t k,
  52. const EigsType type,
  53. Eigen::PlainObjectBase<DerivedU> & sU,
  54. Eigen::PlainObjectBase<DerivedS> & sS);
  55. }
  56. #ifndef IGL_STATIC_LIBRARY
  57. #include "eigs.cpp"
  58. #endif
  59. #endif