TriangularSolverMatrix_MKL.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 Intel(R) MKL
29  * Triangular matrix * matrix product functionality based on ?TRMM.
30  ********************************************************************************
31 */
32 
33 #ifndef EIGEN_TRIANGULAR_SOLVER_MATRIX_MKL_H
34 #define EIGEN_TRIANGULAR_SOLVER_MATRIX_MKL_H
35 
36 namespace Eigen {
37 
38 namespace internal {
39 
40 // implements LeftSide op(triangular)^-1 * general
41 #define EIGEN_MKL_TRSM_L(EIGTYPE, MKLTYPE, MKLPREFIX) \
42 template <typename Index, int Mode, bool Conjugate, int TriStorageOrder> \
43 struct triangular_solve_matrix<EIGTYPE,Index,OnTheLeft,Mode,Conjugate,TriStorageOrder,ColMajor> \
44 { \
45  enum { \
46  IsLower = (Mode&Lower) == Lower, \
47  IsUnitDiag = (Mode&UnitDiag) ? 1 : 0, \
48  IsZeroDiag = (Mode&ZeroDiag) ? 1 : 0, \
49  conjA = ((TriStorageOrder==ColMajor) && Conjugate) ? 1 : 0 \
50  }; \
51  static void run( \
52  Index size, Index otherSize, \
53  const EIGTYPE* _tri, Index triStride, \
54  EIGTYPE* _other, Index otherStride, level3_blocking<EIGTYPE,EIGTYPE>& /*blocking*/) \
55  { \
56  MKL_INT m = size, n = otherSize, lda, ldb; \
57  char side = 'L', uplo, diag='N', transa; \
58  /* Set alpha_ */ \
59  MKLTYPE alpha; \
60  EIGTYPE myone(1); \
61  assign_scalar_eig2mkl(alpha, myone); \
62  ldb = otherStride;\
63 \
64  const EIGTYPE *a; \
65 /* Set trans */ \
66  transa = (TriStorageOrder==RowMajor) ? ((Conjugate) ? 'C' : 'T') : 'N'; \
67 /* Set uplo */ \
68  uplo = IsLower ? 'L' : 'U'; \
69  if (TriStorageOrder==RowMajor) uplo = (uplo == 'L') ? 'U' : 'L'; \
70 /* Set a, lda */ \
71  typedef Matrix<EIGTYPE, Dynamic, Dynamic, TriStorageOrder> MatrixTri; \
72  Map<const MatrixTri, 0, OuterStride<> > tri(_tri,size,size,OuterStride<>(triStride)); \
73  MatrixTri a_tmp; \
74 \
75  if (conjA) { \
76  a_tmp = tri.conjugate(); \
77  a = a_tmp.data(); \
78  lda = a_tmp.outerStride(); \
79  } else { \
80  a = _tri; \
81  lda = triStride; \
82  } \
83  if (IsUnitDiag) diag='U'; \
84 /* call ?trsm*/ \
85  MKLPREFIX##trsm(&side, &uplo, &transa, &diag, &m, &n, &alpha, (const MKLTYPE*)a, &lda, (MKLTYPE*)_other, &ldb); \
86  } \
87 };
88 
89 EIGEN_MKL_TRSM_L(double, double, d)
90 EIGEN_MKL_TRSM_L(dcomplex, MKL_Complex16, z)
91 EIGEN_MKL_TRSM_L(float, float, s)
92 EIGEN_MKL_TRSM_L(scomplex, MKL_Complex8, c)
93 
94 
95 // implements RightSide general * op(triangular)^-1
96 #define EIGEN_MKL_TRSM_R(EIGTYPE, MKLTYPE, MKLPREFIX) \
97 template <typename Index, int Mode, bool Conjugate, int TriStorageOrder> \
98 struct triangular_solve_matrix<EIGTYPE,Index,OnTheRight,Mode,Conjugate,TriStorageOrder,ColMajor> \
99 { \
100  enum { \
101  IsLower = (Mode&Lower) == Lower, \
102  IsUnitDiag = (Mode&UnitDiag) ? 1 : 0, \
103  IsZeroDiag = (Mode&ZeroDiag) ? 1 : 0, \
104  conjA = ((TriStorageOrder==ColMajor) && Conjugate) ? 1 : 0 \
105  }; \
106  static void run( \
107  Index size, Index otherSize, \
108  const EIGTYPE* _tri, Index triStride, \
109  EIGTYPE* _other, Index otherStride, level3_blocking<EIGTYPE,EIGTYPE>& /*blocking*/) \
110  { \
111  MKL_INT m = otherSize, n = size, lda, ldb; \
112  char side = 'R', uplo, diag='N', transa; \
113  /* Set alpha_ */ \
114  MKLTYPE alpha; \
115  EIGTYPE myone(1); \
116  assign_scalar_eig2mkl(alpha, myone); \
117  ldb = otherStride;\
118 \
119  const EIGTYPE *a; \
120 /* Set trans */ \
121  transa = (TriStorageOrder==RowMajor) ? ((Conjugate) ? 'C' : 'T') : 'N'; \
122 /* Set uplo */ \
123  uplo = IsLower ? 'L' : 'U'; \
124  if (TriStorageOrder==RowMajor) uplo = (uplo == 'L') ? 'U' : 'L'; \
125 /* Set a, lda */ \
126  typedef Matrix<EIGTYPE, Dynamic, Dynamic, TriStorageOrder> MatrixTri; \
127  Map<const MatrixTri, 0, OuterStride<> > tri(_tri,size,size,OuterStride<>(triStride)); \
128  MatrixTri a_tmp; \
129 \
130  if (conjA) { \
131  a_tmp = tri.conjugate(); \
132  a = a_tmp.data(); \
133  lda = a_tmp.outerStride(); \
134  } else { \
135  a = _tri; \
136  lda = triStride; \
137  } \
138  if (IsUnitDiag) diag='U'; \
139 /* call ?trsm*/ \
140  MKLPREFIX##trsm(&side, &uplo, &transa, &diag, &m, &n, &alpha, (const MKLTYPE*)a, &lda, (MKLTYPE*)_other, &ldb); \
141  /*std::cout << "TRMS_L specialization!\n";*/ \
142  } \
143 };
144 
145 EIGEN_MKL_TRSM_R(double, double, d)
146 EIGEN_MKL_TRSM_R(dcomplex, MKL_Complex16, z)
147 EIGEN_MKL_TRSM_R(float, float, s)
148 EIGEN_MKL_TRSM_R(scomplex, MKL_Complex8, c)
149 
150 
151 } // end namespace internal
152 
153 } // end namespace Eigen
154 
155 #endif // EIGEN_TRIANGULAR_SOLVER_MATRIX_MKL_H
#define EIGEN_MKL_TRSM_L(EIGTYPE, MKLTYPE, MKLPREFIX)
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
#define EIGEN_MKL_TRSM_R(EIGTYPE, MKLTYPE, MKLPREFIX)


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:35:14