1 /*
2  *   Copyright (c) 2012, Michael Lehn, Klaus Pototzky
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_PTRFS_TCC
34 #define CXXLAPACK_INTERFACE_PTRFS_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
ptrfs(IndexType n,IndexType nRhs,const float * d,const float * e,const float * df,const float * ef,const float * B,IndexType ldB,float * X,IndexType ldX,float * ferr,float * berr,float * work)44 ptrfs(IndexType             n,
45       IndexType             nRhs,
46       const float           *d,
47       const float           *e,
48       const float           *df,
49       const float           *ef,
50       const float           *B,
51       IndexType             ldB,
52       float                 *X,
53       IndexType             ldX,
54       float                 *ferr,
55       float                 *berr,
56       float                 *work)
57 {
58     CXXLAPACK_DEBUG_OUT("sptrfs");
59 
60     IndexType info;
61     LAPACK_IMPL(sptrfs)(&n,
62                         &nRhs,
63                         d,
64                         e,
65                         df,
66                         ef,
67                         B,
68                         &ldB,
69                         X,
70                         &ldX,
71                         ferr,
72                         berr,
73                         work,
74                         &info);
75 #   ifndef NDEBUG
76     if (info<0) {
77         std::cerr << "info = " << info << std::endl;
78     }
79 #   endif
80     ASSERT(info>=0);
81     return info;
82 }
83 
84 
85 template <typename IndexType>
86 IndexType
ptrfs(IndexType n,IndexType nRhs,const double * d,const double * e,const double * df,const double * ef,const double * B,IndexType ldB,double * X,IndexType ldX,double * ferr,double * berr,double * work)87 ptrfs(IndexType             n,
88       IndexType             nRhs,
89       const double          *d,
90       const double          *e,
91       const double          *df,
92       const double          *ef,
93       const double          *B,
94       IndexType             ldB,
95       double                *X,
96       IndexType             ldX,
97       double                *ferr,
98       double                *berr,
99       double                *work)
100 {
101     CXXLAPACK_DEBUG_OUT("dptrfs");
102 
103     IndexType info;
104     LAPACK_IMPL(dptrfs)(&n,
105                         &nRhs,
106                         d,
107                         e,
108                         df,
109                         ef,
110                         B,
111                         &ldB,
112                         X,
113                         &ldX,
114                         ferr,
115                         berr,
116                         work,
117                         &info);
118 #   ifndef NDEBUG
119     if (info<0) {
120         std::cerr << "info = " << info << std::endl;
121     }
122 #   endif
123     ASSERT(info>=0);
124     return info;
125 }
126 
127 
128 
129 template <typename IndexType>
130 IndexType
ptrfs(IndexType n,IndexType nRhs,const float * d,const std::complex<float> * e,const float * df,const std::complex<float> * ef,const std::complex<float> * B,IndexType ldB,std::complex<float> * X,IndexType ldX,float * ferr,float * berr,std::complex<float> * work)131 ptrfs(IndexType                   n,
132       IndexType                   nRhs,
133       const float                 *d,
134       const std::complex<float >  *e,
135       const float                 *df,
136       const std::complex<float >  *ef,
137       const std::complex<float >  *B,
138       IndexType                   ldB,
139       std::complex<float >        *X,
140       IndexType                   ldX,
141       float                       *ferr,
142       float                       *berr,
143       std::complex<float >        *work)
144 {
145     CXXLAPACK_DEBUG_OUT("cptrfs");
146 
147     IndexType info;
148     LAPACK_IMPL(cptrfs)(&n,
149                         &nRhs,
150                         d,
151                         reinterpret_cast<const float  *>(e),
152                         df,
153                         reinterpret_cast<const float  *>(ef),
154                         reinterpret_cast<const float  *>(B),
155                         &ldB,
156                         reinterpret_cast<float  *>(X),
157                         &ldX,
158                         ferr,
159                         berr,
160                         reinterpret_cast<float  *>(work),
161                         &info);
162 #   ifndef NDEBUG
163     if (info<0) {
164         std::cerr << "info = " << info << std::endl;
165     }
166 #   endif
167     ASSERT(info>=0);
168     return info;
169 }
170 
171 template <typename IndexType>
172 IndexType
ptrfs(IndexType n,IndexType nRhs,const double * d,const std::complex<double> * e,const double * df,const std::complex<double> * ef,const std::complex<double> * B,IndexType ldB,std::complex<double> * X,IndexType ldX,double * ferr,double * berr,std::complex<double> * work)173 ptrfs(IndexType                   n,
174       IndexType                   nRhs,
175       const double                *d,
176       const std::complex<double>  *e,
177       const double                *df,
178       const std::complex<double>  *ef,
179       const std::complex<double>  *B,
180       IndexType                   ldB,
181       std::complex<double>        *X,
182       IndexType                   ldX,
183       double                      *ferr,
184       double                      *berr,
185       std::complex<double>        *work)
186 {
187     CXXLAPACK_DEBUG_OUT("zptrfs");
188 
189     IndexType info;
190     LAPACK_IMPL(zptrfs)(&n,
191                         &nRhs,
192                         d,
193                         reinterpret_cast<const double *>(e),
194                         df,
195                         reinterpret_cast<const double *>(ef),
196                         reinterpret_cast<const double *>(B),
197                         &ldB,
198                         reinterpret_cast<double *>(X),
199                         &ldX,
200                         ferr,
201                         berr,
202                         reinterpret_cast<double *>(work),
203                         &info);
204 #   ifndef NDEBUG
205     if (info<0) {
206         std::cerr << "info = " << info << std::endl;
207     }
208 #   endif
209     ASSERT(info>=0);
210     return info;
211 }
212 
213 } // namespace cxxlapack
214 
215 #endif // CXXLAPACK_INTERFACE_PTRFS_TCC
216