fn_eigs_sym.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup fn_eigs_sym
  16. //! @{
  17. //! eigenvalues of symmetric real sparse matrix X
  18. template<typename T1>
  19. arma_warn_unused
  20. inline
  21. Col<typename T1::pod_type>
  22. eigs_sym
  23. (
  24. const SpBase<typename T1::elem_type,T1>& X,
  25. const uword n_eigvals,
  26. const char* form = "lm",
  27. const typename T1::elem_type tol = 0.0,
  28. const typename arma_real_only<typename T1::elem_type>::result* junk = 0
  29. )
  30. {
  31. arma_extra_debug_sigprint();
  32. arma_ignore(junk);
  33. Mat<typename T1::elem_type> eigvec;
  34. Col<typename T1::pod_type > eigval;
  35. const bool status = sp_auxlib::eigs_sym(eigval, eigvec, X, n_eigvals, form, tol);
  36. if(status == false)
  37. {
  38. eigval.soft_reset();
  39. arma_stop_runtime_error("eigs_sym(): decomposition failed");
  40. }
  41. return eigval;
  42. }
  43. //! eigenvalues of symmetric real sparse matrix X
  44. template<typename T1>
  45. inline
  46. bool
  47. eigs_sym
  48. (
  49. Col<typename T1::pod_type >& eigval,
  50. const SpBase<typename T1::elem_type,T1>& X,
  51. const uword n_eigvals,
  52. const char* form = "lm",
  53. const typename T1::elem_type tol = 0.0,
  54. const typename arma_real_only<typename T1::elem_type>::result* junk = 0
  55. )
  56. {
  57. arma_extra_debug_sigprint();
  58. arma_ignore(junk);
  59. Mat<typename T1::elem_type> eigvec;
  60. const bool status = sp_auxlib::eigs_sym(eigval, eigvec, X, n_eigvals, form, tol);
  61. if(status == false)
  62. {
  63. eigval.soft_reset();
  64. arma_debug_warn("eigs_sym(): decomposition failed");
  65. }
  66. return status;
  67. }
  68. //! eigenvalues and eigenvectors of symmetric real sparse matrix X
  69. template<typename T1>
  70. inline
  71. bool
  72. eigs_sym
  73. (
  74. Col<typename T1::pod_type >& eigval,
  75. Mat<typename T1::elem_type>& eigvec,
  76. const SpBase<typename T1::elem_type,T1>& X,
  77. const uword n_eigvals,
  78. const char* form = "lm",
  79. const typename T1::elem_type tol = 0.0,
  80. const typename arma_real_only<typename T1::elem_type>::result* junk = 0
  81. )
  82. {
  83. arma_extra_debug_sigprint();
  84. arma_ignore(junk);
  85. arma_debug_check( void_ptr(&eigval) == void_ptr(&eigvec), "eigs_sym(): parameter 'eigval' is an alias of parameter 'eigvec'" );
  86. const bool status = sp_auxlib::eigs_sym(eigval, eigvec, X, n_eigvals, form, tol);
  87. if(status == false)
  88. {
  89. eigval.soft_reset();
  90. eigvec.soft_reset();
  91. arma_debug_warn("eigs_sym(): decomposition failed");
  92. }
  93. return status;
  94. }
  95. //! @}