DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
cblas_template.h
Go to the documentation of this file.
1 #ifndef CBLAS_TEMPLATE_H
2 #define CBLAS_TEMPLATE_H
3 
4 //#include "cblas.h" dependency on cblas has been removed
5 
7 static char low='l';
8 static char nonUnit='n';
9 static char upper='u';
10 static int info=0;
11 static char incr='I';
12 static char decr='D';
13 
15 #ifdef HAVE_MKL
16 extern "C" {
17 #endif
18  size_t cblas_idamin(const int n, const double* X, const int incX);
19  size_t cblas_isamin(const int n, const float* X, const int incX);
20 #ifdef HAVE_MKL
21 };
22 #endif
23 
24 extern "C" {
25  void dsytrf_(char* uplo, int* n, double* a, int* lda, int* ipiv,
26  double* work, int* lwork, int* info);
27  void ssytrf_(char* uplo, int* n, float* a, int* lda, int* ipiv,
28  float* work, int* lwork, int* info);
29  void dsytri_(char* uplo, int* n, double* a, int* lda, int* ipiv,
30  double* work, int* info);
31  void ssytri_(char* uplo, int* n, float* a, int* lda, int* ipiv,
32  float* work, int* info);
33  void dtrtri_(char* uplo, char* diag, int* n, double * a, int* lda,
34  int* info);
35  void strtri_(char* uplo, char* diag, int* n, float * a, int* lda,
36  int* info);
37  void dlasrt_(char* id, const int* n, double *d, int* info);
38  void slasrt_(char* id, const int* n, float*d, int* info);
39  void dlasrt2_(char* id, const int* n, double *d, int* key, int* info);
40  void slasrt2_(char* id, const int* n, float*d, int* key, int* info);
41 };
42 
43 #ifdef HAVE_MKL
44 extern "C" {
45  void vdSqr(const int n, const double* vecIn, double* vecOut);
46  void vsSqr(const int n, const float* vecIn, float* vecOut);
47  void vdSqrt(const int n, const double* vecIn, double* vecOut);
48  void vsSqrt(const int n, const float* vecIn, float* vecOut);
49  void vdInvSqrt(const int n, const double* vecIn, double* vecOut);
50  void vsInvSqrt(const int n, const float* vecIn, float* vecOut);
51  void vdSub(const int n, const double* vecIn, const double* vecIn2, double* vecOut);
52  void vsSub(const int n, const float* vecIn, const float* vecIn2, float* vecOut);
53  void vdDiv(const int n, const double* vecIn, const double* vecIn2, double* vecOut);
54  void vsDiv(const int n, const float* vecIn, const float* vecIn2, float* vecOut);
55  void vdExp(const int n, const double* vecIn, double* vecOut);
56  void vsExp(const int n, const float* vecIn, float* vecOut);
57  void vdInv(const int n, const double* vecIn, double* vecOut);
58  void vsInv(const int n, const float* vecIn, float* vecOut);
59  void vdAdd(const int n, const double* vecIn, const double* vecIn2, double* vecOut);
60  void vsAdd(const int n, const float* vecIn, const float* vecIn2, float* vecOut);
61  void vdMul(const int n, const double* vecIn, const double* vecIn2, double* vecOut);
62  void vsMul(const int n, const float* vecIn, const float* vecIn2, float* vecOut);
63  void vdAbs(const int n, const double* vecIn, double* vecOut);
64  void vsAbs(const int n, const float* vecIn, float* vecOut);
65 }
66 #endif
67 
68 
69 // Interfaces to a few BLAS function, Level 1
71 template <typename T> T cblas_nrm2(const int n, const T* X, const int incX);
73 template <typename T> void cblas_copy(const int n, const T* X, const int incX,
74  T* Y, const int incY);
76 template <typename T> void cblas_axpy(const int n, const T a, const T* X,
77  const int incX, T* Y, const int incY);
79 template <typename T> void cblas_scal(const int n, const T a, T* X,
80  const int incX);
82 template <typename T> T cblas_asum(const int n, const T* X, const int incX);
84 template <typename T> T cblas_dot(const int n, const T* X, const int incX,
85  const T* Y,const int incY);
87 template <typename T> int cblas_iamin(const int n, const T* X, const int incX);
89 template <typename T> int cblas_iamax(const int n, const T* X, const int incX);
90 
91 // Interfaces to a few BLAS function, Level 2
92 
94 template <typename T> void cblas_gemv(const CBLAS_ORDER order,
95  const CBLAS_TRANSPOSE TransA, const int M,
96  const int N, const T alpha, const T *A, const int lda, const T *X,
97  const int incX, const T beta,T *Y, const int incY);
99 template <typename T> void inline cblas_trmv(const CBLAS_ORDER order, const CBLAS_UPLO Uplo,
100  const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, const int N,
101  const T *A, const int lda, T *X, const int incX);
103 template <typename T> void inline cblas_syr(const CBLAS_ORDER order,
104  const CBLAS_UPLO Uplo, const int N, const T alpha,
105  const T *X, const int incX, T *A, const int lda);
106 
108 template <typename T> inline void cblas_symv(const CBLAS_ORDER order,
109  const CBLAS_UPLO Uplo, const int N,
110  const T alpha, const T *A, const int lda, const T *X,
111  const int incX, const T beta,T *Y, const int incY);
112 
113 
114 // Interfaces to a few BLAS function, Level 3
116 template <typename T> void cblas_gemm(const CBLAS_ORDER Order,
117  const CBLAS_TRANSPOSE TransA, const CBLAS_TRANSPOSE TransB,
118  const int M, const int N, const int K, const T alpha,
119  const T *A, const int lda, const T *B, const int ldb,
120  const T beta, T *C, const int ldc);
122 template <typename T> void cblas_syrk(const CBLAS_ORDER Order,
123  const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE Trans, const int N, const int K,
124  const T alpha, const T *A, const int lda,
125  const T beta, T*C, const int ldc);
127 template <typename T> void cblas_ger(const CBLAS_ORDER order,
128  const int M, const int N, const T alpha, const T *X, const int incX,
129  const T* Y, const int incY, T*A, const int lda);
131 template <typename T> void cblas_trmm(const CBLAS_ORDER Order,
132  const CBLAS_SIDE Side, const CBLAS_UPLO Uplo,
133  const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag,
134  const int M, const int N, const T alpha,
135  const T*A, const int lda,T *B, const int ldb);
136 
137 // Interfaces to a few functions from the Intel Vector Mathematical Library
139 template <typename T> void vSqrt(const int n, const T* vecIn, T* vecOut);
141 template <typename T> void vInvSqrt(const int n, const T* vecIn, T* vecOut);
143 template <typename T> void vSqr(const int n, const T* vecIn, T* vecOut);
145 template <typename T> void vSub(const int n, const T* vecIn, const T* vecIn2, T* vecOut);
147 template <typename T> void vDiv(const int n, const T* vecIn, const T* vecIn2, T* vecOut);
149 template <typename T> void vExp(const int n, const T* vecIn, T* vecOut);
151 template <typename T> void vInv(const int n, const T* vecIn, T* vecOut);
153 template <typename T> void vAdd(const int n, const T* vecIn, const T* vecIn2, T* vecOut);
155 template <typename T> void vMul(const int n, const T* vecIn, const T* vecIn2, T* vecOut);
157 template <typename T> void vAbs(const int n, const T* vecIn, T* vecOut);
158 
159 // Interfaces to a few LAPACK functions
161 template <typename T> void trtri(char& uplo, char& diag,
162  int& n, T * a, int& lda);
164 template <typename T> void sytrf(char& uplo, int& n, T* a, int& lda, int* ipiv,
165  T* work, int& lwork);
167 template <typename T> void sytri(char& uplo, int& n, T* a, int& lda, int* ipiv,
168  T* work);
170 template <typename T> void lasrt(char& id, const int& n, T *d);
171 template <typename T> void lasrt2(char& id, const int& n, T *d, int* key);
172 
173 
174 
175 /* ******************
176  * Implementations
177  * *****************/
178 
179 
180 // Implementations of the interfaces, BLAS Level 1
182 template <> inline double cblas_nrm2<double>(const int n, const double* X,
183  const int incX) {
184  return cblas_dnrm2(n,X,incX);
185 };
187 template <> inline float cblas_nrm2<float>(const int n, const float* X,
188  const int incX) {
189  return cblas_snrm2(n,X,incX);
190 };
192 template <> inline void cblas_copy<double>(const int n, const double* X,
193  const int incX, double* Y, const int incY) {
194  cblas_dcopy(n,X,incX,Y,incY);
195 };
197 template <> inline void cblas_copy<float>(const int n, const float* X, const int incX,
198  float* Y, const int incY) {
199  cblas_scopy(n,X,incX,Y,incY);
200 };
202 template <> inline void cblas_copy<int>(const int n, const int* X, const int incX,
203  int* Y, const int incY) {
204  for (int i = 0; i<n; ++i)
205  Y[incY*i]=X[incX*i];
206 };
208 template <> inline void cblas_copy<bool>(const int n, const bool* X, const int incX,
209  bool* Y, const int incY) {
210  for (int i = 0; i<n; ++i)
211  Y[incY*i]=X[incX*i];
212 };
213 
215 template <> inline void cblas_axpy<double>(const int n, const double a, const double* X,
216  const int incX, double* Y, const int incY) {
217  cblas_daxpy(n,a,X,incX,Y,incY);
218 };
220 template <> inline void cblas_axpy<float>(const int n, const float a, const float* X,
221  const int incX, float* Y, const int incY) {
222  cblas_saxpy(n,a,X,incX,Y,incY);
223 };
224 
226 template <> inline void cblas_axpy<int>(const int n, const int a, const int* X,
227  const int incX, int* Y, const int incY) {
228  for (int i = 0; i<n; ++i)
229  Y[i] += a*X[i];
230 };
231 
233 template <> inline void cblas_axpy<bool>(const int n, const bool a, const bool* X,
234  const int incX, bool* Y, const int incY) {
235  for (int i = 0; i<n; ++i)
236  Y[i] = a*X[i];
237 };
238 
239 
241 template <> inline void cblas_scal<double>(const int n, const double a, double* X,
242  const int incX) {
243  cblas_dscal(n,a,X,incX);
244 };
246 template <> inline void cblas_scal<float>(const int n, const float a, float* X,
247  const int incX) {
248  cblas_sscal(n,a,X,incX);
249 };
251 template <> inline void cblas_scal<int>(const int n, const int a, int* X,
252  const int incX) {
253  for (int i = 0; i<n; ++i) X[i*incX]*=a;
254 };
256 template <> inline void cblas_scal<bool>(const int n, const bool a, bool* X,
257  const int incX) {
259 };
260 
262 template <> inline double cblas_asum<double>(const int n, const double* X, const int incX) {
263  return cblas_dasum(n,X,incX);
264 };
266 template <> inline float cblas_asum<float>(const int n, const float* X, const int incX) {
267  return cblas_sasum(n,X,incX);
268 };
270 template <> inline double cblas_dot<double>(const int n, const double* X,
271  const int incX, const double* Y,const int incY) {
272  return cblas_ddot(n,X,incX,Y,incY);
273 };
275 template <> inline float cblas_dot<float>(const int n, const float* X,
276  const int incX, const float* Y,const int incY) {
277  return cblas_sdot(n,X,incX,Y,incY);
278 };
279 template <> inline int cblas_dot<int>(const int n, const int* X,
280  const int incX, const int* Y,const int incY) {
281  int total=0;
282  int i,j;
283  j=0;
284  for (i = 0; i<n; ++i) {
285  total+=X[i*incX]*Y[j];
286  j+=incY;
287  }
288  return total;
289 };
291 template <> inline bool cblas_dot<bool>(const int n, const bool* X,
292  const int incX, const bool* Y,const int incY) {
294  return true;
295 };
296 
297 // Implementations of the interfaces, BLAS Level 2
299 template <> inline void cblas_gemv<double>(const CBLAS_ORDER order,
300  const CBLAS_TRANSPOSE TransA, const int M, const int N,
301  const double alpha, const double *A, const int lda,
302  const double *X, const int incX, const double beta,
303  double *Y, const int incY) {
304  cblas_dgemv(order,TransA,M,N,alpha,A,lda,X,incX,beta,Y,incY);
305 };
307 template <> inline void cblas_gemv<float>(const CBLAS_ORDER order,
308  const CBLAS_TRANSPOSE TransA, const int M, const int N,
309  const float alpha, const float *A, const int lda,
310  const float *X, const int incX, const float beta,
311  float *Y, const int incY) {
312  cblas_sgemv(order,TransA,M,N,alpha,A,lda,X,incX,beta,Y,incY);
313 };
315 template <> inline void cblas_gemv<int>(const CBLAS_ORDER order,
316  const CBLAS_TRANSPOSE TransA, const int M, const int N,
317  const int alpha, const int *A, const int lda,
318  const int *X, const int incX, const int beta,
319  int *Y, const int incY) {
321 };
323 template <> inline void cblas_gemv<bool>(const CBLAS_ORDER order,
324  const CBLAS_TRANSPOSE TransA, const int M, const int N,
325  const bool alpha, const bool *A, const int lda,
326  const bool *X, const int incX, const bool beta,
327  bool *Y, const int incY) {
329 };
330 
332 template <> inline void cblas_ger<double>(const CBLAS_ORDER order,
333  const int M, const int N, const double alpha, const double *X, const int incX,
334  const double* Y, const int incY, double *A, const int lda) {
335  cblas_dger(order,M,N,alpha,X,incX,Y,incY,A,lda);
336 };
338 template <> inline void cblas_ger<float>(const CBLAS_ORDER order,
339  const int M, const int N, const float alpha, const float *X, const int incX,
340  const float* Y, const int incY, float *A, const int lda) {
341  cblas_sger(order,M,N,alpha,X,incX,Y,incY,A,lda);
342 };
344 template <> inline void cblas_trmv<double>(const CBLAS_ORDER order, const CBLAS_UPLO Uplo,
345  const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, const int N,
346  const double *A, const int lda, double *X, const int incX) {
347  cblas_dtrmv(order,Uplo,TransA,Diag,N,A,lda,X,incX);
348 };
350 template <> inline void cblas_trmv<float>(const CBLAS_ORDER order, const CBLAS_UPLO Uplo,
351  const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, const int N,
352  const float *A, const int lda, float *X, const int incX) {
353  cblas_strmv(order,Uplo,TransA,Diag,N,A,lda,X,incX);
354 };
356 template <> inline void cblas_syr(const CBLAS_ORDER order,
357  const CBLAS_UPLO Uplo,
358  const int N, const double alpha, const double*X,
359  const int incX, double *A, const int lda) {
360  cblas_dsyr(order,Uplo,N,alpha,X,incX,A,lda);
361 };
363 template <> inline void cblas_syr(const CBLAS_ORDER order,
364  const CBLAS_UPLO Uplo,
365  const int N, const float alpha, const float*X,
366  const int incX, float *A, const int lda) {
367  cblas_ssyr(order,Uplo,N,alpha,X,incX,A,lda);
368 };
370 template <> inline void cblas_symv(const CBLAS_ORDER order,
371  const CBLAS_UPLO Uplo, const int N,
372  const float alpha, const float *A, const int lda, const float *X,
373  const int incX, const float beta,float *Y, const int incY) {
374  cblas_ssymv(order,Uplo,N,alpha,A,lda,X,incX,beta,Y,incY);
375 }
377 template <> inline void cblas_symv(const CBLAS_ORDER order,
378  const CBLAS_UPLO Uplo, const int N,
379  const double alpha, const double *A, const int lda, const double *X,
380  const int incX, const double beta,double *Y, const int incY) {
381  cblas_dsymv(order,Uplo,N,alpha,A,lda,X,incX,beta,Y,incY);
382 }
383 
384 
385 // Implementations of the interfaces, BLAS Level 3
387 template <> inline void cblas_gemm<double>(const CBLAS_ORDER Order,
388  const CBLAS_TRANSPOSE TransA, const CBLAS_TRANSPOSE TransB,
389  const int M, const int N, const int K, const double alpha,
390  const double *A, const int lda, const double *B, const int ldb,
391  const double beta, double *C, const int ldc) {
392  cblas_dgemm(Order,TransA,TransB,M,N,K,alpha,A,lda,B,ldb,beta,C,ldc);
393 };
395 template <> inline void cblas_gemm<float>(const CBLAS_ORDER Order,
396  const CBLAS_TRANSPOSE TransA, const CBLAS_TRANSPOSE TransB,
397  const int M, const int N, const int K, const float alpha,
398  const float *A, const int lda, const float *B, const int ldb,
399  const float beta, float *C, const int ldc) {
400  cblas_sgemm(Order,TransA,TransB,M,N,K,alpha,A,lda,B,ldb,beta,C,ldc);
401 };
402 template <> inline void cblas_gemm<int>(const CBLAS_ORDER Order,
403  const CBLAS_TRANSPOSE TransA, const CBLAS_TRANSPOSE TransB,
404  const int M, const int N, const int K, const int alpha,
405  const int *A, const int lda, const int *B, const int ldb,
406  const int beta, int *C, const int ldc) {
408 };
410 template <> inline void cblas_gemm<bool>(const CBLAS_ORDER Order,
411  const CBLAS_TRANSPOSE TransA, const CBLAS_TRANSPOSE TransB,
412  const int M, const int N, const int K, const bool alpha,
413  const bool *A, const int lda, const bool *B, const int ldb,
414  const bool beta, bool *C, const int ldc) {
416 };
417 
419 template <> inline void cblas_syrk<double>(const CBLAS_ORDER Order,
420  const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE Trans, const int N, const int K,
421  const double alpha, const double *A, const int lda,
422  const double beta, double *C, const int ldc) {
423  cblas_dsyrk(Order,Uplo,Trans,N,K,alpha,A,lda,beta,C,ldc);
424 };
426 template <> inline void cblas_syrk<float>(const CBLAS_ORDER Order,
427  const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE Trans, const int N, const int K,
428  const float alpha, const float *A, const int lda,
429  const float beta, float *C, const int ldc) {
430  cblas_ssyrk(Order,Uplo,Trans,N,K,alpha,A,lda,beta,C,ldc);
431 };
433 template <> inline void cblas_syrk<int>(const CBLAS_ORDER Order,
434  const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE Trans, const int N, const int K,
435  const int alpha, const int *A, const int lda,
436  const int beta, int *C, const int ldc) {
438 };
440 template <> inline void cblas_syrk<bool>(const CBLAS_ORDER Order,
441  const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE Trans, const int N, const int K,
442  const bool alpha, const bool *A, const int lda,
443  const bool beta, bool *C, const int ldc) {
445 };
446 
448 template <> inline void cblas_trmm<double>(const CBLAS_ORDER Order,
449  const CBLAS_SIDE Side, const CBLAS_UPLO Uplo,
450  const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag,
451  const int M, const int N, const double alpha,
452  const double *A, const int lda,double *B, const int ldb) {
453  cblas_dtrmm(Order,Side,Uplo,TransA,Diag,M,N,alpha,A,lda,B,ldb);
454 };
456 template <> inline void cblas_trmm<float>(const CBLAS_ORDER Order,
457  const CBLAS_SIDE Side, const CBLAS_UPLO Uplo,
458  const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag,
459  const int M, const int N, const float alpha,
460  const float *A, const int lda,float *B, const int ldb) {
461  cblas_strmm(Order,Side,Uplo,TransA,Diag,M,N,alpha,A,lda,B,ldb);
462 };
464 template <> inline int cblas_iamax<double>(const int n, const double* X,
465  const int incX) {
466  return cblas_idamax(n,X,incX);
467 };
469 template <> inline int cblas_iamax<float>(const int n, const float* X,
470  const int incX) {
471  return cblas_isamax(n,X,incX);
472 };
473 
474 // Implementations of the interfaces, LAPACK
476 template <> inline void trtri<double>(char& uplo, char& diag,
477  int& n, double * a, int& lda) {
478  dtrtri_(&uplo,&diag,&n,a,&lda,&info);
479 };
481 template <> inline void trtri<float>(char& uplo, char& diag,
482  int& n, float* a, int& lda) {
483  strtri_(&uplo,&diag,&n,a,&lda,&info);
484 };
486 template <> void inline sytrf<double>(char& uplo, int& n, double* a,
487  int& lda, int* ipiv, double* work, int& lwork) {
488  dsytrf_(&uplo,&n,a,&lda,ipiv,work,&lwork,&info);
489 };
491 template <> inline void sytrf<float>(char& uplo, int& n, float* a,
492  int& lda, int* ipiv, float* work, int& lwork) {
493  ssytrf_(&uplo,&n,a,&lda,ipiv,work,&lwork,&info);
494 };
496 template <> inline void sytri<double>(char& uplo, int& n, double* a,
497  int& lda, int* ipiv, double* work) {
498  dsytri_(&uplo,&n,a,&lda,ipiv,work,&info);
499 };
501 template <> inline void sytri<float>(char& uplo, int& n, float* a,
502  int& lda, int* ipiv, float* work) {
503  ssytri_(&uplo,&n,a,&lda,ipiv,work,&info);
504 };
506 template <> inline void lasrt(char& id, const int& n, double *d) {
507  dlasrt_(&id,const_cast<int*>(&n),d,&info);
508 };
510 template <> inline void lasrt(char& id, const int& n, float *d) {
511  slasrt_(&id,const_cast<int*>(&n),d,&info);
512 };
513 template <> inline void lasrt2(char& id, const int& n, double *d,int* key) {
514  dlasrt2_(&id,const_cast<int*>(&n),d,key,&info);
515 };
517 template <> inline void lasrt2(char& id, const int& n, float *d, int* key) {
518  slasrt2_(&id,const_cast<int*>(&n),d,key,&info);
519 };
520 
521 
523 #ifdef HAVE_MKL
524 template <> inline void vSqr<double>(const int n, const double* vecIn,
526  double* vecOut) {
527  vdSqr(n,vecIn,vecOut);
528 };
530 template <> inline void vSqr<float>(const int n, const float* vecIn,
531  float* vecOut) {
532  vsSqr(n,vecIn,vecOut);
533 };
534 template <> inline void vSqrt<double>(const int n, const double* vecIn,
535  double* vecOut) {
536  vdSqrt(n,vecIn,vecOut);
537 };
539 template <> inline void vSqrt<float>(const int n, const float* vecIn,
540  float* vecOut) {
541  vsSqrt(n,vecIn,vecOut);
542 };
543 template <> inline void vInvSqrt<double>(const int n, const double* vecIn,
544  double* vecOut) {
545  vdInvSqrt(n,vecIn,vecOut);
546 };
548 template <> inline void vInvSqrt<float>(const int n, const float* vecIn,
549  float* vecOut) {
550  vsInvSqrt(n,vecIn,vecOut);
551 };
552 
554 template <> inline void vSub<double>(const int n, const double* vecIn,
555  const double* vecIn2, double* vecOut) {
556  vdSub(n,vecIn,vecIn2,vecOut);
557 };
559 template <> inline void vSub<float>(const int n, const float* vecIn,
560  const float* vecIn2, float* vecOut) {
561  vsSub(n,vecIn,vecIn2,vecOut);
562 };
564 template <> inline void vDiv<double>(const int n, const double* vecIn,
565  const double* vecIn2, double* vecOut) {
566  vdDiv(n,vecIn,vecIn2,vecOut);
567 };
569 template <> inline void vDiv<float>(const int n, const float* vecIn,
570  const float* vecIn2, float* vecOut) {
571  vsDiv(n,vecIn,vecIn2,vecOut);
572 };
574 template <> inline void vExp<double>(const int n, const double* vecIn,
575  double* vecOut) {
576  vdExp(n,vecIn,vecOut);
577 };
579 template <> inline void vExp<float>(const int n, const float* vecIn,
580  float* vecOut) {
581  vsExp(n,vecIn,vecOut);
582 };
584 template <> inline void vInv<double>(const int n, const double* vecIn,
585  double* vecOut) {
586  vdInv(n,vecIn,vecOut);
587 };
589 template <> inline void vInv<float>(const int n, const float* vecIn,
590  float* vecOut) {
591  vsInv(n,vecIn,vecOut);
592 };
594 template <> inline void vAdd<double>(const int n, const double* vecIn,
595  const double* vecIn2, double* vecOut) {
596  vdAdd(n,vecIn,vecIn2,vecOut);
597 };
599 template <> inline void vAdd<float>(const int n, const float* vecIn,
600  const float* vecIn2, float* vecOut) {
601  vsAdd(n,vecIn,vecIn2,vecOut);
602 };
604 template <> inline void vMul<double>(const int n, const double* vecIn,
605  const double* vecIn2, double* vecOut) {
606  vdMul(n,vecIn,vecIn2,vecOut);
607 };
609 template <> inline void vMul<float>(const int n, const float* vecIn,
610  const float* vecIn2, float* vecOut) {
611  vsMul(n,vecIn,vecIn2,vecOut);
612 };
613 
615 template <> inline void vAbs(const int n, const double* vecIn,
616  double* vecOut) {
617  vdAbs(n,vecIn,vecOut);
618 };
620 template <> inline void vAbs(const int n, const float* vecIn,
621  float* vecOut) {
622  vsAbs(n,vecIn,vecOut);
623 };
624 
625 
628 template <> inline int cblas_iamin<double>(const int n, const double* X,
629  const int incX) {
630  return (int) cblas_idamin(n,X,incX);
631 };
634 template <> inline int cblas_iamin<float>(const int n, const float* X,
635  const int incX) {
636  return (int) cblas_isamin(n,X,incX);
637 };
639 #else
640 template <typename T> inline void vSqr(const int n, const T* vecIn, T* vecOut) {
642  for (int i = 0; i<n; ++i) vecOut[i]=vecIn[i]*vecIn[i];
643 };
644 template <typename T> inline void vSqrt(const int n, const T* vecIn, T* vecOut) {
645  for (int i = 0; i<n; ++i) vecOut[i]=spams::sqr<T>(vecIn[i]);
646 };
647 template <typename T> inline void vInvSqrt(const int n, const T* vecIn, T* vecOut) {
648  for (int i = 0; i<n; ++i) vecOut[i]=T(1.0)/spams::sqr<T>(vecIn[i]);
649 };
650 
652 template <typename T> inline void vSub(const int n, const T* vecIn1,
653  const T* vecIn2, T* vecOut) {
654  for (int i = 0; i<n; ++i) vecOut[i]=vecIn1[i]-vecIn2[i];
655 };
657 template <typename T> inline void vInv(const int n, const T* vecIn, T* vecOut) {
658  for (int i = 0; i<n; ++i) vecOut[i]=1.0/vecIn[i];
659 };
661 template <typename T> inline void vExp(const int n, const T* vecIn, T* vecOut) {
662  for (int i = 0; i<n; ++i) vecOut[i]=exp(vecIn[i]);
663 };
665 template <typename T> inline void vAdd(const int n, const T* vecIn1,
666  const T* vecIn2, T* vecOut) {
667  for (int i = 0; i<n; ++i) vecOut[i]=vecIn1[i]+vecIn2[i];
668 };
670 template <typename T> inline void vMul(const int n, const T* vecIn1,
671  const T* vecIn2, T* vecOut) {
672  for (int i = 0; i<n; ++i) vecOut[i]=vecIn1[i]*vecIn2[i];
673 };
675 template <typename T> inline void vDiv(const int n, const T* vecIn1,
676  const T* vecIn2, T* vecOut) {
677  for (int i = 0; i<n; ++i) vecOut[i]=vecIn1[i]/vecIn2[i];
678 };
680 template <typename T> inline void vAbs(const int n, const T* vecIn,
681  T* vecOut) {
682  for (int i = 0; i<n; ++i) vecOut[i]=spams::abs<T>(vecIn[i]);
683 };
684 
686 template <typename T> inline int cblas_iamin(int n, T* X, int incX) {
687  int imin=0;
688  double min=fabs(X[0]);
689  for (int j = 1; j<n; j+=incX) {
690  double cur = fabs(X[j]);
691  if (cur < min) {
692  imin=j;
693  min = cur;
694  }
695  }
696  return imin;
697 }
698 #endif
699 
700 #endif
void cblas_trmm(const CBLAS_ORDER Order, const CBLAS_SIDE Side, const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, const int M, const int N, const T alpha, const T *A, const int lda, T *B, const int ldb)
interface to cblas_*trmm
void cblas_strmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const int N, const float *A, const int lda, float *X, const int incX)
void cblas_trmv< float >(const CBLAS_ORDER order, const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, const int N, const float *A, const int lda, float *X, const int incX)
Implementation of the interface for cblas_strmv.
CBLAS_TRANSPOSE
Definition: utl_cblas.h:6
void cblas_gemv< int >(const CBLAS_ORDER order, const CBLAS_TRANSPOSE TransA, const int M, const int N, const int alpha, const int *A, const int lda, const int *X, const int incX, const int beta, int *Y, const int incY)
Implementation of the interface for cblas_sgemv.
void cblas_syrk< float >(const CBLAS_ORDER Order, const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE Trans, const int N, const int K, const float alpha, const float *A, const int lda, const float beta, float *C, const int ldc)
Implementation of the interface for cblas_ssyrk.
void vSqr(const int n, const T *vecIn, T *vecOut)
interface to v*Sqr
double cblas_dot< double >(const int n, const double *X, const int incX, const double *Y, const int incY)
Implementation of the interface for cblas_ddot.
vcl_size_t cblas_idamin(const int n, const double *X, const int incX)
external functions
void cblas_dscal(const int N, const double alpha, double *X, const int incX)
void cblas_sgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const float alpha, const float *A, const int lda, const float *B, const int ldb, const float beta, float *C, const int ldc)
void cblas_ger< float >(const CBLAS_ORDER order, const int M, const int N, const float alpha, const float *X, const int incX, const float *Y, const int incY, float *A, const int lda)
Implementation of the interface for cblas_sger.
void cblas_dtrmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const int N, const double *A, const int lda, double *X, const int incX)
void cblas_strmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const int M, const int N, const float alpha, const float *A, const int lda, float *B, const int ldb)
void vSqrt(const int n, const T *vecIn, T *vecOut)
interface to v*Sqr
void cblas_scal(const int n, const T a, T *X, const int incX)
interface to cblas_*scal
void vSub(const int n, const T *vecIn, const T *vecIn2, T *vecOut)
interface to v*Sub
void cblas_ssyr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N, const float alpha, const float *X, const int incX, float *A, const int lda)
T cblas_dot(const int n, const T *X, const int incX, const T *Y, const int incY)
interface to cblas_*adot
void cblas_trmv(const CBLAS_ORDER order, const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, const int N, const T *A, const int lda, T *X, const int incX)
interface to cblas_*trmv
void cblas_axpy< bool >(const int n, const bool a, const bool *X, const int incX, bool *Y, const int incY)
Implementation of the interface for cblas_saxpy.
void lasrt2(char &id, const int &n, T *d, int *key)
void sytri(char &uplo, int &n, T *a, int &lda, int *ipiv, T *work)
interface to *sytri
void sytrf< float >(char &uplo, int &n, float *a, int &lda, int *ipiv, float *work, int &lwork)
Implemenation of the interface for ssytrf.
void cblas_gemm(const CBLAS_ORDER Order, const CBLAS_TRANSPOSE TransA, const CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const T alpha, const T *A, const int lda, const T *B, const int ldb, const T beta, T *C, const int ldc)
interface to cblas_*gemm
void vExp(const int n, const T *vecIn, T *vecOut)
interface to v*Exp
void cblas_axpy< float >(const int n, const float a, const float *X, const int incX, float *Y, const int incY)
Implementation of the interface for cblas_saxpy.
void cblas_copy(const int n, const T *X, const int incX, T *Y, const int incY)
interface to cblas_*copy
void cblas_gemm< int >(const CBLAS_ORDER Order, const CBLAS_TRANSPOSE TransA, const CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const int alpha, const int *A, const int lda, const int *B, const int ldb, const int beta, int *C, const int ldc)
float cblas_sasum(const int N, const float *X, const int incX)
double cblas_ddot(const int N, const double *X, const int incX, const double *Y, const int incY)
void ssytrf_(char *uplo, int *n, float *a, int *lda, int *ipiv, float *work, int *lwork, int *info)
void cblas_axpy< int >(const int n, const int a, const int *X, const int incX, int *Y, const int incY)
Implementation of the interface for cblas_saxpy.
int cblas_iamin(const int n, const T *X, const int incX)
interface to cblas_i*amin
Definition: utlBlas.h:170
void cblas_trmm< float >(const CBLAS_ORDER Order, const CBLAS_SIDE Side, const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, const int M, const int N, const float alpha, const float *A, const int lda, float *B, const int ldb)
Implementation of the interface for cblas_strmm.
void ssytri_(char *uplo, int *n, float *a, int *lda, int *ipiv, float *work, int *info)
void dlasrt2_(char *id, const int *n, double *d, int *key, int *info)
float cblas_nrm2< float >(const int n, const float *X, const int incX)
Implementation of the interface for cblas_snrm2.
void cblas_axpy< double >(const int n, const double a, const double *X, const int incX, double *Y, const int incY)
Implementation of the interface for cblas_daxpy.
CBLAS_ORDER
Definition: utl_cblas.h:5
void cblas_ssymv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N, const float alpha, const float *A, const int lda, const float *X, const int incX, const float beta, float *Y, const int incY)
void cblas_gemv< float >(const CBLAS_ORDER order, const CBLAS_TRANSPOSE TransA, const int M, const int N, const float alpha, const float *A, const int lda, const float *X, const int incX, const float beta, float *Y, const int incY)
Implementation of the interface for cblas_sgemv.
void cblas_gemm< double >(const CBLAS_ORDER Order, const CBLAS_TRANSPOSE TransA, const CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const double alpha, const double *A, const int lda, const double *B, const int ldb, const double beta, double *C, const int ldc)
Implementation of the interface for cblas_dgemm.
void cblas_scal< bool >(const int n, const bool a, bool *X, const int incX)
Implementation of the interface for cblas_sscal.
void cblas_dsymv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N, const double alpha, const double *A, const int lda, const double *X, const int incX, const double beta, double *Y, const int incY)
CBLAS_SIDE
Definition: utl_cblas.h:10
void trtri(char &uplo, char &diag, int &n, T *a, int &lda)
interface to *trtri
void cblas_scopy(const int N, const float *X, const int incX, float *Y, const int incY)
void slasrt2_(char *id, const int *n, float *d, int *key, int *info)
void sytri< float >(char &uplo, int &n, float *a, int &lda, int *ipiv, float *work)
Implemenation of the interface for ssytri.
void cblas_copy< bool >(const int n, const bool *X, const int incX, bool *Y, const int incY)
Implementation of the interface for cblas_scopy.
void cblas_saxpy(const int N, const float alpha, const float *X, const int incX, float *Y, const int incY)
float cblas_asum< float >(const int n, const float *X, const int incX)
Implementation of the interface for cblas_sasum.
void sytri< double >(char &uplo, int &n, double *a, int &lda, int *ipiv, double *work)
Implemenation of the interface for dsytri.
int cblas_iamax< double >(const int n, const double *X, const int incX)
Implementation of the interface for cblas_idamax.
void cblas_ger(const CBLAS_ORDER order, const int M, const int N, const T alpha, const T *X, const int incX, const T *Y, const int incY, T *A, const int lda)
interface to cblas_*ger
void cblas_copy< double >(const int n, const double *X, const int incX, double *Y, const int incY)
Implementation of the interface for cblas_dcopy.
int cblas_dot< int >(const int n, const int *X, const int incX, const int *Y, const int incY)
const T & min(const T &a, const T &b)
Return the minimum between a and b.
Definition: utlCore.h:257
void cblas_syrk< int >(const CBLAS_ORDER Order, const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE Trans, const int N, const int K, const int alpha, const int *A, const int lda, const int beta, int *C, const int ldc)
Implementation of the interface for cblas_ssyrk.
float cblas_snrm2(const int N, const float *X, const int incX)
double cblas_dnrm2(const int N, const double *X, const int incX)
int cblas_idamax(const int N, const double *X, const int incX)
void cblas_gemv< bool >(const CBLAS_ORDER order, const CBLAS_TRANSPOSE TransA, const int M, const int N, const bool alpha, const bool *A, const int lda, const bool *X, const int incX, const bool beta, bool *Y, const int incY)
Implementation of the interface for cblas_sgemv.
static char nonUnit
Definition: cblas_template.h:8
void cblas_ssyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const float alpha, const float *A, const int lda, const float beta, float *C, const int ldc)
void cblas_dgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const double alpha, const double *A, const int lda, const double *B, const int ldb, const double beta, double *C, const int ldc)
void vDiv(const int n, const T *vecIn, const T *vecIn2, T *vecOut)
interface to v*Div
float cblas_sdot(const int N, const float *X, const int incX, const float *Y, const int incY)
void cblas_trmv< double >(const CBLAS_ORDER order, const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, const int N, const double *A, const int lda, double *X, const int incX)
Implementation of the interface for cblas_dtrmv.
int cblas_iamax< float >(const int n, const float *X, const int incX)
Implementation of the interface for cblas_isamax.
void vAdd(const int n, const T *vecIn, const T *vecIn2, T *vecOut)
interface to v*Add
void dsytri_(char *uplo, int *n, double *a, int *lda, int *ipiv, double *work, int *info)
void dsytrf_(char *uplo, int *n, double *a, int *lda, int *ipiv, double *work, int *lwork, int *info)
void cblas_symv(const CBLAS_ORDER order, const CBLAS_UPLO Uplo, const int N, const T alpha, const T *A, const int lda, const T *X, const int incX, const T beta, T *Y, const int incY)
interface to cblas_*symv
void cblas_dger(const enum CBLAS_ORDER Order, const int M, const int N, const double alpha, const double *X, const int incX, const double *Y, const int incY, double *A, const int lda)
void vInv(const int n, const T *vecIn, T *vecOut)
interface to v*Inv
void cblas_copy< int >(const int n, const int *X, const int incX, int *Y, const int incY)
Implementation of the interface for cblas_scopy.
void vAbs(const int n, const T *vecIn, T *vecOut)
interface to v*Abs
void cblas_dsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const double alpha, const double *A, const int lda, const double beta, double *C, const int ldc)
void cblas_scal< int >(const int n, const int a, int *X, const int incX)
Implementation of the interface for cblas_sscal.
static int info
void cblas_ger< double >(const CBLAS_ORDER order, const int M, const int N, const double alpha, const double *X, const int incX, const double *Y, const int incY, double *A, const int lda)
Implementation of the interface for cblas_dger.
void sytrf< double >(char &uplo, int &n, double *a, int &lda, int *ipiv, double *work, int &lwork)
Implemenation of the interface for dsytrf.
static char incr
void cblas_scal< float >(const int n, const float a, float *X, const int incX)
Implementation of the interface for cblas_sscal.
void cblas_dtrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, const int M, const int N, const double alpha, const double *A, const int lda, double *B, const int ldb)
void cblas_gemv(const CBLAS_ORDER order, const CBLAS_TRANSPOSE TransA, const int M, const int N, const T alpha, const T *A, const int lda, const T *X, const int incX, const T beta, T *Y, const int incY)
interface to cblas_*gemv
void cblas_syrk(const CBLAS_ORDER Order, const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE Trans, const int N, const int K, const T alpha, const T *A, const int lda, const T beta, T *C, const int ldc)
interface to cblas_*syrk
CBLAS_UPLO
Definition: utl_cblas.h:8
void vInvSqrt(const int n, const T *vecIn, T *vecOut)
interface to v*Sqr
void cblas_copy< float >(const int n, const float *X, const int incX, float *Y, const int incY)
Implementation of the interface for cblas_scopy.
void slasrt_(char *id, const int *n, float *d, int *info)
void trtri< float >(char &uplo, char &diag, int &n, float *a, int &lda)
Implemenation of the interface for strtri.
bool cblas_dot< bool >(const int n, const bool *X, const int incX, const bool *Y, const int incY)
Implementation of the interface for cblas_sdot.
void cblas_sgemv(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const float alpha, const float *A, const int lda, const float *X, const int incX, const float beta, float *Y, const int incY)
void cblas_axpy(const int n, const T a, const T *X, const int incX, T *Y, const int incY)
interface to cblas_*axpy
CBLAS_DIAG
Definition: utl_cblas.h:9
int cblas_isamax(const int N, const float *X, const int incX)
void dlasrt_(char *id, const int *n, double *d, int *info)
void cblas_trmm< double >(const CBLAS_ORDER Order, const CBLAS_SIDE Side, const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE TransA, const CBLAS_DIAG Diag, const int M, const int N, const double alpha, const double *A, const int lda, double *B, const int ldb)
Implementation of the interface for cblas_dtrmm.
double cblas_dasum(const int N, const double *X, const int incX)
static char upper
Definition: cblas_template.h:9
void dtrtri_(char *uplo, char *diag, int *n, double *a, int *lda, int *info)
void cblas_syr(const CBLAS_ORDER order, const CBLAS_UPLO Uplo, const int N, const T alpha, const T *X, const int incX, T *A, const int lda)
interface to cblas_*syr
void cblas_gemv< double >(const CBLAS_ORDER order, const CBLAS_TRANSPOSE TransA, const int M, const int N, const double alpha, const double *A, const int lda, const double *X, const int incX, const double beta, double *Y, const int incY)
Implementation of the interface for cblas_dgemv.
void lasrt(char &id, const int &n, T *d)
interaface to *lasrt
int cblas_iamax(const int n, const T *X, const int incX)
interface to cblas_i*amax
Definition: utlBlas.h:183
void cblas_gemm< float >(const CBLAS_ORDER Order, const CBLAS_TRANSPOSE TransA, const CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const float alpha, const float *A, const int lda, const float *B, const int ldb, const float beta, float *C, const int ldc)
Implementation of the interface for cblas_sgemm.
void sytrf(char &uplo, int &n, T *a, int &lda, int *ipiv, T *work, int &lwork)
interface to *sytrf
void strtri_(char *uplo, char *diag, int *n, float *a, int *lda, int *info)
void cblas_dcopy(const int N, const double *X, const int incX, double *Y, const int incY)
void cblas_syrk< bool >(const CBLAS_ORDER Order, const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE Trans, const int N, const int K, const bool alpha, const bool *A, const int lda, const bool beta, bool *C, const int ldc)
Implementation of the interface for cblas_ssyrk.
void cblas_dgemv(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const double alpha, const double *A, const int lda, const double *X, const int incX, const double beta, double *Y, const int incY)
void cblas_sger(const enum CBLAS_ORDER Order, const int M, const int N, const float alpha, const float *X, const int incX, const float *Y, const int incY, float *A, const int lda)
static char low
a few static variables for lapack
Definition: cblas_template.h:7
void cblas_scal< double >(const int n, const double a, double *X, const int incX)
Implementation of the interface for cblas_dscal.
void cblas_sscal(const int N, const float alpha, float *X, const int incX)
vcl_size_t cblas_isamin(const int n, const float *X, const int incX)
void trtri< double >(char &uplo, char &diag, int &n, double *a, int &lda)
Implemenation of the interface for dtrtri.
double cblas_asum< double >(const int n, const double *X, const int incX)
Implementation of the interface for cblas_dasum.
void cblas_syrk< double >(const CBLAS_ORDER Order, const CBLAS_UPLO Uplo, const CBLAS_TRANSPOSE Trans, const int N, const int K, const double alpha, const double *A, const int lda, const double beta, double *C, const int ldc)
Implementation of the interface for cblas_dsyrk.
T cblas_nrm2(const int n, const T *X, const int incX)
interface to cblas_*nrm2
void cblas_daxpy(const int N, const double alpha, const double *X, const int incX, double *Y, const int incY)
float cblas_dot< float >(const int n, const float *X, const int incX, const float *Y, const int incY)
Implementation of the interface for cblas_sdot.
void vMul(const int n, const T *vecIn, const T *vecIn2, T *vecOut)
interface to v*Mul
static char decr
void cblas_gemm< bool >(const CBLAS_ORDER Order, const CBLAS_TRANSPOSE TransA, const CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const bool alpha, const bool *A, const int lda, const bool *B, const int ldb, const bool beta, bool *C, const int ldc)
Implementation of the interface for cblas_sgemm.
double cblas_nrm2< double >(const int n, const double *X, const int incX)
Implementation of the interface for cblas_dnrm2.
T cblas_asum(const int n, const T *X, const int incX)
interface to cblas_*asum
void cblas_dsyr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N, const double alpha, const double *X, const int incX, double *A, const int lda)