Ravelin
cblas.h
1 /****************************************************************************
2  * Copyright 2006 Evan Drumwright
3  * This library is distributed under the terms of the Apache V2.0
4  * License (obtainable from http://www.apache.org/licenses/LICENSE-2.0).
5  ****************************************************************************/
6 
7 /* This is a copy of the CBLAS standard header. */
8 
9 #ifndef __RAVELIN_CBLAS_H__
10 #define __RAVELIN_CBLAS_H__
11 #include <stddef.h>
12 
13 #undef __BEGIN_DECLS
14 #undef __END_DECLS
15 #ifdef __cplusplus
16 //#include <iostream>
17 //#include <cmath>
18 #define __BEGIN_DECLS extern "C" {
19 #define __END_DECLS }
20 #else
21 #define __BEGIN_DECLS /* empty */
22 #define __END_DECLS /* empty */
23 #endif
24 
25 __BEGIN_DECLS
26 
27 /*
28  * Enumerated and derived types
29  */
30 #define CBLAS_INDEX size_t /* this may vary between platforms */
31 
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};
37 
38 /*
39  * ===========================================================================
40  * Prototypes for level 1 BLAS functions (complex are recast as routines)
41  * ===========================================================================
42  */
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,
46  const int incY);
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);
51 
52 /*
53  * Functions having prefixes S D
54  */
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);
57 
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);
60 
61 /*
62  * Functions having standard prefixes (S D)
63  */
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);
66 
67 /*
68  * ===========================================================================
69  * Prototypes for level 1 BLAS routines
70  * ===========================================================================
71  */
72 
73 /*
74  * Routines with standard prefixes (s, d)
75  */
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);
82 
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);
89 
90 
91 
92 /*
93  * Routines with S and D prefix only
94  */
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);
101 
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);
108 
109 
110 /*
111  * Routines with S D prefixes
112  */
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);
115 
116 /*
117  * ===========================================================================
118  * Prototypes for level 2 BLAS
119  * ===========================================================================
120  */
121 
122 /*
123  * Routines with standard prefixes (S, D)
124  */
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,
149  const int incX);
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);
157 
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,
182  const int incX);
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);
190 
191 
192 /*
193  * Routines with S and D prefixes only
194  */
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,
219  const int lda);
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);
223 
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,
248  const int lda);
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);
252 
253 
254 /*
255  * ===========================================================================
256  * Prototypes for level 3 BLAS
257  * ===========================================================================
258  */
259 
260 /*
261  * Routines with standard 4 prefixes (S, D)
262  */
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);
292 
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);
322 
323 void cblas_xerbla(int p, const char *rout, const char *form, ...);
324 
325 __END_DECLS
326 
327 class CBLAS
328 {
329  public:
330  template <class T>
331  static void rotg(T& a, T& b, T& c, T& s);
332 
333  template <class T>
334  static void rot(const int N, T* X, const int incX, T* Y, const int incY, const T c, const T s);
335 
336  template <class T>
337  static void scal(int N, T alpha, T* X, int incX);
338 
339  template <class T>
340  static void copy(int N, const T* X, int incX, T* Y, int incY);
341 
342  template <class T>
343  static void axpy(int N, T alpha, const T* X, int incX, T* Y, int incY);
344 
345  template <class T>
346  static T dot(int N, const T* X, int incX, const T* Y, int incY);
347 
348  template <class T>
349  static T nrm2(int N, const T* X, int incX);
350 
351  template <class T>
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);
353 
354  template <class T>
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)
356  {
357  ger(order, M, N, (T) 1.0, X, incX, Y, incY, A, lda);
358  }
359 
360  template <class T>
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);
362 
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); }
365 
366  template <class T>
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);
368 
369  template <class T>
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);
373 
374  template <class T>
375  static void trsv(enum CBLAS_UPLO uplo, enum CBLAS_TRANSPOSE transA,
376  int n, const T* A, int lda, T* x, int incx);
377 
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)
382  {
383  trsm(CblasColMajor, side, uplo, transA, CblasNonUnit, m, n, alpha, A.begin(), lda, B.begin(), ldb);
384  }
385 
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)
389  {
390  trsv(uplo, transA, n, A.begin(), lda, x.begin(), incx);
391  }
392 
393  template <class Matrix>
394  static unsigned rows(const Matrix& m, CBLAS_TRANSPOSE trans)
395  {
396  return (trans == CblasNoTrans) ? m.rows() : m.columns();
397  }
398 
399  template <class Matrix>
400  static unsigned columns(const Matrix& m, CBLAS_TRANSPOSE trans)
401  {
402  return (trans == CblasNoTrans) ? m.columns() : m.rows();
403  }
404 };
405 
406 #endif /* __GSL_CBLAS_H__ */
407 
Definition: cblas.h:327