max@0
|
1 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
|
max@0
|
2 // Copyright (C) 2008-2011 Conrad Sanderson
|
max@0
|
3 //
|
max@0
|
4 // This file is part of the Armadillo C++ library.
|
max@0
|
5 // It is provided without any warranty of fitness
|
max@0
|
6 // for any purpose. You can redistribute this file
|
max@0
|
7 // and/or modify it under the terms of the GNU
|
max@0
|
8 // Lesser General Public License (LGPL) as published
|
max@0
|
9 // by the Free Software Foundation, either version 3
|
max@0
|
10 // of the License or (at your option) any later version.
|
max@0
|
11 // (see http://www.opensource.org/licenses for more info)
|
max@0
|
12
|
max@0
|
13
|
max@0
|
14 #ifdef ARMA_USE_ATLAS
|
max@0
|
15
|
max@0
|
16
|
max@0
|
17 //! \namespace atlas namespace for ATLAS functions (imported from the global namespace)
|
max@0
|
18 namespace atlas
|
max@0
|
19 {
|
max@0
|
20
|
max@0
|
21 template<typename eT>
|
max@0
|
22 inline static const eT& tmp_real(const eT& X) { return X; }
|
max@0
|
23
|
max@0
|
24 template<typename T>
|
max@0
|
25 inline static const T& tmp_real(const std::complex<T>& X) { return X.real(); }
|
max@0
|
26
|
max@0
|
27
|
max@0
|
28
|
max@0
|
29 template<typename eT>
|
max@0
|
30 arma_inline
|
max@0
|
31 eT
|
max@0
|
32 cblas_dot(const int N, const eT* X, const eT* Y)
|
max@0
|
33 {
|
max@0
|
34 arma_type_check((is_supported_blas_type<eT>::value == false));
|
max@0
|
35
|
max@0
|
36 if(is_float<eT>::value == true)
|
max@0
|
37 {
|
max@0
|
38 typedef float T;
|
max@0
|
39 return eT( arma_atlas(cblas_sdot)(N, (const T*)X, 1, (const T*)Y, 1) );
|
max@0
|
40 }
|
max@0
|
41 else
|
max@0
|
42 if(is_double<eT>::value == true)
|
max@0
|
43 {
|
max@0
|
44 typedef double T;
|
max@0
|
45 return eT( arma_atlas(cblas_ddot)(N, (const T*)X, 1, (const T*)Y, 1) );
|
max@0
|
46 }
|
max@0
|
47 else
|
max@0
|
48 {
|
max@0
|
49 return eT(0);
|
max@0
|
50 }
|
max@0
|
51 }
|
max@0
|
52
|
max@0
|
53
|
max@0
|
54
|
max@0
|
55 template<typename eT>
|
max@0
|
56 arma_inline
|
max@0
|
57 eT
|
max@0
|
58 cx_cblas_dot(const int N, const eT* X, const eT* Y)
|
max@0
|
59 {
|
max@0
|
60 arma_type_check((is_supported_blas_type<eT>::value == false));
|
max@0
|
61
|
max@0
|
62 if(is_supported_complex_float<eT>::value == true)
|
max@0
|
63 {
|
max@0
|
64 typedef typename std::complex<float> T;
|
max@0
|
65
|
max@0
|
66 T out;
|
max@0
|
67 arma_atlas(cblas_cdotu_sub)(N, (const T*)X, 1, (const T*)Y, 1, &out);
|
max@0
|
68
|
max@0
|
69 return eT(out);
|
max@0
|
70 }
|
max@0
|
71 else
|
max@0
|
72 if(is_supported_complex_double<eT>::value == true)
|
max@0
|
73 {
|
max@0
|
74 typedef typename std::complex<double> T;
|
max@0
|
75
|
max@0
|
76 T out;
|
max@0
|
77 arma_atlas(cblas_zdotu_sub)(N, (const T*)X, 1, (const T*)Y, 1, &out);
|
max@0
|
78
|
max@0
|
79 return eT(out);
|
max@0
|
80 }
|
max@0
|
81 else
|
max@0
|
82 {
|
max@0
|
83 return eT(0);
|
max@0
|
84 }
|
max@0
|
85 }
|
max@0
|
86
|
max@0
|
87
|
max@0
|
88
|
max@0
|
89 template<typename eT>
|
max@0
|
90 inline
|
max@0
|
91 void
|
max@0
|
92 cblas_gemv
|
max@0
|
93 (
|
max@0
|
94 const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
|
max@0
|
95 const int M, const int N,
|
max@0
|
96 const eT alpha,
|
max@0
|
97 const eT *A, const int lda,
|
max@0
|
98 const eT *X, const int incX,
|
max@0
|
99 const eT beta,
|
max@0
|
100 eT *Y, const int incY
|
max@0
|
101 )
|
max@0
|
102 {
|
max@0
|
103 arma_type_check((is_supported_blas_type<eT>::value == false));
|
max@0
|
104
|
max@0
|
105 if(is_float<eT>::value == true)
|
max@0
|
106 {
|
max@0
|
107 typedef float T;
|
max@0
|
108 arma_atlas(cblas_sgemv)(Order, TransA, M, N, (const T)tmp_real(alpha), (const T*)A, lda, (const T*)X, incX, (const T)tmp_real(beta), (T*)Y, incY);
|
max@0
|
109 }
|
max@0
|
110 else
|
max@0
|
111 if(is_double<eT>::value == true)
|
max@0
|
112 {
|
max@0
|
113 typedef double T;
|
max@0
|
114 arma_atlas(cblas_dgemv)(Order, TransA, M, N, (const T)tmp_real(alpha), (const T*)A, lda, (const T*)X, incX, (const T)tmp_real(beta), (T*)Y, incY);
|
max@0
|
115 }
|
max@0
|
116 else
|
max@0
|
117 if(is_supported_complex_float<eT>::value == true)
|
max@0
|
118 {
|
max@0
|
119 typedef std::complex<float> T;
|
max@0
|
120 arma_atlas(cblas_cgemv)(Order, TransA, M, N, (const T*)&alpha, (const T*)A, lda, (const T*)X, incX, (const T*)&beta, (T*)Y, incY);
|
max@0
|
121 }
|
max@0
|
122 else
|
max@0
|
123 if(is_supported_complex_double<eT>::value == true)
|
max@0
|
124 {
|
max@0
|
125 typedef std::complex<double> T;
|
max@0
|
126 arma_atlas(cblas_zgemv)(Order, TransA, M, N, (const T*)&alpha, (const T*)A, lda, (const T*)X, incX, (const T*)&beta, (T*)Y, incY);
|
max@0
|
127 }
|
max@0
|
128 }
|
max@0
|
129
|
max@0
|
130
|
max@0
|
131
|
max@0
|
132 template<typename eT>
|
max@0
|
133 inline
|
max@0
|
134 void
|
max@0
|
135 cblas_gemm
|
max@0
|
136 (
|
max@0
|
137 const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
|
max@0
|
138 const enum CBLAS_TRANSPOSE TransB, const int M, const int N,
|
max@0
|
139 const int K, const eT alpha, const eT *A,
|
max@0
|
140 const int lda, const eT *B, const int ldb,
|
max@0
|
141 const eT beta, eT *C, const int ldc
|
max@0
|
142 )
|
max@0
|
143 {
|
max@0
|
144 arma_type_check((is_supported_blas_type<eT>::value == false));
|
max@0
|
145
|
max@0
|
146 if(is_float<eT>::value == true)
|
max@0
|
147 {
|
max@0
|
148 typedef float T;
|
max@0
|
149 arma_atlas(cblas_sgemm)(Order, TransA, TransB, M, N, K, (const T)tmp_real(alpha), (const T*)A, lda, (const T*)B, ldb, (const T)tmp_real(beta), (T*)C, ldc);
|
max@0
|
150 }
|
max@0
|
151 else
|
max@0
|
152 if(is_double<eT>::value == true)
|
max@0
|
153 {
|
max@0
|
154 typedef double T;
|
max@0
|
155 arma_atlas(cblas_dgemm)(Order, TransA, TransB, M, N, K, (const T)tmp_real(alpha), (const T*)A, lda, (const T*)B, ldb, (const T)tmp_real(beta), (T*)C, ldc);
|
max@0
|
156 }
|
max@0
|
157 else
|
max@0
|
158 if(is_supported_complex_float<eT>::value == true)
|
max@0
|
159 {
|
max@0
|
160 typedef std::complex<float> T;
|
max@0
|
161 arma_atlas(cblas_cgemm)(Order, TransA, TransB, M, N, K, (const T*)&alpha, (const T*)A, lda, (const T*)B, ldb, (const T*)&beta, (T*)C, ldc);
|
max@0
|
162 }
|
max@0
|
163 else
|
max@0
|
164 if(is_supported_complex_double<eT>::value == true)
|
max@0
|
165 {
|
max@0
|
166 typedef std::complex<double> T;
|
max@0
|
167 arma_atlas(cblas_zgemm)(Order, TransA, TransB, M, N, K, (const T*)&alpha, (const T*)A, lda, (const T*)B, ldb, (const T*)&beta, (T*)C, ldc);
|
max@0
|
168 }
|
max@0
|
169 }
|
max@0
|
170
|
max@0
|
171
|
max@0
|
172
|
max@0
|
173 template<typename eT>
|
max@0
|
174 inline
|
max@0
|
175 int
|
max@0
|
176 clapack_getrf
|
max@0
|
177 (
|
max@0
|
178 const enum CBLAS_ORDER Order, const int M, const int N,
|
max@0
|
179 eT *A, const int lda, int *ipiv
|
max@0
|
180 )
|
max@0
|
181 {
|
max@0
|
182 arma_type_check((is_supported_blas_type<eT>::value == false));
|
max@0
|
183
|
max@0
|
184 if(is_float<eT>::value == true)
|
max@0
|
185 {
|
max@0
|
186 typedef float T;
|
max@0
|
187 return arma_atlas(clapack_sgetrf)(Order, M, N, (T*)A, lda, ipiv);
|
max@0
|
188 }
|
max@0
|
189 else
|
max@0
|
190 if(is_double<eT>::value == true)
|
max@0
|
191 {
|
max@0
|
192 typedef double T;
|
max@0
|
193 return arma_atlas(clapack_dgetrf)(Order, M, N, (T*)A, lda, ipiv);
|
max@0
|
194 }
|
max@0
|
195 else
|
max@0
|
196 if(is_supported_complex_float<eT>::value == true)
|
max@0
|
197 {
|
max@0
|
198 typedef std::complex<float> T;
|
max@0
|
199 return arma_atlas(clapack_cgetrf)(Order, M, N, (T*)A, lda, ipiv);
|
max@0
|
200 }
|
max@0
|
201 else
|
max@0
|
202 if(is_supported_complex_double<eT>::value == true)
|
max@0
|
203 {
|
max@0
|
204 typedef std::complex<double> T;
|
max@0
|
205 return arma_atlas(clapack_zgetrf)(Order, M, N, (T*)A, lda, ipiv);
|
max@0
|
206 }
|
max@0
|
207 else
|
max@0
|
208 {
|
max@0
|
209 return -1;
|
max@0
|
210 }
|
max@0
|
211 }
|
max@0
|
212
|
max@0
|
213
|
max@0
|
214
|
max@0
|
215 template<typename eT>
|
max@0
|
216 inline
|
max@0
|
217 int
|
max@0
|
218 clapack_getri
|
max@0
|
219 (
|
max@0
|
220 const enum CBLAS_ORDER Order, const int N, eT *A,
|
max@0
|
221 const int lda, const int *ipiv
|
max@0
|
222 )
|
max@0
|
223 {
|
max@0
|
224 arma_type_check((is_supported_blas_type<eT>::value == false));
|
max@0
|
225
|
max@0
|
226 if(is_float<eT>::value == true)
|
max@0
|
227 {
|
max@0
|
228 typedef float T;
|
max@0
|
229 return arma_atlas(clapack_sgetri)(Order, N, (T*)A, lda, ipiv);
|
max@0
|
230 }
|
max@0
|
231 else
|
max@0
|
232 if(is_double<eT>::value == true)
|
max@0
|
233 {
|
max@0
|
234 typedef double T;
|
max@0
|
235 return arma_atlas(clapack_dgetri)(Order, N, (T*)A, lda, ipiv);
|
max@0
|
236 }
|
max@0
|
237 else
|
max@0
|
238 if(is_supported_complex_float<eT>::value == true)
|
max@0
|
239 {
|
max@0
|
240 typedef std::complex<float> T;
|
max@0
|
241 return arma_atlas(clapack_cgetri)(Order, N, (T*)A, lda, ipiv);
|
max@0
|
242 }
|
max@0
|
243 else
|
max@0
|
244 if(is_supported_complex_double<eT>::value == true)
|
max@0
|
245 {
|
max@0
|
246 typedef std::complex<double> T;
|
max@0
|
247 return arma_atlas(clapack_zgetri)(Order, N, (T*)A, lda, ipiv);
|
max@0
|
248 }
|
max@0
|
249 else
|
max@0
|
250 {
|
max@0
|
251 return -1;
|
max@0
|
252 }
|
max@0
|
253 }
|
max@0
|
254
|
max@0
|
255
|
max@0
|
256
|
max@0
|
257 template<typename eT>
|
max@0
|
258 inline
|
max@0
|
259 int
|
max@0
|
260 clapack_gesv
|
max@0
|
261 (
|
max@0
|
262 const enum CBLAS_ORDER Order,
|
max@0
|
263 const int N, const int NRHS,
|
max@0
|
264 eT* A, const int lda, int* ipiv,
|
max@0
|
265 eT* B, const int ldb
|
max@0
|
266 )
|
max@0
|
267 {
|
max@0
|
268 arma_type_check((is_supported_blas_type<eT>::value == false));
|
max@0
|
269
|
max@0
|
270 if(is_float<eT>::value == true)
|
max@0
|
271 {
|
max@0
|
272 typedef float T;
|
max@0
|
273 return arma_atlas(clapack_sgesv)(Order, N, NRHS, (T*)A, lda, ipiv, (T*)B, ldb);
|
max@0
|
274 }
|
max@0
|
275 else
|
max@0
|
276 if(is_double<eT>::value == true)
|
max@0
|
277 {
|
max@0
|
278 typedef double T;
|
max@0
|
279 return arma_atlas(clapack_dgesv)(Order, N, NRHS, (T*)A, lda, ipiv, (T*)B, ldb);
|
max@0
|
280 }
|
max@0
|
281 else
|
max@0
|
282 if(is_supported_complex_float<eT>::value == true)
|
max@0
|
283 {
|
max@0
|
284 typedef std::complex<float> T;
|
max@0
|
285 return arma_atlas(clapack_cgesv)(Order, N, NRHS, (T*)A, lda, ipiv, (T*)B, ldb);
|
max@0
|
286 }
|
max@0
|
287 else
|
max@0
|
288 if(is_supported_complex_double<eT>::value == true)
|
max@0
|
289 {
|
max@0
|
290 typedef std::complex<double> T;
|
max@0
|
291 return arma_atlas(clapack_zgesv)(Order, N, NRHS, (T*)A, lda, ipiv, (T*)B, ldb);
|
max@0
|
292 }
|
max@0
|
293 else
|
max@0
|
294 {
|
max@0
|
295 return -1;
|
max@0
|
296 }
|
max@0
|
297 }
|
max@0
|
298
|
max@0
|
299
|
max@0
|
300
|
max@0
|
301 }
|
max@0
|
302
|
max@0
|
303 #endif
|