9 #ifndef __RAVELIN_CBLAS_H__
10 #define __RAVELIN_CBLAS_H__
18 #define __BEGIN_DECLS extern "C" {
30 #define CBLAS_INDEX size_t
32 enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102};
33 enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113};
34 enum CBLAS_UPLO {CblasUpper=121, CblasLower=122};
35 enum CBLAS_DIAG {CblasNonUnit=131, CblasUnit=132};
36 enum CBLAS_SIDE {CblasLeft=141, CblasRight=142};
43 float cblas_sdsdot(
const int N,
const float alpha,
const float *X,
44 const int incX,
const float *Y,
const int incY);
45 double cblas_dsdot(
const int N,
const float *X,
const int incX,
const float *Y,
47 float cblas_sdot(
const int N,
const float *X,
const int incX,
48 const float *Y,
const int incY);
49 double cblas_ddot(
const int N,
const double *X,
const int incX,
50 const double *Y,
const int incY);
55 float cblas_snrm2(
const int N,
const float *X,
const int incX);
56 float cblas_sasum(
const int N,
const float *X,
const int incX);
58 double cblas_dnrm2(
const int N,
const double *X,
const int incX);
59 double cblas_dasum(
const int N,
const double *X,
const int incX);
64 CBLAS_INDEX cblas_isamax(
const int N,
const float *X,
const int incX);
65 CBLAS_INDEX cblas_idamax(
const int N,
const double *X,
const int incX);
76 void cblas_sswap(
const int N,
float *X,
const int incX,
77 float *Y,
const int incY);
78 void cblas_scopy(
const int N,
const float *X,
const int incX,
79 float *Y,
const int incY);
80 void cblas_saxpy(
const int N,
const float alpha,
const float *X,
81 const int incX,
float *Y,
const int incY);
83 void cblas_dswap(
const int N,
double *X,
const int incX,
84 double *Y,
const int incY);
85 void cblas_dcopy(
const int N,
const double *X,
const int incX,
86 double *Y,
const int incY);
87 void cblas_daxpy(
const int N,
const double alpha,
const double *X,
88 const int incX,
double *Y,
const int incY);
95 void cblas_srotg(
float *a,
float *b,
float *c,
float *s);
96 void cblas_srotmg(
float *d1,
float *d2,
float *b1,
const float b2,
float *P);
97 void cblas_srot(
const int N,
float *X,
const int incX,
98 float *Y,
const int incY,
const float c,
const float s);
99 void cblas_srotm(
const int N,
float *X,
const int incX,
100 float *Y,
const int incY,
const float *P);
102 void cblas_drotg(
double *a,
double *b,
double *c,
double *s);
103 void cblas_drotmg(
double *d1,
double *d2,
double *b1,
const double b2,
double *P);
104 void cblas_drot(
const int N,
double *X,
const int incX,
105 double *Y,
const int incY,
const double c,
const double s);
106 void cblas_drotm(
const int N,
double *X,
const int incX,
107 double *Y,
const int incY,
const double *P);
113 void cblas_sscal(
const int N,
const float alpha,
float *X,
const int incX);
114 void cblas_dscal(
const int N,
const double alpha,
double *X,
const int incX);
125 void cblas_sgemv(
const enum CBLAS_ORDER order,
126 const enum CBLAS_TRANSPOSE TransA,
const int M,
const int N,
127 const float alpha,
const float *A,
const int lda,
128 const float *X,
const int incX,
const float beta,
129 float *Y,
const int incY);
130 void cblas_sgbmv(
const enum CBLAS_ORDER order,
131 const enum CBLAS_TRANSPOSE TransA,
const int M,
const int N,
132 const int KL,
const int KU,
const float alpha,
133 const float *A,
const int lda,
const float *X,
134 const int incX,
const float beta,
float *Y,
const int incY);
135 void cblas_strmv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
136 const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag,
137 const int N,
const float *A,
const int lda,
138 float *X,
const int incX);
139 void cblas_stbmv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
140 const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag,
141 const int N,
const int K,
const float *A,
const int lda,
142 float *X,
const int incX);
143 void cblas_stpmv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
144 const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag,
145 const int N,
const float *Ap,
float *X,
const int incX);
146 void cblas_strsv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
147 const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag,
148 const int N,
const float *A,
const int lda,
float *X,
150 void cblas_stbsv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
151 const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag,
152 const int N,
const int K,
const float *A,
const int lda,
153 float *X,
const int incX);
154 void cblas_stpsv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
155 const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag,
156 const int N,
const float *Ap,
float *X,
const int incX);
158 void cblas_dgemv(
const enum CBLAS_ORDER order,
159 const enum CBLAS_TRANSPOSE TransA,
const int M,
const int N,
160 const double alpha,
const double *A,
const int lda,
161 const double *X,
const int incX,
const double beta,
162 double *Y,
const int incY);
163 void cblas_dgbmv(
const enum CBLAS_ORDER order,
164 const enum CBLAS_TRANSPOSE TransA,
const int M,
const int N,
165 const int KL,
const int KU,
const double alpha,
166 const double *A,
const int lda,
const double *X,
167 const int incX,
const double beta,
double *Y,
const int incY);
168 void cblas_dtrmv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
169 const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag,
170 const int N,
const double *A,
const int lda,
171 double *X,
const int incX);
172 void cblas_dtbmv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
173 const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag,
174 const int N,
const int K,
const double *A,
const int lda,
175 double *X,
const int incX);
176 void cblas_dtpmv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
177 const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag,
178 const int N,
const double *Ap,
double *X,
const int incX);
179 void cblas_dtrsv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
180 const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag,
181 const int N,
const double *A,
const int lda,
double *X,
183 void cblas_dtbsv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
184 const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag,
185 const int N,
const int K,
const double *A,
const int lda,
186 double *X,
const int incX);
187 void cblas_dtpsv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
188 const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag,
189 const int N,
const double *Ap,
double *X,
const int incX);
195 void cblas_ssymv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
196 const int N,
const float alpha,
const float *A,
197 const int lda,
const float *X,
const int incX,
198 const float beta,
float *Y,
const int incY);
199 void cblas_ssbmv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
200 const int N,
const int K,
const float alpha,
const float *A,
201 const int lda,
const float *X,
const int incX,
202 const float beta,
float *Y,
const int incY);
203 void cblas_sspmv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
204 const int N,
const float alpha,
const float *Ap,
205 const float *X,
const int incX,
206 const float beta,
float *Y,
const int incY);
207 void cblas_sger(
const enum CBLAS_ORDER order,
const int M,
const int N,
208 const float alpha,
const float *X,
const int incX,
209 const float *Y,
const int incY,
float *A,
const int lda);
210 void cblas_ssyr(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
211 const int N,
const float alpha,
const float *X,
212 const int incX,
float *A,
const int lda);
213 void cblas_sspr(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
214 const int N,
const float alpha,
const float *X,
215 const int incX,
float *Ap);
216 void cblas_ssyr2(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
217 const int N,
const float alpha,
const float *X,
218 const int incX,
const float *Y,
const int incY,
float *A,
220 void cblas_sspr2(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
221 const int N,
const float alpha,
const float *X,
222 const int incX,
const float *Y,
const int incY,
float *A);
224 void cblas_dsymv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
225 const int N,
const double alpha,
const double *A,
226 const int lda,
const double *X,
const int incX,
227 const double beta,
double *Y,
const int incY);
228 void cblas_dsbmv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
229 const int N,
const int K,
const double alpha,
const double *A,
230 const int lda,
const double *X,
const int incX,
231 const double beta,
double *Y,
const int incY);
232 void cblas_dspmv(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
233 const int N,
const double alpha,
const double *Ap,
234 const double *X,
const int incX,
235 const double beta,
double *Y,
const int incY);
236 void cblas_dger(
const enum CBLAS_ORDER order,
const int M,
const int N,
237 const double alpha,
const double *X,
const int incX,
238 const double *Y,
const int incY,
double *A,
const int lda);
239 void cblas_dsyr(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
240 const int N,
const double alpha,
const double *X,
241 const int incX,
double *A,
const int lda);
242 void cblas_dspr(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
243 const int N,
const double alpha,
const double *X,
244 const int incX,
double *Ap);
245 void cblas_dsyr2(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
246 const int N,
const double alpha,
const double *X,
247 const int incX,
const double *Y,
const int incY,
double *A,
249 void cblas_dspr2(
const enum CBLAS_ORDER order,
const enum CBLAS_UPLO Uplo,
250 const int N,
const double alpha,
const double *X,
251 const int incX,
const double *Y,
const int incY,
double *A);
263 void cblas_sgemm(
const enum CBLAS_ORDER Order,
const enum CBLAS_TRANSPOSE TransA,
264 const enum CBLAS_TRANSPOSE TransB,
const int M,
const int N,
265 const int K,
const float alpha,
const float *A,
266 const int lda,
const float *B,
const int ldb,
267 const float beta,
float *C,
const int ldc);
268 void cblas_ssymm(
const enum CBLAS_ORDER Order,
const enum CBLAS_SIDE Side,
269 const enum CBLAS_UPLO Uplo,
const int M,
const int N,
270 const float alpha,
const float *A,
const int lda,
271 const float *B,
const int ldb,
const float beta,
272 float *C,
const int ldc);
273 void cblas_ssyrk(
const enum CBLAS_ORDER Order,
const enum CBLAS_UPLO Uplo,
274 const enum CBLAS_TRANSPOSE Trans,
const int N,
const int K,
275 const float alpha,
const float *A,
const int lda,
276 const float beta,
float *C,
const int ldc);
277 void cblas_ssyr2k(
const enum CBLAS_ORDER Order,
const enum CBLAS_UPLO Uplo,
278 const enum CBLAS_TRANSPOSE Trans,
const int N,
const int K,
279 const float alpha,
const float *A,
const int lda,
280 const float *B,
const int ldb,
const float beta,
281 float *C,
const int ldc);
282 void cblas_strmm(
const enum CBLAS_ORDER Order,
const enum CBLAS_SIDE Side,
283 const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA,
284 const enum CBLAS_DIAG Diag,
const int M,
const int N,
285 const float alpha,
const float *A,
const int lda,
286 float *B,
const int ldb);
287 void cblas_strsm(
const enum CBLAS_ORDER Order,
const enum CBLAS_SIDE Side,
288 const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA,
289 const enum CBLAS_DIAG Diag,
const int M,
const int N,
290 const float alpha,
const float *A,
const int lda,
291 float *B,
const int ldb);
293 void cblas_dgemm(
const enum CBLAS_ORDER Order,
const enum CBLAS_TRANSPOSE TransA,
294 const enum CBLAS_TRANSPOSE TransB,
const int M,
const int N,
295 const int K,
const double alpha,
const double *A,
296 const int lda,
const double *B,
const int ldb,
297 const double beta,
double *C,
const int ldc);
298 void cblas_dsymm(
const enum CBLAS_ORDER Order,
const enum CBLAS_SIDE Side,
299 const enum CBLAS_UPLO Uplo,
const int M,
const int N,
300 const double alpha,
const double *A,
const int lda,
301 const double *B,
const int ldb,
const double beta,
302 double *C,
const int ldc);
303 void cblas_dsyrk(
const enum CBLAS_ORDER Order,
const enum CBLAS_UPLO Uplo,
304 const enum CBLAS_TRANSPOSE Trans,
const int N,
const int K,
305 const double alpha,
const double *A,
const int lda,
306 const double beta,
double *C,
const int ldc);
307 void cblas_dsyr2k(
const enum CBLAS_ORDER Order,
const enum CBLAS_UPLO Uplo,
308 const enum CBLAS_TRANSPOSE Trans,
const int N,
const int K,
309 const double alpha,
const double *A,
const int lda,
310 const double *B,
const int ldb,
const double beta,
311 double *C,
const int ldc);
312 void cblas_dtrmm(
const enum CBLAS_ORDER Order,
const enum CBLAS_SIDE Side,
313 const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA,
314 const enum CBLAS_DIAG Diag,
const int M,
const int N,
315 const double alpha,
const double *A,
const int lda,
316 double *B,
const int ldb);
317 void cblas_dtrsm(
const enum CBLAS_ORDER Order,
const enum CBLAS_SIDE Side,
318 const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA,
319 const enum CBLAS_DIAG Diag,
const int M,
const int N,
320 const double alpha,
const double *A,
const int lda,
321 double *B,
const int ldb);
323 void cblas_xerbla(
int p,
const char *rout,
const char *form, ...);
331 static void rotg(T& a, T& b, T& c, T& s);
334 static void rot(
const int N, T* X,
const int incX, T* Y,
const int incY,
const T c,
const T s);
337 static void scal(
int N, T alpha, T* X,
int incX);
340 static void copy(
int N,
const T* X,
int incX, T* Y,
int incY);
343 static void axpy(
int N, T alpha,
const T* X,
int incX, T* Y,
int incY);
346 static T dot(
int N,
const T* X,
int incX,
const T* Y,
int incY);
349 static T nrm2(
int N,
const T* X,
int incX);
352 static void ger(
enum CBLAS_ORDER order,
int M,
int N, T alpha,
const T* X,
int incX,
const T* Y,
int incY, T* A,
int lda);
355 static void ger(
enum CBLAS_ORDER order,
int M,
int N,
const T* X,
int incX,
const T* Y,
int incY, T* A,
int lda)
357 ger(order, M, N, (T) 1.0, X, incX, Y, incY, A, lda);
361 static void gemv(
enum CBLAS_ORDER order, CBLAS_TRANSPOSE transA,
int M,
int N, T alpha,
const T* A,
int lda,
const T* X,
int incX, T beta, T* Y,
int incY);
363 template <
class Mat,
class Vec1,
class Vec2,
class T>
364 static void gemv(CBLAS_TRANSPOSE trans_m,
int M,
int N,
const Mat& m,
int ldm,
const Vec1& v,
int incv, T alpha, T beta, Vec2& target,
int inctarget) { gemv(CblasColMajor, trans_m, M, N, alpha, m.begin(), ldm, v.begin(), incv, beta, target.begin(), inctarget); }
367 static void gemm(
enum CBLAS_ORDER order, CBLAS_TRANSPOSE transA, CBLAS_TRANSPOSE transB,
int M,
int N,
int K, T alpha,
const T* A,
int lda,
const T* B,
int ldb, T beta, T* C,
int ldc);
370 static void trsm(
enum CBLAS_SIDE side,
371 enum CBLAS_UPLO uplo,
enum CBLAS_TRANSPOSE transA,
372 int m,
int n, T alpha,
const T* A,
int lda, T* B,
int ldb);
375 static void trsv(
enum CBLAS_UPLO uplo,
enum CBLAS_TRANSPOSE transA,
376 int n,
const T* A,
int lda, T* x,
int incx);
378 template <
class Mat1,
class Mat2,
class T>
379 static void trsm(
enum CBLAS_SIDE side,
380 enum CBLAS_UPLO uplo,
enum CBLAS_TRANSPOSE transA,
381 int m,
int n, T alpha,
const Mat1& A,
int lda, Mat2& B,
int ldb)
383 trsm(CblasColMajor, side, uplo, transA, CblasNonUnit, m, n, alpha, A.begin(), lda, B.begin(), ldb);
386 template <
class Mat,
class Vec>
387 static void trsv(
enum CBLAS_UPLO uplo,
enum CBLAS_TRANSPOSE transA,
388 int n,
const Mat& A,
int lda, Vec& x,
int incx)
390 trsv(uplo, transA, n, A.begin(), lda, x.begin(), incx);
393 template <
class Matrix>
394 static unsigned rows(
const Matrix& m, CBLAS_TRANSPOSE trans)
396 return (trans == CblasNoTrans) ? m.rows() : m.columns();
399 template <
class Matrix>
400 static unsigned columns(
const Matrix& m, CBLAS_TRANSPOSE trans)
402 return (trans == CblasNoTrans) ? m.columns() : m.rows();