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_LAQR4_TCC
34 #define CXXLAPACK_INTERFACE_LAQR4_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
laqr4(bool wantT,bool wantZ,IndexType n,const IndexType iLo,const IndexType iHi,float * H,const IndexType ldH,float * wr,float * wi,const IndexType iLoZ,const IndexType iHiZ,float * Z,const IndexType ldZ,float * work,const IndexType lWork)44 laqr4(bool              wantT,
45       bool              wantZ,
46       IndexType         n,
47       const IndexType   iLo,
48       const IndexType   iHi,
49       float             *H,
50       const IndexType   ldH,
51       float             *wr,
52       float             *wi,
53       const IndexType   iLoZ,
54       const IndexType   iHiZ,
55       float             *Z,
56       const IndexType   ldZ,
57       float             *work,
58       const IndexType   lWork)
59 {
60     CXXLAPACK_DEBUG_OUT("slaqr4");
61 
62     IndexType  info;
63     IndexType  wantT_ = wantT;
64     IndexType  wantZ_ = wantZ;
65     LAPACK_IMPL(slaqr4)(&wantT_,
66                         &wantZ_,
67                         &n,
68                         &iLo,
69                         &iHi,
70                         H,
71                         &ldH,
72                         wr,
73                         wi,
74                         &iLoZ,
75                         &iHiZ,
76                         Z,
77                         &ldZ,
78                         work,
79                         &lWork,
80                         &info);
81 #   ifndef NDEBUG
82     if (info<0) {
83         std::cerr << "info = " << info << std::endl;
84     }
85 #   endif
86     ASSERT(info>=0);
87     return info;
88 }
89 
90 
91 template <typename IndexType>
92 IndexType
laqr4(bool wantT,bool wantZ,IndexType n,const IndexType iLo,const IndexType iHi,double * H,const IndexType ldH,double * wr,double * wi,const IndexType iLoZ,const IndexType iHiZ,double * Z,const IndexType ldZ,double * work,const IndexType lWork)93 laqr4(bool              wantT,
94       bool              wantZ,
95       IndexType         n,
96       const IndexType   iLo,
97       const IndexType   iHi,
98       double            *H,
99       const IndexType   ldH,
100       double            *wr,
101       double            *wi,
102       const IndexType   iLoZ,
103       const IndexType   iHiZ,
104       double            *Z,
105       const IndexType   ldZ,
106       double            *work,
107       const IndexType   lWork)
108 {
109     CXXLAPACK_DEBUG_OUT("dlaqr4");
110 
111     IndexType  info;
112     IndexType  wantT_ = wantT;
113     IndexType  wantZ_ = wantZ;
114     LAPACK_IMPL(dlaqr4)(&wantT_,
115                         &wantZ_,
116                         &n,
117                         &iLo,
118                         &iHi,
119                         H,
120                         &ldH,
121                         wr,
122                         wi,
123                         &iLoZ,
124                         &iHiZ,
125                         Z,
126                         &ldZ,
127                         work,
128                         &lWork,
129                         &info);
130 #   ifndef NDEBUG
131     if (info<0) {
132         std::cerr << "info = " << info << std::endl;
133     }
134 #   endif
135     ASSERT(info>=0);
136     return info;
137 }
138 
139 template <typename IndexType>
140 IndexType
laqr4(bool wantT,bool wantZ,IndexType n,IndexType iLo,IndexType iHi,std::complex<float> * H,IndexType ldH,std::complex<float> * w,IndexType iLoZ,IndexType iHiZ,std::complex<float> * Z,IndexType ldZ,std::complex<float> * work,IndexType lWork)141 laqr4(bool                  wantT,
142       bool                  wantZ,
143       IndexType             n,
144       IndexType             iLo,
145       IndexType             iHi,
146       std::complex<float >  *H,
147       IndexType             ldH,
148       std::complex<float >  *w,
149       IndexType             iLoZ,
150       IndexType             iHiZ,
151       std::complex<float >  *Z,
152       IndexType             ldZ,
153       std::complex<float >  *work,
154       IndexType             lWork)
155 {
156     CXXLAPACK_DEBUG_OUT("claqr4");
157 
158     IndexType info;
159     IndexType wantT_ = wantT;
160     IndexType wantZ_ = wantZ;
161     LAPACK_IMPL(claqr4)(&wantT_,
162                         &wantZ_,
163                         &n,
164                         &iLo,
165                         &iHi,
166                         reinterpret_cast<float  *>(H),
167                         &ldH,
168                         reinterpret_cast<float  *>(w),
169                         &iLoZ,
170                         &iHiZ,
171                         reinterpret_cast<float  *>(Z),
172                         &ldZ,
173                         reinterpret_cast<float  *>(work),
174                         &lWork,
175                         &info);
176 #   ifndef NDEBUG
177     if (info<0) {
178         std::cerr << "info = " << info << std::endl;
179     }
180 #   endif
181     ASSERT(info>=0);
182     return info;
183 }
184 
185 template <typename IndexType>
186 IndexType
laqr4(bool wantT,bool wantZ,IndexType n,IndexType iLo,IndexType iHi,std::complex<double> * H,IndexType ldH,std::complex<double> * w,IndexType iLoZ,IndexType iHiZ,std::complex<double> * Z,IndexType ldZ,std::complex<double> * work,IndexType lWork)187 laqr4(bool                  wantT,
188       bool                  wantZ,
189       IndexType             n,
190       IndexType             iLo,
191       IndexType             iHi,
192       std::complex<double>  *H,
193       IndexType             ldH,
194       std::complex<double>  *w,
195       IndexType             iLoZ,
196       IndexType             iHiZ,
197       std::complex<double>  *Z,
198       IndexType             ldZ,
199       std::complex<double>  *work,
200       IndexType             lWork)
201 {
202     CXXLAPACK_DEBUG_OUT("zlaqr4");
203 
204     IndexType info;
205     IndexType wantT_ = wantT;
206     IndexType wantZ_ = wantZ;
207     LAPACK_IMPL(zlaqr4)(&wantT_,
208                         &wantZ_,
209                         &n,
210                         &iLo,
211                         &iHi,
212                         reinterpret_cast<double *>(H),
213                         &ldH,
214                         reinterpret_cast<double *>(w),
215                         &iLoZ,
216                         &iHiZ,
217                         reinterpret_cast<double *>(Z),
218                         &ldZ,
219                         reinterpret_cast<double *>(work),
220                         &lWork,
221                         &info);
222 #   ifndef NDEBUG
223     if (info<0) {
224         std::cerr << "info = " << info << std::endl;
225     }
226 #   endif
227     ASSERT(info>=0);
228     return info;
229 }
230 
231 } // namespace cxxlapack
232 
233 #endif // CXXLAPACK_INTERFACE_LAQR4_TCC
234