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 // IWYU pragma: private
37 #include "../InternalHeaderCheck.h"
38 
39 namespace Eigen {
40 
41 namespace internal {
42 
43 /**********************************************************************
44  * This file implements selfadjoint matrix-vector multiplication using BLAS
45  **********************************************************************/
46 
47 // symv/hemv specialization
48 
49 template <typename Scalar, typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs>
51  : selfadjoint_matrix_vector_product<Scalar, Index, StorageOrder, UpLo, ConjugateLhs, ConjugateRhs, BuiltIn> {};
52 
53 #define EIGEN_BLAS_SYMV_SPECIALIZE(Scalar) \
54  template <typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs> \
55  struct selfadjoint_matrix_vector_product<Scalar, Index, StorageOrder, UpLo, ConjugateLhs, ConjugateRhs, \
56  Specialized> { \
57  static void run(Index size, const Scalar* lhs, Index lhsStride, const Scalar* _rhs, Scalar* res, Scalar alpha) { \
58  enum { IsColMajor = StorageOrder == ColMajor }; \
59  if (IsColMajor == ConjugateLhs) { \
60  selfadjoint_matrix_vector_product<Scalar, Index, StorageOrder, UpLo, ConjugateLhs, ConjugateRhs, \
61  BuiltIn>::run(size, lhs, lhsStride, _rhs, res, alpha); \
62  } else { \
63  selfadjoint_matrix_vector_product_symv<Scalar, Index, StorageOrder, UpLo, ConjugateLhs, ConjugateRhs>::run( \
64  size, lhs, lhsStride, _rhs, res, alpha); \
65  } \
66  } \
67  };
68 
73 
74 #define EIGEN_BLAS_SYMV_SPECIALIZATION(EIGTYPE, BLASTYPE, BLASFUNC) \
75  template <typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs> \
76  struct selfadjoint_matrix_vector_product_symv<EIGTYPE, Index, StorageOrder, UpLo, ConjugateLhs, ConjugateRhs> { \
77  typedef Matrix<EIGTYPE, Dynamic, 1, ColMajor> SYMVVector; \
78  \
79  static void run(Index size, const EIGTYPE* lhs, Index lhsStride, const EIGTYPE* _rhs, EIGTYPE* res, \
80  EIGTYPE alpha) { \
81  if (size == 0) return; \
82  enum { IsRowMajor = StorageOrder == RowMajor ? 1 : 0, IsLower = UpLo == Lower ? 1 : 0 }; \
83  BlasIndex n = convert_index<BlasIndex>(size), lda = convert_index<BlasIndex>(lhsStride), incx = 1, incy = 1; \
84  EIGTYPE beta(1); \
85  const EIGTYPE* x_ptr; \
86  char uplo = (IsRowMajor) ? (IsLower ? 'U' : 'L') : (IsLower ? 'L' : 'U'); \
87  SYMVVector x_tmp; \
88  if (ConjugateRhs) { \
89  Map<const SYMVVector, 0> map_x(_rhs, size, 1); \
90  x_tmp = map_x.conjugate(); \
91  x_ptr = x_tmp.data(); \
92  } else \
93  x_ptr = _rhs; \
94  BLASFUNC(&uplo, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)lhs, &lda, \
95  (const BLASTYPE*)x_ptr, &incx, (const BLASTYPE*)&numext::real_ref(beta), (BLASTYPE*)res, &incy); \
96  } \
97  };
98 
99 #ifdef EIGEN_USE_MKL
100 EIGEN_BLAS_SYMV_SPECIALIZATION(double, double, dsymv)
104 #else
105 EIGEN_BLAS_SYMV_SPECIALIZATION(double, double, dsymv_)
106 EIGEN_BLAS_SYMV_SPECIALIZATION(float, float, ssymv_)
109 #endif
110 
111 } // end namespace internal
112 
113 } // end namespace Eigen
114 
115 #endif // EIGEN_SELFADJOINT_MATRIX_VECTOR_BLAS_H
#define EIGEN_BLAS_SYMV_SPECIALIZATION(EIGTYPE, BLASTYPE, BLASFUNC)
Definition: SelfadjointMatrixVector_BLAS.h:74
#define EIGEN_BLAS_SYMV_SPECIALIZE(Scalar)
Definition: SelfadjointMatrixVector_BLAS.h:53
int BLASFUNC() dsymv(char *, int *, double *, double *, int *, double *, int *, double *, double *, int *)
int BLASFUNC() chemv(char *, int *, float *, float *, int *, float *, int *, float *, float *, int *)
int BLASFUNC() zhemv(char *, int *, double *, double *, int *, double *, int *, double *, double *, int *)
int BLASFUNC() ssymv(char *, int *, float *, float *, int *, float *, int *, float *, float *, int *)
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
std::complex< double > dcomplex
Definition: MKL_support.h:128
std::complex< float > scomplex
Definition: MKL_support.h:129
Definition: Eigen_Colamd.h:49
Definition: SelfadjointMatrixVector_BLAS.h:51
Definition: SelfadjointMatrixVector.h:34