10 #ifndef EIGEN_TRIANGULAR_SOLVER_MATRIX_H
11 #define EIGEN_TRIANGULAR_SOLVER_MATRIX_H
18 template <
typename Scalar,
typename Index,
int S
ide,
int Mode,
bool Conjugate,
int TriStorageOrder>
19 struct triangular_solve_matrix<Scalar,Index,Side,Mode,Conjugate,TriStorageOrder,
RowMajor>
22 Index size, Index cols,
23 const Scalar* tri, Index triStride,
24 Scalar* _other, Index otherStride,
25 level3_blocking<Scalar,Scalar>& blocking)
27 triangular_solve_matrix<
30 NumTraits<Scalar>::IsComplex && Conjugate,
32 ::run(size, cols, tri, triStride, _other, otherStride, blocking);
38 template <
typename Scalar,
typename Index,
int Mode,
bool Conjugate,
int TriStorageOrder>
39 struct triangular_solve_matrix<Scalar,Index,
OnTheLeft,Mode,Conjugate,TriStorageOrder,
ColMajor>
41 static EIGEN_DONT_INLINE
void run(
42 Index size, Index otherSize,
43 const Scalar* _tri, Index triStride,
44 Scalar* _other, Index otherStride,
45 level3_blocking<Scalar,Scalar>& blocking);
47 template <
typename Scalar,
typename Index,
int Mode,
bool Conjugate,
int TriStorageOrder>
48 EIGEN_DONT_INLINE
void triangular_solve_matrix<Scalar,Index,OnTheLeft,Mode,Conjugate,TriStorageOrder,ColMajor>::run(
49 Index size, Index otherSize,
50 const Scalar* _tri, Index triStride,
51 Scalar* _other, Index otherStride,
52 level3_blocking<Scalar,Scalar>& blocking)
54 Index cols = otherSize;
55 const_blas_data_mapper<Scalar, Index, TriStorageOrder> tri(_tri,triStride);
56 blas_data_mapper<Scalar, Index, ColMajor> other(_other,otherStride);
58 typedef gebp_traits<Scalar,Scalar> Traits;
60 SmallPanelWidth = EIGEN_PLAIN_ENUM_MAX(Traits::mr,Traits::nr),
64 Index kc = blocking.kc();
65 Index mc = (std::min)(size,blocking.mc());
67 std::size_t sizeA = kc*mc;
68 std::size_t sizeB = kc*cols;
69 std::size_t sizeW = kc*Traits::WorkSpaceFactor;
71 ei_declare_aligned_stack_constructed_variable(Scalar, blockA, sizeA, blocking.blockA());
72 ei_declare_aligned_stack_constructed_variable(Scalar, blockB, sizeB, blocking.blockB());
73 ei_declare_aligned_stack_constructed_variable(Scalar, blockW, sizeW, blocking.blockW());
75 conj_if<Conjugate> conj;
76 gebp_kernel<Scalar, Scalar, Index, Traits::mr, Traits::nr, Conjugate, false> gebp_kernel;
77 gemm_pack_lhs<Scalar, Index, Traits::mr, Traits::LhsProgress, TriStorageOrder> pack_lhs;
78 gemm_pack_rhs<Scalar, Index, Traits::nr, ColMajor, false, true> pack_rhs;
82 std::ptrdiff_t l1, l2;
83 manage_caching_sizes(GetAction, &l1, &l2);
84 Index subcols = cols>0 ? l2/(4 *
sizeof(Scalar) * otherStride) : 0;
85 subcols = std::max<Index>((subcols/Traits::nr)*Traits::nr, Traits::nr);
87 for(Index k2=IsLower ? 0 : size;
88 IsLower ? k2<size : k2>0;
89 IsLower ? k2+=kc : k2-=kc)
91 const Index actual_kc = (std::min)(IsLower ? size-k2 : k2, kc);
106 for(Index j2=0; j2<cols; j2+=subcols)
108 Index actual_cols = (std::min)(cols-j2,subcols);
110 for (Index k1=0; k1<actual_kc; k1+=SmallPanelWidth)
112 Index actualPanelWidth = std::min<Index>(actual_kc-k1, SmallPanelWidth);
114 for (Index k=0; k<actualPanelWidth; ++k)
117 Index i = IsLower ? k2+k1+k : k2-k1-k-1;
118 Index rs = actualPanelWidth - k - 1;
119 Index s = TriStorageOrder==
RowMajor ? (IsLower ? k2+k1 : i+1)
120 : IsLower ? i+1 : i-rs;
122 Scalar a = (Mode &
UnitDiag) ? Scalar(1) : Scalar(1)/conj(tri(i,i));
123 for (Index j=j2; j<j2+actual_cols; ++j)
128 const Scalar* l = &tri(i,s);
129 Scalar* r = &other(s,j);
130 for (Index i3=0; i3<k; ++i3)
131 b += conj(l[i3]) * r[i3];
133 other(i,j) = (other(i,j) - b)*a;
137 Scalar b = (other(i,j) *= a);
138 Scalar* r = &other(s,j);
139 const Scalar* l = &tri(s,i);
140 for (Index i3=0;i3<rs;++i3)
141 r[i3] -= b * conj(l[i3]);
146 Index lengthTarget = actual_kc-k1-actualPanelWidth;
147 Index startBlock = IsLower ? k2+k1 : k2-k1-actualPanelWidth;
148 Index blockBOffset = IsLower ? k1 : lengthTarget;
151 pack_rhs(blockB+actual_kc*j2, &other(startBlock,j2), otherStride, actualPanelWidth, actual_cols, actual_kc, blockBOffset);
156 Index startTarget = IsLower ? k2+k1+actualPanelWidth : k2-actual_kc;
158 pack_lhs(blockA, &tri(startTarget,startBlock), triStride, actualPanelWidth, lengthTarget);
160 gebp_kernel(&other(startTarget,j2), otherStride, blockA, blockB+actual_kc*j2, lengthTarget, actualPanelWidth, actual_cols, Scalar(-1),
161 actualPanelWidth, actual_kc, 0, blockBOffset, blockW);
168 Index start = IsLower ? k2+kc : 0;
169 Index end = IsLower ? size : k2-kc;
170 for(Index i2=start; i2<end; i2+=mc)
172 const Index actual_mc = (std::min)(mc,end-i2);
175 pack_lhs(blockA, &tri(i2, IsLower ? k2 : k2-kc), triStride, actual_kc, actual_mc);
177 gebp_kernel(_other+i2, otherStride, blockA, blockB, actual_mc, actual_kc, cols, Scalar(-1), -1, -1, 0, 0, blockW);
186 template <
typename Scalar,
typename Index,
int Mode,
bool Conjugate,
int TriStorageOrder>
187 struct triangular_solve_matrix<Scalar,Index,
OnTheRight,Mode,Conjugate,TriStorageOrder,
ColMajor>
189 static EIGEN_DONT_INLINE
void run(
190 Index size, Index otherSize,
191 const Scalar* _tri, Index triStride,
192 Scalar* _other, Index otherStride,
193 level3_blocking<Scalar,Scalar>& blocking);
195 template <
typename Scalar,
typename Index,
int Mode,
bool Conjugate,
int TriStorageOrder>
196 EIGEN_DONT_INLINE
void triangular_solve_matrix<Scalar,Index,OnTheRight,Mode,Conjugate,TriStorageOrder,ColMajor>::run(
197 Index size, Index otherSize,
198 const Scalar* _tri, Index triStride,
199 Scalar* _other, Index otherStride,
200 level3_blocking<Scalar,Scalar>& blocking)
202 Index rows = otherSize;
203 const_blas_data_mapper<Scalar, Index, TriStorageOrder> rhs(_tri,triStride);
204 blas_data_mapper<Scalar, Index, ColMajor> lhs(_other,otherStride);
206 typedef gebp_traits<Scalar,Scalar> Traits;
208 RhsStorageOrder = TriStorageOrder,
209 SmallPanelWidth = EIGEN_PLAIN_ENUM_MAX(Traits::mr,Traits::nr),
213 Index kc = blocking.kc();
214 Index mc = (std::min)(rows,blocking.mc());
216 std::size_t sizeA = kc*mc;
217 std::size_t sizeB = kc*size;
218 std::size_t sizeW = kc*Traits::WorkSpaceFactor;
220 ei_declare_aligned_stack_constructed_variable(Scalar, blockA, sizeA, blocking.blockA());
221 ei_declare_aligned_stack_constructed_variable(Scalar, blockB, sizeB, blocking.blockB());
222 ei_declare_aligned_stack_constructed_variable(Scalar, blockW, sizeW, blocking.blockW());
224 conj_if<Conjugate> conj;
225 gebp_kernel<Scalar,Scalar, Index, Traits::mr, Traits::nr, false, Conjugate> gebp_kernel;
226 gemm_pack_rhs<Scalar, Index, Traits::nr,RhsStorageOrder> pack_rhs;
227 gemm_pack_rhs<Scalar, Index, Traits::nr,RhsStorageOrder,false,true> pack_rhs_panel;
228 gemm_pack_lhs<Scalar, Index, Traits::mr, Traits::LhsProgress, ColMajor, false, true> pack_lhs_panel;
230 for(Index k2=IsLower ? size : 0;
231 IsLower ? k2>0 : k2<size;
232 IsLower ? k2-=kc : k2+=kc)
234 const Index actual_kc = (std::min)(IsLower ? k2 : size-k2, kc);
235 Index actual_k2 = IsLower ? k2-actual_kc : k2 ;
237 Index startPanel = IsLower ? 0 : k2+actual_kc;
238 Index rs = IsLower ? actual_k2 : size - actual_k2 - actual_kc;
239 Scalar* geb = blockB+actual_kc*actual_kc;
241 if (rs>0) pack_rhs(geb, &rhs(actual_k2,startPanel), triStride, actual_kc, rs);
246 for (Index j2=0; j2<actual_kc; j2+=SmallPanelWidth)
248 Index actualPanelWidth = std::min<Index>(actual_kc-j2, SmallPanelWidth);
249 Index actual_j2 = actual_k2 + j2;
250 Index panelOffset = IsLower ? j2+actualPanelWidth : 0;
251 Index panelLength = IsLower ? actual_kc-j2-actualPanelWidth : j2;
254 pack_rhs_panel(blockB+j2*actual_kc,
255 &rhs(actual_k2+panelOffset, actual_j2), triStride,
256 panelLength, actualPanelWidth,
257 actual_kc, panelOffset);
261 for(Index i2=0; i2<rows; i2+=mc)
263 const Index actual_mc = (std::min)(mc,rows-i2);
268 for (Index j2 = IsLower
269 ? (actual_kc - ((actual_kc%SmallPanelWidth) ? Index(actual_kc%SmallPanelWidth)
270 : Index(SmallPanelWidth)))
272 IsLower ? j2>=0 : j2<actual_kc;
273 IsLower ? j2-=SmallPanelWidth : j2+=SmallPanelWidth)
275 Index actualPanelWidth = std::min<Index>(actual_kc-j2, SmallPanelWidth);
276 Index absolute_j2 = actual_k2 + j2;
277 Index panelOffset = IsLower ? j2+actualPanelWidth : 0;
278 Index panelLength = IsLower ? actual_kc - j2 - actualPanelWidth : j2;
283 gebp_kernel(&lhs(i2,absolute_j2), otherStride,
284 blockA, blockB+j2*actual_kc,
285 actual_mc, panelLength, actualPanelWidth,
287 actual_kc, actual_kc,
288 panelOffset, panelOffset,
293 for (Index k=0; k<actualPanelWidth; ++k)
295 Index j = IsLower ? absolute_j2+actualPanelWidth-k-1 : absolute_j2+k;
297 Scalar* r = &lhs(i2,j);
298 for (Index k3=0; k3<k; ++k3)
300 Scalar b = conj(rhs(IsLower ? j+1+k3 : absolute_j2+k3,j));
301 Scalar* a = &lhs(i2,IsLower ? j+1+k3 : absolute_j2+k3);
302 for (Index i=0; i<actual_mc; ++i)
307 Scalar b = conj(rhs(j,j));
308 for (Index i=0; i<actual_mc; ++i)
314 pack_lhs_panel(blockA, _other+absolute_j2*otherStride+i2, otherStride,
315 actualPanelWidth, actual_mc,
321 gebp_kernel(_other+i2+startPanel*otherStride, otherStride, blockA, geb,
322 actual_mc, actual_kc, rs, Scalar(-1),
323 -1, -1, 0, 0, blockW);
332 #endif // EIGEN_TRIANGULAR_SOLVER_MATRIX_H
Definition: Constants.h:167
Definition: Constants.h:264
Definition: Constants.h:169
Definition: Constants.h:279
Definition: Constants.h:171
Definition: Constants.h:266
Definition: Constants.h:277