1 /*
2  *   Copyright (c) 2012, Michael Lehn
3  *
4  *   All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *   1) Redistributions of source code must retain the above copyright
11  *      notice, this list of conditions and the following disclaimer.
12  *   2) Redistributions in binary form must reproduce the above copyright
13  *      notice, this list of conditions and the following disclaimer in
14  *      the documentation and/or other materials provided with the
15  *      distribution.
16  *   3) Neither the name of the FLENS development group nor the names of
17  *      its contributors may be used to endorse or promote products derived
18  *      from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef CXXLAPACK_INTERFACE_TRSYL_TCC
34 #define CXXLAPACK_INTERFACE_TRSYL_TCC 1
35 
36 #include <iostream>
37 #include "xflens/cxxlapack/interface/interface.h"
38 #include "xflens/cxxlapack/netlib/netlib.h"
39 
40 namespace cxxlapack {
41 
42 template <typename IndexType>
43 IndexType
trsyl(char transA,char transB,IndexType sign,IndexType m,IndexType n,const float * A,IndexType ldA,const float * B,IndexType ldB,float * C,IndexType ldC,float & scale)44 trsyl(char          transA,
45       char          transB,
46       IndexType     sign,
47       IndexType     m,
48       IndexType     n,
49       const float   *A,
50       IndexType     ldA,
51       const float   *B,
52       IndexType     ldB,
53       float         *C,
54       IndexType     ldC,
55       float         &scale)
56 {
57     CXXLAPACK_DEBUG_OUT("strsyl");
58 
59     IndexType info;
60     LAPACK_IMPL(strsyl)(&transA,
61                         &transB,
62                         &sign,
63                         &m,
64                         &n,
65                         A,
66                         &ldA,
67                         B,
68                         &ldB,
69                         C,
70                         &ldC,
71                         &scale,
72                         &info);
73 #   ifndef NDEBUG
74     if (info<0) {
75         std::cerr << "info = " << info << std::endl;
76     }
77 #   endif
78     ASSERT(info>=0);
79     return info;
80 }
81 
82 
83 template <typename IndexType>
84 IndexType
trsyl(char transA,char transB,IndexType sign,IndexType m,IndexType n,const double * A,IndexType ldA,const double * B,IndexType ldB,double * C,IndexType ldC,double & scale)85 trsyl(char          transA,
86       char          transB,
87       IndexType     sign,
88       IndexType     m,
89       IndexType     n,
90       const double  *A,
91       IndexType     ldA,
92       const double  *B,
93       IndexType     ldB,
94       double        *C,
95       IndexType     ldC,
96       double        &scale)
97 {
98     CXXLAPACK_DEBUG_OUT("dtrsyl");
99 
100     IndexType info;
101     LAPACK_IMPL(dtrsyl)(&transA,
102                         &transB,
103                         &sign,
104                         &m,
105                         &n,
106                         A,
107                         &ldA,
108                         B,
109                         &ldB,
110                         C,
111                         &ldC,
112                         &scale,
113                         &info);
114 #   ifndef NDEBUG
115     if (info<0) {
116         std::cerr << "info = " << info << std::endl;
117     }
118 #   endif
119     ASSERT(info>=0);
120     return info;
121 }
122 
123 template <typename IndexType>
124 IndexType
trsyl(char transA,char transB,IndexType sign,IndexType m,IndexType n,const std::complex<float> * A,const IndexType ldA,const std::complex<float> * B,const IndexType ldB,std::complex<float> * C,const IndexType ldC,float & scale)125 trsyl(char                          transA,
126       char                          transB,
127       IndexType                     sign,
128       IndexType                     m,
129       IndexType                     n,
130       const std::complex<float >    *A,
131       const IndexType               ldA,
132       const std::complex<float >    *B,
133       const IndexType               ldB,
134       std::complex<float >          *C,
135       const IndexType               ldC,
136       float                         &scale)
137 {
138     CXXLAPACK_DEBUG_OUT("ctrsyl");
139 
140     IndexType info;
141     LAPACK_IMPL(ctrsyl)(&transA,
142                         &transB,
143                         &sign,
144                         &m,
145                         &n,
146                         reinterpret_cast<const float  *>(A),
147                         &ldA,
148                         reinterpret_cast<const float  *>(B),
149                         &ldB,
150                         reinterpret_cast<float  *>(C),
151                         &ldC,
152                         &scale,
153                         &info);
154 #   ifndef NDEBUG
155     if (info<0) {
156         std::cerr << "info = " << info << std::endl;
157     }
158 #   endif
159     ASSERT(info>=0);
160     return info;
161 }
162 
163 
164 template <typename IndexType>
165 IndexType
trsyl(char transA,char transB,IndexType sign,IndexType m,IndexType n,const std::complex<double> * A,const IndexType ldA,const std::complex<double> * B,const IndexType ldB,std::complex<double> * C,const IndexType ldC,double & scale)166 trsyl(char                          transA,
167       char                          transB,
168       IndexType                     sign,
169       IndexType                     m,
170       IndexType                     n,
171       const std::complex<double>    *A,
172       const IndexType               ldA,
173       const std::complex<double>    *B,
174       const IndexType               ldB,
175       std::complex<double>          *C,
176       const IndexType               ldC,
177       double                        &scale)
178 {
179     CXXLAPACK_DEBUG_OUT("ztrsyl");
180 
181     IndexType info;
182     LAPACK_IMPL(ztrsyl)(&transA,
183                         &transB,
184                         &sign,
185                         &m,
186                         &n,
187                         reinterpret_cast<const double *>(A),
188                         &ldA,
189                         reinterpret_cast<const double *>(B),
190                         &ldB,
191                         reinterpret_cast<double *>(C),
192                         &ldC,
193                         &scale,
194                         &info);
195 #   ifndef NDEBUG
196     if (info<0) {
197         std::cerr << "info = " << info << std::endl;
198     }
199 #   endif
200     ASSERT(info>=0);
201     return info;
202 }
203 
204 } // namespace cxxlapack
205 
206 #endif // CXXLAPACK_INTERFACE_TRSYL_TCC
207