blas_interface_impl.hh
Go to the documentation of this file.
1 
2 #define BLAS_FUNC(NAME) CAT(CAT(SCALAR_PREFIX,NAME),_)
3 
4 template<> class blas_interface<SCALAR> : public c_interface_base<SCALAR>
5 {
6 
7 public :
8 
9  static SCALAR fone;
10  static SCALAR fzero;
11 
12  static inline std::string name()
13  {
14  return MAKE_STRING(CBLASNAME);
15  }
16 
17  static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
18  BLAS_FUNC(gemv)(&notrans,&N,&N,&fone,A,&N,B,&intone,&fzero,X,&intone);
19  }
20 
21  static inline void symv(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
22  BLAS_FUNC(symv)(&lower, &N,&fone,A,&N,B,&intone,&fzero,X,&intone);
23  }
24 
25  static inline void syr2(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
26  BLAS_FUNC(syr2)(&lower,&N,&fone,B,&intone,X,&intone,A,&N);
27  }
28 
29  static inline void ger(gene_matrix & A, gene_vector & X, gene_vector & Y, int N){
30  BLAS_FUNC(ger)(&N,&N,&fone,X,&intone,Y,&intone,A,&N);
31  }
32 
33  static inline void rot(gene_vector & A, gene_vector & B, SCALAR c, SCALAR s, int N){
34  BLAS_FUNC(rot)(&N,A,&intone,B,&intone,&c,&s);
35  }
36 
37  static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
38  BLAS_FUNC(gemv)(&trans,&N,&N,&fone,A,&N,B,&intone,&fzero,X,&intone);
39  }
40 
41  static inline void matrix_matrix_product(gene_matrix & A, gene_matrix & B, gene_matrix & X, int N){
42  BLAS_FUNC(gemm)(&notrans,&notrans,&N,&N,&N,&fone,A,&N,B,&N,&fzero,X,&N);
43  }
44 
46  BLAS_FUNC(gemm)(&notrans,&notrans,&N,&N,&N,&fone,A,&N,B,&N,&fzero,X,&N);
47  }
48 
49  static inline void ata_product(gene_matrix & A, gene_matrix & X, int N){
50  BLAS_FUNC(syrk)(&lower,&trans,&N,&N,&fone,A,&N,&fzero,X,&N);
51  }
52 
53  static inline void aat_product(gene_matrix & A, gene_matrix & X, int N){
54  BLAS_FUNC(syrk)(&lower,&notrans,&N,&N,&fone,A,&N,&fzero,X,&N);
55  }
56 
57  static inline void axpy(SCALAR coef, const gene_vector & X, gene_vector & Y, int N){
58  BLAS_FUNC(axpy)(&N,&coef,X,&intone,Y,&intone);
59  }
60 
61  static inline void axpby(SCALAR a, const gene_vector & X, SCALAR b, gene_vector & Y, int N){
62  BLAS_FUNC(scal)(&N,&b,Y,&intone);
63  BLAS_FUNC(axpy)(&N,&a,X,&intone,Y,&intone);
64  }
65 
66  static inline void cholesky(const gene_matrix & X, gene_matrix & C, int N){
67  int N2 = N*N;
68  BLAS_FUNC(copy)(&N2, X, &intone, C, &intone);
69  char uplo = 'L';
70  int info = 0;
71  BLAS_FUNC(potrf)(&uplo, &N, C, &N, &info);
72  if(info!=0) std::cerr << "potrf_ error " << info << "\n";
73  }
74 
75  static inline void partial_lu_decomp(const gene_matrix & X, gene_matrix & C, int N){
76  int N2 = N*N;
77  BLAS_FUNC(copy)(&N2, X, &intone, C, &intone);
78  int info = 0;
79  int * ipiv = (int*)alloca(sizeof(int)*N);
80  BLAS_FUNC(getrf)(&N, &N, C, &N, ipiv, &info);
81  if(info!=0) std::cerr << "getrf_ error " << info << "\n";
82  }
83 
84  static inline void trisolve_lower(const gene_matrix & L, const gene_vector& B, gene_vector & X, int N){
85  BLAS_FUNC(copy)(&N, B, &intone, X, &intone);
86  BLAS_FUNC(trsv)(&lower, &notrans, &nonunit, &N, L, &N, X, &intone);
87  }
88 
89  static inline void trisolve_lower_matrix(const gene_matrix & L, const gene_matrix& B, gene_matrix & X, int N){
90  BLAS_FUNC(copy)(&N, B, &intone, X, &intone);
91  BLAS_FUNC(trsm)(&right, &lower, &notrans, &nonunit, &N, &N, &fone, L, &N, X, &N);
92  }
93 
94  static inline void trmm(gene_matrix & A, gene_matrix & B, gene_matrix & /*X*/, int N){
95  BLAS_FUNC(trmm)(&left, &lower, &notrans,&nonunit, &N,&N,&fone,A,&N,B,&N);
96  }
97 
98  #ifdef HAS_LAPACK
99 
100  static inline void lu_decomp(const gene_matrix & X, gene_matrix & C, int N){
101  int N2 = N*N;
102  BLAS_FUNC(copy)(&N2, X, &intone, C, &intone);
103  int info = 0;
104  int * ipiv = (int*)alloca(sizeof(int)*N);
105  int * jpiv = (int*)alloca(sizeof(int)*N);
106  BLAS_FUNC(getc2)(&N, C, &N, ipiv, jpiv, &info);
107  }
108 
109 
110 
111  static inline void hessenberg(const gene_matrix & X, gene_matrix & C, int N){
112  {
113  int N2 = N*N;
114  int inc = 1;
115  BLAS_FUNC(copy)(&N2, X, &inc, C, &inc);
116  }
117  int info = 0;
118  int ilo = 1;
119  int ihi = N;
120  int bsize = 64;
121  int worksize = N*bsize;
122  SCALAR* d = new SCALAR[N+worksize];
123  BLAS_FUNC(gehrd)(&N, &ilo, &ihi, C, &N, d, d+N, &worksize, &info);
124  delete[] d;
125  }
126 
127  static inline void tridiagonalization(const gene_matrix & X, gene_matrix & C, int N){
128  {
129  int N2 = N*N;
130  int inc = 1;
131  BLAS_FUNC(copy)(&N2, X, &inc, C, &inc);
132  }
133  char uplo = 'U';
134  int info = 0;
135  int bsize = 64;
136  int worksize = N*bsize;
137  SCALAR* d = new SCALAR[3*N+worksize];
138  BLAS_FUNC(sytrd)(&uplo, &N, C, &N, d, d+N, d+2*N, d+3*N, &worksize, &info);
139  delete[] d;
140  }
141 
142  #endif // HAS_LAPACK
143 
144 };
145 
BLAS_FUNC
#define BLAS_FUNC(NAME)
Definition: blas_interface_impl.hh:2
gemv
EIGEN_DONT_INLINE void gemv(const Mat &A, const Vec &B, Vec &C)
Definition: gemv.cpp:4
hessenberg
void hessenberg(int size=Size)
Definition: hessenberg.cpp:14
s
RealScalar s
Definition: level1_cplx_impl.h:126
blas_interface< SCALAR >::transposed_matrix_matrix_product
static void transposed_matrix_matrix_product(gene_matrix &A, gene_matrix &B, gene_matrix &X, int N)
Definition: blas_interface_impl.hh:45
d
static const double d[K][N]
Definition: igam.h:11
blas_interface< SCALAR >::fone
static SCALAR fone
Definition: blas_interface_impl.hh:9
blas_interface< SCALAR >::matrix_vector_product
static void matrix_vector_product(gene_matrix &A, gene_vector &B, gene_vector &X, int N)
Definition: blas_interface_impl.hh:17
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
b
Scalar * b
Definition: benchVecAdd.cpp:17
gtsam::Y
GaussianFactorGraphValuePair Y
Definition: HybridGaussianProductFactor.cpp:29
blas_interface< SCALAR >::ger
static void ger(gene_matrix &A, gene_vector &X, gene_vector &Y, int N)
Definition: blas_interface_impl.hh:29
blas_interface< SCALAR >::axpby
static void axpby(SCALAR a, const gene_vector &X, SCALAR b, gene_vector &Y, int N)
Definition: blas_interface_impl.hh:61
trsm
int EIGEN_BLAS_FUNC() trsm(const char *side, const char *uplo, const char *opa, const char *diag, const int *m, const int *n, const RealScalar *palpha, const RealScalar *pa, const int *lda, RealScalar *pb, const int *ldb)
Definition: level3_impl.h:78
c_interface_base< SCALAR >::gene_vector
SCALAR * gene_vector
Definition: c_interface_base.h:18
trans
static char trans
Definition: blas_interface.hh:58
B
Definition: test_numpy_dtypes.cpp:299
E1::B
@ B
lower
static char lower
Definition: blas_interface.hh:60
ger
int EIGEN_BLAS_FUNC() ger(int *m, int *n, Scalar *palpha, Scalar *px, int *incx, Scalar *py, int *incy, Scalar *pa, int *lda)
Definition: level2_real_impl.h:278
blas_interface< SCALAR >::rot
static void rot(gene_vector &A, gene_vector &B, SCALAR c, SCALAR s, int N)
Definition: blas_interface_impl.hh:33
X
#define X
Definition: icosphere.cpp:20
c_interface_base
Definition: c_interface_base.h:8
blas_interface< SCALAR >::axpy
static void axpy(SCALAR coef, const gene_vector &X, gene_vector &Y, int N)
Definition: blas_interface_impl.hh:57
blas_interface< SCALAR >::trisolve_lower
static void trisolve_lower(const gene_matrix &L, const gene_vector &B, gene_vector &X, int N)
Definition: blas_interface_impl.hh:84
intone
static int intone
Definition: blas_interface.hh:63
scal
int EIGEN_BLAS_FUNC() scal(int *n, RealScalar *palpha, RealScalar *px, int *incx)
Definition: level1_impl.h:117
rot
int EIGEN_BLAS_FUNC() rot(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pc, RealScalar *ps)
Definition: level1_real_impl.h:79
symv
int EIGEN_BLAS_FUNC() symv(const char *uplo, const int *n, const RealScalar *palpha, const RealScalar *pa, const int *lda, const RealScalar *px, const int *incx, const RealScalar *pbeta, RealScalar *py, const int *incy)
Definition: level2_real_impl.h:13
blas_interface< SCALAR >::syr2
static void syr2(gene_matrix &A, gene_vector &B, gene_vector &X, int N)
Definition: blas_interface_impl.hh:25
blas_interface< SCALAR >::ata_product
static void ata_product(gene_matrix &A, gene_matrix &X, int N)
Definition: blas_interface_impl.hh:49
blas_interface< SCALAR >::matrix_matrix_product
static void matrix_matrix_product(gene_matrix &A, gene_matrix &B, gene_matrix &X, int N)
Definition: blas_interface_impl.hh:41
blas_interface< SCALAR >::fzero
static SCALAR fzero
Definition: blas_interface_impl.hh:10
trmm
int EIGEN_BLAS_FUNC() trmm(const char *side, const char *uplo, const char *opa, const char *diag, const int *m, const int *n, const RealScalar *palpha, const RealScalar *pa, const int *lda, RealScalar *pb, const int *ldb)
Definition: level3_impl.h:183
A
Definition: test_numpy_dtypes.cpp:298
left
static char left
Definition: blas_interface.hh:62
return_value_policy::copy
@ copy
axpy
int EIGEN_BLAS_FUNC() axpy(const int *n, const RealScalar *palpha, const RealScalar *px, const int *incx, RealScalar *py, const int *incy)
Definition: level1_impl.h:12
syrk
int EIGEN_BLAS_FUNC() syrk(const char *uplo, const char *op, const int *n, const int *k, const RealScalar *palpha, const RealScalar *pa, const int *lda, const RealScalar *pbeta, RealScalar *pc, const int *ldc)
Definition: level3_impl.h:357
info
else if n * info
Definition: 3rdparty/Eigen/lapack/cholesky.cpp:18
L
MatrixXd L
Definition: LLT_example.cpp:6
gemm
EIGEN_DONT_INLINE void gemm(const A &a, const B &b, C &c)
Definition: bench_gemm.cpp:162
E1::A
@ A
notrans
static char notrans
Definition: blas_interface.hh:57
blas_interface< SCALAR >::cholesky
static void cholesky(const gene_matrix &X, gene_matrix &C, int N)
Definition: blas_interface_impl.hh:66
blas_interface< SCALAR >::atv_product
static void atv_product(gene_matrix &A, gene_vector &B, gene_vector &X, int N)
Definition: blas_interface_impl.hh:37
right
static char right
Definition: blas_interface.hh:61
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
SCALAR
#define SCALAR
Definition: bench_gemm.cpp:23
C
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:50
syr2
int EIGEN_BLAS_FUNC() syr2(const char *uplo, const int *n, const RealScalar *palpha, const RealScalar *px, const int *incx, const RealScalar *py, const int *incy, RealScalar *pc, const int *ldc)
Definition: level2_real_impl.h:105
c_interface_base< SCALAR >::gene_matrix
SCALAR * gene_matrix
Definition: c_interface_base.h:17
blas_interface
Definition: blas_interface.hh:54
blas_interface< SCALAR >::symv
static void symv(gene_matrix &A, gene_vector &B, gene_vector &X, int N)
Definition: blas_interface_impl.hh:21
trsv
int EIGEN_BLAS_FUNC() trsv(const char *uplo, const char *opa, const char *diag, const int *n, const RealScalar *pa, const int *lda, RealScalar *pb, const int *incb)
Definition: level2_impl.h:86
N
#define N
Definition: igam.h:9
nonunit
static char nonunit
Definition: blas_interface.hh:59
blas_interface< SCALAR >::trmm
static void trmm(gene_matrix &A, gene_matrix &B, gene_matrix &, int N)
Definition: blas_interface_impl.hh:94
blas_interface< SCALAR >::trisolve_lower_matrix
static void trisolve_lower_matrix(const gene_matrix &L, const gene_matrix &B, gene_matrix &X, int N)
Definition: blas_interface_impl.hh:89
blas_interface< SCALAR >::name
static std::string name()
Definition: blas_interface_impl.hh:12
blas_interface< SCALAR >::aat_product
static void aat_product(gene_matrix &A, gene_matrix &X, int N)
Definition: blas_interface_impl.hh:53
blas_interface< SCALAR >::partial_lu_decomp
static void partial_lu_decomp(const gene_matrix &X, gene_matrix &C, int N)
Definition: blas_interface_impl.hh:75
MAKE_STRING
#define MAKE_STRING(S)
Definition: blas_interface.hh:48


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:12