fn_eigs_gen.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_gen
  16. //! @{
  17. //! eigenvalues of general sparse matrix X
  18. template<typename T1>
  19. arma_warn_unused
  20. inline
  21. Col< std::complex<typename T1::pod_type> >
  22. eigs_gen
  23. (
  24. const SpBase<typename T1::elem_type, T1>& X,
  25. const uword n_eigvals,
  26. const char* form = "lm",
  27. const typename T1::pod_type tol = 0.0,
  28. const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
  29. )
  30. {
  31. arma_extra_debug_sigprint();
  32. arma_ignore(junk);
  33. typedef typename T1::pod_type T;
  34. Mat< std::complex<T> > eigvec;
  35. Col< std::complex<T> > eigval;
  36. const bool status = sp_auxlib::eigs_gen(eigval, eigvec, X, n_eigvals, form, tol);
  37. if(status == false)
  38. {
  39. eigval.soft_reset();
  40. arma_stop_runtime_error("eigs_gen(): decomposition failed");
  41. }
  42. return eigval;
  43. }
  44. //! eigenvalues of general sparse matrix X
  45. template<typename T1>
  46. inline
  47. bool
  48. eigs_gen
  49. (
  50. Col< std::complex<typename T1::pod_type> >& eigval,
  51. const SpBase<typename T1::elem_type, T1>& X,
  52. const uword n_eigvals,
  53. const char* form = "lm",
  54. const typename T1::pod_type tol = 0.0,
  55. const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
  56. )
  57. {
  58. arma_extra_debug_sigprint();
  59. arma_ignore(junk);
  60. typedef typename T1::pod_type T;
  61. Mat< std::complex<T> > eigvec;
  62. const bool status = sp_auxlib::eigs_gen(eigval, eigvec, X, n_eigvals, form, tol);
  63. if(status == false)
  64. {
  65. eigval.soft_reset();
  66. arma_debug_warn("eigs_gen(): decomposition failed");
  67. }
  68. return status;
  69. }
  70. //! eigenvalues and eigenvectors of general real sparse matrix X
  71. template<typename T1>
  72. inline
  73. bool
  74. eigs_gen
  75. (
  76. Col< std::complex<typename T1::pod_type> >& eigval,
  77. Mat< std::complex<typename T1::pod_type> >& eigvec,
  78. const SpBase<typename T1::elem_type, T1>& X,
  79. const uword n_eigvals,
  80. const char* form = "lm",
  81. const typename T1::pod_type tol = 0.0,
  82. const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
  83. )
  84. {
  85. arma_extra_debug_sigprint();
  86. arma_ignore(junk);
  87. arma_debug_check( void_ptr(&eigval) == void_ptr(&eigvec), "eigs_gen(): parameter 'eigval' is an alias of parameter 'eigvec'" );
  88. const bool status = sp_auxlib::eigs_gen(eigval, eigvec, X, n_eigvals, form, tol);
  89. if(status == false)
  90. {
  91. eigval.soft_reset();
  92. eigvec.soft_reset();
  93. arma_debug_warn("eigs_gen(): decomposition failed");
  94. }
  95. return status;
  96. }
  97. //! @}