fn_syl_lyap.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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_syl_lyap
  16. //! @{
  17. //! find the solution of the Sylvester equation AX + XB = C
  18. template<typename T1, typename T2, typename T3>
  19. inline
  20. bool
  21. syl
  22. (
  23. Mat <typename T1::elem_type> & out,
  24. const Base<typename T1::elem_type,T1>& in_A,
  25. const Base<typename T1::elem_type,T2>& in_B,
  26. const Base<typename T1::elem_type,T3>& in_C,
  27. const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
  28. )
  29. {
  30. arma_extra_debug_sigprint();
  31. arma_ignore(junk);
  32. typedef typename T1::elem_type eT;
  33. const unwrap_check<T1> tmp_A(in_A.get_ref(), out);
  34. const unwrap_check<T2> tmp_B(in_B.get_ref(), out);
  35. const unwrap_check<T3> tmp_C(in_C.get_ref(), out);
  36. const Mat<eT>& A = tmp_A.M;
  37. const Mat<eT>& B = tmp_B.M;
  38. const Mat<eT>& C = tmp_C.M;
  39. const bool status = auxlib::syl(out, A, B, C);
  40. if(status == false)
  41. {
  42. out.soft_reset();
  43. arma_debug_warn("syl(): solution not found");
  44. }
  45. return status;
  46. }
  47. template<typename T1, typename T2, typename T3>
  48. arma_warn_unused
  49. inline
  50. Mat<typename T1::elem_type>
  51. syl
  52. (
  53. const Base<typename T1::elem_type,T1>& in_A,
  54. const Base<typename T1::elem_type,T2>& in_B,
  55. const Base<typename T1::elem_type,T3>& in_C,
  56. const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
  57. )
  58. {
  59. arma_extra_debug_sigprint();
  60. arma_ignore(junk);
  61. typedef typename T1::elem_type eT;
  62. const unwrap<T1> tmp_A( in_A.get_ref() );
  63. const unwrap<T2> tmp_B( in_B.get_ref() );
  64. const unwrap<T3> tmp_C( in_C.get_ref() );
  65. const Mat<eT>& A = tmp_A.M;
  66. const Mat<eT>& B = tmp_B.M;
  67. const Mat<eT>& C = tmp_C.M;
  68. Mat<eT> out;
  69. const bool status = auxlib::syl(out, A, B, C);
  70. if(status == false)
  71. {
  72. out.soft_reset();
  73. arma_stop_runtime_error("syl(): solution not found");
  74. }
  75. return out;
  76. }
  77. //! @}