Eigen  5.0.1
 
Loading...
Searching...
No Matches
TriangularSolverMatrix_BLAS.h
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 * Triangular matrix-matrix solve functionality based on ?TRSM.
30 ********************************************************************************
31*/
32// SPDX-License-Identifier: BSD-3-Clause
33
34#ifndef EIGEN_TRIANGULAR_SOLVER_MATRIX_BLAS_H
35#define EIGEN_TRIANGULAR_SOLVER_MATRIX_BLAS_H
36
37// IWYU pragma: private
38#include "../InternalHeaderCheck.h"
39
40namespace Eigen {
41
42namespace internal {
43
44// implements LeftSide op(triangular)^-1 * general
45#define EIGEN_BLAS_TRSM_L(EIGTYPE, BLASTYPE, BLASFUNC) \
46 template <typename Index, int Mode, bool Conjugate, int TriStorageOrder> \
47 struct triangular_solve_matrix<EIGTYPE, Index, OnTheLeft, Mode, Conjugate, TriStorageOrder, ColMajor, 1> { \
48 enum { \
49 IsLower = (Mode & Lower) == Lower, \
50 IsUnitDiag = (Mode & UnitDiag) ? 1 : 0, \
51 IsZeroDiag = (Mode & ZeroDiag) ? 1 : 0, \
52 conjA = ((TriStorageOrder == ColMajor) && Conjugate) ? 1 : 0 \
53 }; \
54 static void run(Index size, Index otherSize, const EIGTYPE* _tri, Index triStride, EIGTYPE* _other, \
55 Index otherIncr, Index otherStride, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) { \
56 if (size == 0 || otherSize == 0) return; \
57 EIGEN_ONLY_USED_FOR_DEBUG(otherIncr); \
58 eigen_assert(otherIncr == 1); \
59 BlasIndex m = convert_index<BlasIndex>(size), n = convert_index<BlasIndex>(otherSize), lda, ldb; \
60 char side = 'L', uplo, diag = 'N', transa; \
61 /* Set alpha_ */ \
62 EIGTYPE alpha(1); \
63 ldb = convert_index<BlasIndex>(otherStride); \
64 \
65 const EIGTYPE* a; \
66 /* Set trans */ \
67 transa = (TriStorageOrder == RowMajor) ? ((Conjugate) ? 'C' : 'T') : 'N'; \
68 /* Set uplo */ \
69 uplo = IsLower ? 'L' : 'U'; \
70 EIGEN_IF_CONSTEXPR (TriStorageOrder == RowMajor) { \
71 uplo = (uplo == 'L') ? 'U' : 'L'; \
72 } \
73 /* Set a, lda */ \
74 typedef Matrix<EIGTYPE, Dynamic, Dynamic, TriStorageOrder> MatrixTri; \
75 Map<const MatrixTri, 0, OuterStride<> > tri(_tri, size, size, OuterStride<>(triStride)); \
76 MatrixTri a_tmp; \
77 \
78 EIGEN_IF_CONSTEXPR (conjA) { \
79 a_tmp = tri.conjugate(); \
80 a = a_tmp.data(); \
81 lda = convert_index<BlasIndex>(a_tmp.outerStride()); \
82 } else { \
83 a = _tri; \
84 lda = convert_index<BlasIndex>(triStride); \
85 } \
86 EIGEN_IF_CONSTEXPR (IsUnitDiag) { \
87 diag = 'U'; \
88 } \
89 /* call ?trsm*/ \
90 BLASFUNC(&side, &uplo, &transa, &diag, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, \
91 &lda, (BLASTYPE*)_other, &ldb); \
92 } \
93 };
94
95#ifdef EIGEN_USE_MKL
96EIGEN_BLAS_TRSM_L(double, double, dtrsm)
97EIGEN_BLAS_TRSM_L(dcomplex, MKL_Complex16, ztrsm)
98EIGEN_BLAS_TRSM_L(float, float, strsm)
99EIGEN_BLAS_TRSM_L(scomplex, MKL_Complex8, ctrsm)
100#else
101EIGEN_BLAS_TRSM_L(double, double, EIGEN_BLAS_SYM(dtrsm))
102EIGEN_BLAS_TRSM_L(dcomplex, double, EIGEN_BLAS_SYM(ztrsm))
103EIGEN_BLAS_TRSM_L(float, float, EIGEN_BLAS_SYM(strsm))
104EIGEN_BLAS_TRSM_L(scomplex, float, EIGEN_BLAS_SYM(ctrsm))
105#endif
106
107// implements RightSide general * op(triangular)^-1
108#define EIGEN_BLAS_TRSM_R(EIGTYPE, BLASTYPE, BLASFUNC) \
109 template <typename Index, int Mode, bool Conjugate, int TriStorageOrder> \
110 struct triangular_solve_matrix<EIGTYPE, Index, OnTheRight, Mode, Conjugate, TriStorageOrder, ColMajor, 1> { \
111 enum { \
112 IsLower = (Mode & Lower) == Lower, \
113 IsUnitDiag = (Mode & UnitDiag) ? 1 : 0, \
114 IsZeroDiag = (Mode & ZeroDiag) ? 1 : 0, \
115 conjA = ((TriStorageOrder == ColMajor) && Conjugate) ? 1 : 0 \
116 }; \
117 static void run(Index size, Index otherSize, const EIGTYPE* _tri, Index triStride, EIGTYPE* _other, \
118 Index otherIncr, Index otherStride, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) { \
119 if (size == 0 || otherSize == 0) return; \
120 EIGEN_ONLY_USED_FOR_DEBUG(otherIncr); \
121 eigen_assert(otherIncr == 1); \
122 BlasIndex m = convert_index<BlasIndex>(otherSize), n = convert_index<BlasIndex>(size), lda, ldb; \
123 char side = 'R', uplo, diag = 'N', transa; \
124 /* Set alpha_ */ \
125 EIGTYPE alpha(1); \
126 ldb = convert_index<BlasIndex>(otherStride); \
127 \
128 const EIGTYPE* a; \
129 /* Set trans */ \
130 transa = (TriStorageOrder == RowMajor) ? ((Conjugate) ? 'C' : 'T') : 'N'; \
131 /* Set uplo */ \
132 uplo = IsLower ? 'L' : 'U'; \
133 EIGEN_IF_CONSTEXPR (TriStorageOrder == RowMajor) { \
134 uplo = (uplo == 'L') ? 'U' : 'L'; \
135 } \
136 /* Set a, lda */ \
137 typedef Matrix<EIGTYPE, Dynamic, Dynamic, TriStorageOrder> MatrixTri; \
138 Map<const MatrixTri, 0, OuterStride<> > tri(_tri, size, size, OuterStride<>(triStride)); \
139 MatrixTri a_tmp; \
140 \
141 EIGEN_IF_CONSTEXPR (conjA) { \
142 a_tmp = tri.conjugate(); \
143 a = a_tmp.data(); \
144 lda = convert_index<BlasIndex>(a_tmp.outerStride()); \
145 } else { \
146 a = _tri; \
147 lda = convert_index<BlasIndex>(triStride); \
148 } \
149 EIGEN_IF_CONSTEXPR (IsUnitDiag) { \
150 diag = 'U'; \
151 } \
152 /* call ?trsm*/ \
153 BLASFUNC(&side, &uplo, &transa, &diag, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, \
154 &lda, (BLASTYPE*)_other, &ldb); \
155 /*std::cout << "TRMS_L specialization!\n";*/ \
156 } \
157 };
158
159#ifdef EIGEN_USE_MKL
160EIGEN_BLAS_TRSM_R(double, double, dtrsm)
161EIGEN_BLAS_TRSM_R(dcomplex, MKL_Complex16, ztrsm)
162EIGEN_BLAS_TRSM_R(float, float, strsm)
163EIGEN_BLAS_TRSM_R(scomplex, MKL_Complex8, ctrsm)
164#else
165EIGEN_BLAS_TRSM_R(double, double, EIGEN_BLAS_SYM(dtrsm))
166EIGEN_BLAS_TRSM_R(dcomplex, double, EIGEN_BLAS_SYM(ztrsm))
167EIGEN_BLAS_TRSM_R(float, float, EIGEN_BLAS_SYM(strsm))
168EIGEN_BLAS_TRSM_R(scomplex, float, EIGEN_BLAS_SYM(ctrsm))
169#endif
170
171#undef EIGEN_BLAS_TRSM_R
172#undef EIGEN_BLAS_TRSM_L
173} // end namespace internal
174
175} // end namespace Eigen
176
177#endif // EIGEN_TRIANGULAR_SOLVER_MATRIX_BLAS_H