sp_auxlib_bones.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 sp_auxlib
  16. //! @{
  17. //! wrapper for accesing external functions in ARPACK and SuperLU
  18. class sp_auxlib
  19. {
  20. public:
  21. enum form_type
  22. {
  23. form_none, form_lm, form_sm, form_lr, form_la, form_sr, form_li, form_si, form_sa
  24. };
  25. inline static form_type interpret_form_str(const char* form_str);
  26. //
  27. // eigs_sym()
  28. template<typename eT, typename T1>
  29. inline static bool eigs_sym(Col<eT>& eigval, Mat<eT>& eigvec, const SpBase<eT, T1>& X, const uword n_eigvals, const char* form_str, const eT default_tol);
  30. template<typename eT>
  31. inline static bool eigs_sym_newarp(Col<eT>& eigval, Mat<eT>& eigvec, const SpMat<eT>& X, const uword n_eigvals, const char* form_str, const eT default_tol);
  32. template<typename eT>
  33. inline static bool eigs_sym_arpack(Col<eT>& eigval, Mat<eT>& eigvec, const SpMat<eT>& X, const uword n_eigvals, const char* form_str, const eT default_tol);
  34. //
  35. // eigs_gen()
  36. template<typename T, typename T1>
  37. inline static bool eigs_gen(Col< std::complex<T> >& eigval, Mat< std::complex<T> >& eigvec, const SpBase<T, T1>& X, const uword n_eigvals, const char* form_str, const T default_tol);
  38. template<typename T>
  39. inline static bool eigs_gen_newarp(Col< std::complex<T> >& eigval, Mat< std::complex<T> >& eigvec, const SpMat<T>& X, const uword n_eigvals, const char* form_str, const T default_tol);
  40. template<typename T>
  41. inline static bool eigs_gen_arpack(Col< std::complex<T> >& eigval, Mat< std::complex<T> >& eigvec, const SpMat<T>& X, const uword n_eigvals, const char* form_str, const T default_tol);
  42. template<typename T, typename T1>
  43. inline static bool eigs_gen(Col< std::complex<T> >& eigval, Mat< std::complex<T> >& eigvec, const SpBase< std::complex<T>, T1>& X, const uword n_eigvals, const char* form_str, const T default_tol);
  44. //
  45. // spsolve() via SuperLU
  46. template<typename T1, typename T2>
  47. inline static bool spsolve_simple(Mat<typename T1::elem_type>& out, const SpBase<typename T1::elem_type, T1>& A, const Base<typename T1::elem_type, T2>& B, const superlu_opts& user_opts);
  48. template<typename T1, typename T2>
  49. inline static bool spsolve_refine(Mat<typename T1::elem_type>& out, typename T1::pod_type& out_rcond, const SpBase<typename T1::elem_type, T1>& A, const Base<typename T1::elem_type, T2>& B, const superlu_opts& user_opts);
  50. #if defined(ARMA_USE_SUPERLU)
  51. inline static void set_superlu_opts(superlu::superlu_options_t& options, const superlu_opts& user_opts);
  52. template<typename eT>
  53. inline static bool copy_to_supermatrix(superlu::SuperMatrix& out, const SpMat<eT>& A);
  54. template<typename eT>
  55. inline static bool wrap_to_supermatrix(superlu::SuperMatrix& out, const Mat<eT>& A);
  56. inline static void destroy_supermatrix(superlu::SuperMatrix& out);
  57. #endif
  58. private:
  59. // calls arpack saupd()/naupd() because the code is so similar for each
  60. // all of the extra variables are later used by seupd()/neupd(), but those
  61. // functions are very different and we can't combine their code
  62. template<typename eT, typename T>
  63. inline static void run_aupd
  64. (
  65. const uword n_eigvals, char* which, const SpMat<T>& X, const bool sym,
  66. blas_int& n, eT& tol,
  67. podarray<T>& resid, blas_int& ncv, podarray<T>& v, blas_int& ldv,
  68. podarray<blas_int>& iparam, podarray<blas_int>& ipntr,
  69. podarray<T>& workd, podarray<T>& workl, blas_int& lworkl, podarray<eT>& rwork,
  70. blas_int& info
  71. );
  72. template<typename eT>
  73. inline static bool rudimentary_sym_check(const SpMat<eT>& X);
  74. template<typename T>
  75. inline static bool rudimentary_sym_check(const SpMat< std::complex<T> >& X);
  76. };
  77. //! @}