SelfadjointMatrixVector_BLAS.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2011, Intel Corporation. All rights reserved.
3 
4  Redistribution and use in source and binary forms, with or without modification,
5  are permitted provided that the following conditions are met:
6 
7  * Redistributions of source code must retain the above copyright notice, this
8  list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright notice,
10  this list of conditions and the following disclaimer in the documentation
11  and/or other materials provided with the distribution.
12  * Neither the name of Intel Corporation nor the names of its contributors may
13  be used to endorse or promote products derived from this software without
14  specific prior written permission.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27  ********************************************************************************
28  * Content : Eigen bindings to BLAS F77
29  * Selfadjoint matrix-vector product functionality based on ?SYMV/HEMV.
30  ********************************************************************************
31 */
32 
33 #ifndef EIGEN_SELFADJOINT_MATRIX_VECTOR_BLAS_H
34 #define EIGEN_SELFADJOINT_MATRIX_VECTOR_BLAS_H
35 
36 #include "../InternalHeaderCheck.h"
37 
38 namespace Eigen {
39 
40 namespace internal {
41 
42 
46 // symv/hemv specialization
47 
48 template<typename Scalar, typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs>
49 struct selfadjoint_matrix_vector_product_symv :
50  selfadjoint_matrix_vector_product<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs,BuiltIn> {};
51 
52 #define EIGEN_BLAS_SYMV_SPECIALIZE(Scalar) \
53 template<typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs> \
54 struct selfadjoint_matrix_vector_product<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs,Specialized> { \
55 static void run( \
56  Index size, const Scalar* lhs, Index lhsStride, \
57  const Scalar* _rhs, Scalar* res, Scalar alpha) { \
58  enum {\
59  IsColMajor = StorageOrder==ColMajor \
60  }; \
61  if (IsColMajor == ConjugateLhs) {\
62  selfadjoint_matrix_vector_product<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs,BuiltIn>::run( \
63  size, lhs, lhsStride, _rhs, res, alpha); \
64  } else {\
65  selfadjoint_matrix_vector_product_symv<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs>::run( \
66  size, lhs, lhsStride, _rhs, res, alpha); \
67  }\
68  } \
69 }; \
70 
75 
76 #define EIGEN_BLAS_SYMV_SPECIALIZATION(EIGTYPE,BLASTYPE,BLASFUNC) \
77 template<typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs> \
78 struct selfadjoint_matrix_vector_product_symv<EIGTYPE,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs> \
79 { \
80 typedef Matrix<EIGTYPE,Dynamic,1,ColMajor> SYMVVector;\
81 \
82 static void run( \
83 Index size, const EIGTYPE* lhs, Index lhsStride, \
84 const EIGTYPE* _rhs, EIGTYPE* res, EIGTYPE alpha) \
85 { \
86  enum {\
87  IsRowMajor = StorageOrder==RowMajor ? 1 : 0, \
88  IsLower = UpLo == Lower ? 1 : 0 \
89  }; \
90  BlasIndex n=convert_index<BlasIndex>(size), lda=convert_index<BlasIndex>(lhsStride), incx=1, incy=1; \
91  EIGTYPE beta(1); \
92  const EIGTYPE *x_ptr; \
93  char uplo=(IsRowMajor) ? (IsLower ? 'U' : 'L') : (IsLower ? 'L' : 'U'); \
94  SYMVVector x_tmp; \
95  if (ConjugateRhs) { \
96  Map<const SYMVVector, 0 > map_x(_rhs,size,1); \
97  x_tmp=map_x.conjugate(); \
98  x_ptr=x_tmp.data(); \
99  } else x_ptr=_rhs; \
100  BLASFUNC(&uplo, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)lhs, &lda, (const BLASTYPE*)x_ptr, &incx, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)res, &incy); \
101 }\
102 };
103 
104 #ifdef EIGEN_USE_MKL
105 EIGEN_BLAS_SYMV_SPECIALIZATION(double, double, dsymv)
109 #else
110 EIGEN_BLAS_SYMV_SPECIALIZATION(double, double, dsymv_)
111 EIGEN_BLAS_SYMV_SPECIALIZATION(float, float, ssymv_)
114 #endif
115 
116 } // end namespace internal
117 
118 } // end namespace Eigen
119 
120 #endif // EIGEN_SELFADJOINT_MATRIX_VECTOR_BLAS_H
#define EIGEN_BLAS_SYMV_SPECIALIZATION(EIGTYPE, BLASTYPE, BLASFUNC)
#define EIGEN_BLAS_SYMV_SPECIALIZE(Scalar)
int BLASFUNC() ssymv(const char *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *)
int BLASFUNC() zhemv(const char *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *)
int BLASFUNC() dsymv(const char *, const int *, const double *, const double *, const int *, const double *, const int *, const double *, double *, const int *)
int BLASFUNC() chemv(const char *, const int *, const float *, const float *, const int *, const float *, const int *, const float *, float *, const int *)
: InteropHeaders
Definition: Core:139
std::complex< double > dcomplex
Definition: MKL_support.h:127
std::complex< float > scomplex
Definition: MKL_support.h:128