1 // SPDX-License-Identifier: Apache-2.0
2 //
3 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
4 // Copyright 2008-2016 National ICT Australia (NICTA)
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 // ------------------------------------------------------------------------
17
18
19 //! \addtogroup fn_syl_lyap
20 //! @{
21
22
23 //! find the solution of the Sylvester equation AX + XB = C
24 template<typename T1, typename T2, typename T3>
25 inline
26 bool
syl(Mat<typename T1::elem_type> & out,const Base<typename T1::elem_type,T1> & in_A,const Base<typename T1::elem_type,T2> & in_B,const Base<typename T1::elem_type,T3> & in_C,const typename arma_blas_type_only<typename T1::elem_type>::result * junk=nullptr)27 syl
28 (
29 Mat <typename T1::elem_type> & out,
30 const Base<typename T1::elem_type,T1>& in_A,
31 const Base<typename T1::elem_type,T2>& in_B,
32 const Base<typename T1::elem_type,T3>& in_C,
33 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = nullptr
34 )
35 {
36 arma_extra_debug_sigprint();
37 arma_ignore(junk);
38
39 typedef typename T1::elem_type eT;
40
41 const unwrap_check<T1> tmp_A(in_A.get_ref(), out);
42 const unwrap_check<T2> tmp_B(in_B.get_ref(), out);
43 const unwrap_check<T3> tmp_C(in_C.get_ref(), out);
44
45 const Mat<eT>& A = tmp_A.M;
46 const Mat<eT>& B = tmp_B.M;
47 const Mat<eT>& C = tmp_C.M;
48
49 const bool status = auxlib::syl(out, A, B, C);
50
51 if(status == false)
52 {
53 out.soft_reset();
54 arma_debug_warn_level(3, "syl(): solution not found");
55 }
56
57 return status;
58 }
59
60
61
62 template<typename T1, typename T2, typename T3>
63 inline
64 bool
sylvester(Mat<typename T1::elem_type> & out,const Base<typename T1::elem_type,T1> & in_A,const Base<typename T1::elem_type,T2> & in_B,const Base<typename T1::elem_type,T3> & in_C,const typename arma_blas_type_only<typename T1::elem_type>::result * junk=nullptr)65 sylvester
66 (
67 Mat <typename T1::elem_type> & out,
68 const Base<typename T1::elem_type,T1>& in_A,
69 const Base<typename T1::elem_type,T2>& in_B,
70 const Base<typename T1::elem_type,T3>& in_C,
71 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = nullptr
72 )
73 {
74 arma_ignore(junk);
75 return syl(out, in_A, in_B, in_C);
76 }
77
78
79
80 template<typename T1, typename T2, typename T3>
81 arma_warn_unused
82 inline
83 Mat<typename T1::elem_type>
syl(const Base<typename T1::elem_type,T1> & in_A,const Base<typename T1::elem_type,T2> & in_B,const Base<typename T1::elem_type,T3> & in_C,const typename arma_blas_type_only<typename T1::elem_type>::result * junk=nullptr)84 syl
85 (
86 const Base<typename T1::elem_type,T1>& in_A,
87 const Base<typename T1::elem_type,T2>& in_B,
88 const Base<typename T1::elem_type,T3>& in_C,
89 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = nullptr
90 )
91 {
92 arma_extra_debug_sigprint();
93 arma_ignore(junk);
94
95 typedef typename T1::elem_type eT;
96
97 const unwrap<T1> tmp_A( in_A.get_ref() );
98 const unwrap<T2> tmp_B( in_B.get_ref() );
99 const unwrap<T3> tmp_C( in_C.get_ref() );
100
101 const Mat<eT>& A = tmp_A.M;
102 const Mat<eT>& B = tmp_B.M;
103 const Mat<eT>& C = tmp_C.M;
104
105 Mat<eT> out;
106
107 const bool status = auxlib::syl(out, A, B, C);
108
109 if(status == false)
110 {
111 out.soft_reset();
112 arma_stop_runtime_error("syl(): solution not found");
113 }
114
115 return out;
116 }
117
118
119
120 template<typename T1, typename T2, typename T3>
121 arma_warn_unused
122 inline
123 Mat<typename T1::elem_type>
sylvester(const Base<typename T1::elem_type,T1> & in_A,const Base<typename T1::elem_type,T2> & in_B,const Base<typename T1::elem_type,T3> & in_C,const typename arma_blas_type_only<typename T1::elem_type>::result * junk=nullptr)124 sylvester
125 (
126 const Base<typename T1::elem_type,T1>& in_A,
127 const Base<typename T1::elem_type,T2>& in_B,
128 const Base<typename T1::elem_type,T3>& in_C,
129 const typename arma_blas_type_only<typename T1::elem_type>::result* junk = nullptr
130 )
131 {
132 arma_ignore(junk);
133 return syl(in_A, in_B, in_C);
134 }
135
136
137 //! @}
138