comparison armadillo-2.4.4/include/armadillo_bits/atlas_wrapper.hpp @ 0:8b6102e2a9b0

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