10 #ifndef EIGEN_TRIANGULAR_MATRIX_MATRIX_H 11 #define EIGEN_TRIANGULAR_MATRIX_MATRIX_H 44 template <
typename Scalar,
typename Index,
45 int Mode,
bool LhsIsTriangular,
46 int LhsStorageOrder,
bool ConjugateLhs,
47 int RhsStorageOrder,
bool ConjugateRhs,
48 int ResStorageOrder,
int Version = Specialized>
49 struct product_triangular_matrix_matrix;
51 template <
typename Scalar,
typename Index,
52 int Mode,
bool LhsIsTriangular,
53 int LhsStorageOrder,
bool ConjugateLhs,
54 int RhsStorageOrder,
bool ConjugateRhs,
int Version>
55 struct product_triangular_matrix_matrix<Scalar,Index,Mode,LhsIsTriangular,
56 LhsStorageOrder,ConjugateLhs,
57 RhsStorageOrder,ConjugateRhs,
RowMajor,Version>
59 static EIGEN_STRONG_INLINE
void run(
60 Index rows, Index cols, Index depth,
61 const Scalar* lhs, Index lhsStride,
62 const Scalar* rhs, Index rhsStride,
63 Scalar* res, Index resStride,
64 const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking)
66 product_triangular_matrix_matrix<Scalar, Index,
71 LhsStorageOrder==RowMajor ?
ColMajor : RowMajor,
74 ::run(cols, rows, depth, rhs, rhsStride, lhs, lhsStride, res, resStride, alpha, blocking);
79 template <
typename Scalar,
typename Index,
int Mode,
80 int LhsStorageOrder,
bool ConjugateLhs,
81 int RhsStorageOrder,
bool ConjugateRhs,
int Version>
82 struct product_triangular_matrix_matrix<Scalar,Index,Mode,true,
83 LhsStorageOrder,ConjugateLhs,
84 RhsStorageOrder,ConjugateRhs,
ColMajor,Version>
87 typedef gebp_traits<Scalar,Scalar> Traits;
89 SmallPanelWidth = 2 * EIGEN_PLAIN_ENUM_MAX(Traits::mr,Traits::nr),
94 static EIGEN_DONT_INLINE
void run(
95 Index _rows, Index _cols, Index _depth,
96 const Scalar* _lhs, Index lhsStride,
97 const Scalar* _rhs, Index rhsStride,
98 Scalar* res, Index resStride,
99 const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking);
102 template <
typename Scalar,
typename Index,
int Mode,
103 int LhsStorageOrder,
bool ConjugateLhs,
104 int RhsStorageOrder,
bool ConjugateRhs,
int Version>
105 EIGEN_DONT_INLINE
void product_triangular_matrix_matrix<Scalar,Index,Mode,
true,
106 LhsStorageOrder,ConjugateLhs,
107 RhsStorageOrder,ConjugateRhs,
ColMajor,Version>::run(
108 Index _rows, Index _cols, Index _depth,
109 const Scalar* _lhs, Index lhsStride,
110 const Scalar* _rhs, Index rhsStride,
111 Scalar* _res, Index resStride,
112 const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking)
115 Index diagSize = (std::min)(_rows,_depth);
116 Index rows = IsLower ? _rows : diagSize;
117 Index depth = IsLower ? diagSize : _depth;
120 typedef const_blas_data_mapper<Scalar, Index, LhsStorageOrder> LhsMapper;
121 typedef const_blas_data_mapper<Scalar, Index, RhsStorageOrder> RhsMapper;
122 typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor> ResMapper;
123 LhsMapper lhs(_lhs,lhsStride);
124 RhsMapper rhs(_rhs,rhsStride);
125 ResMapper res(_res, resStride);
127 Index kc = blocking.kc();
128 Index mc = (std::min)(rows,blocking.mc());
130 std::size_t sizeA = kc*mc;
131 std::size_t sizeB = kc*cols;
133 ei_declare_aligned_stack_constructed_variable(Scalar, blockA, sizeA, blocking.blockA());
134 ei_declare_aligned_stack_constructed_variable(Scalar, blockB, sizeB, blocking.blockB());
136 Matrix<Scalar,SmallPanelWidth,SmallPanelWidth,LhsStorageOrder> triangularBuffer;
137 triangularBuffer.setZero();
139 triangularBuffer.diagonal().setZero();
141 triangularBuffer.diagonal().setOnes();
143 gebp_kernel<Scalar, Scalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp_kernel;
144 gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, LhsStorageOrder> pack_lhs;
145 gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr,RhsStorageOrder> pack_rhs;
147 for(Index k2=IsLower ? depth : 0;
148 IsLower ? k2>0 : k2<depth;
149 IsLower ? k2-=kc : k2+=kc)
151 Index actual_kc = (std::min)(IsLower ? k2 : depth-k2, kc);
152 Index actual_k2 = IsLower ? k2-actual_kc : k2;
155 if((!IsLower)&&(k2<rows)&&(k2+actual_kc>rows))
158 k2 = k2+actual_kc-kc;
161 pack_rhs(blockB, rhs.getSubMapper(actual_k2,0), actual_kc, cols);
169 if(IsLower || actual_k2<rows)
172 for (Index k1=0; k1<actual_kc; k1+=SmallPanelWidth)
174 Index actualPanelWidth = std::min<Index>(actual_kc-k1, SmallPanelWidth);
175 Index lengthTarget = IsLower ? actual_kc-k1-actualPanelWidth : k1;
176 Index startBlock = actual_k2+k1;
177 Index blockBOffset = k1;
182 for (Index k=0;k<actualPanelWidth;++k)
185 triangularBuffer.coeffRef(k,k) = lhs(startBlock+k,startBlock+k);
186 for (Index i=IsLower ? k+1 : 0; IsLower ? i<actualPanelWidth : i<k; ++i)
187 triangularBuffer.coeffRef(i,k) = lhs(startBlock+i,startBlock+k);
189 pack_lhs(blockA, LhsMapper(triangularBuffer.data(), triangularBuffer.outerStride()), actualPanelWidth, actualPanelWidth);
191 gebp_kernel(res.getSubMapper(startBlock, 0), blockA, blockB,
192 actualPanelWidth, actualPanelWidth, cols, alpha,
193 actualPanelWidth, actual_kc, 0, blockBOffset);
198 Index startTarget = IsLower ? actual_k2+k1+actualPanelWidth : actual_k2;
200 pack_lhs(blockA, lhs.getSubMapper(startTarget,startBlock), actualPanelWidth, lengthTarget);
202 gebp_kernel(res.getSubMapper(startTarget, 0), blockA, blockB,
203 lengthTarget, actualPanelWidth, cols, alpha,
204 actualPanelWidth, actual_kc, 0, blockBOffset);
210 Index start = IsLower ? k2 : 0;
211 Index end = IsLower ? rows : (std::min)(actual_k2,rows);
212 for(Index i2=start; i2<end; i2+=mc)
214 const Index actual_mc = (std::min)(i2+mc,end)-i2;
215 gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr,Traits::LhsProgress, LhsStorageOrder,false>()
216 (blockA, lhs.getSubMapper(i2, actual_k2), actual_kc, actual_mc);
218 gebp_kernel(res.getSubMapper(i2, 0), blockA, blockB, actual_mc,
219 actual_kc, cols, alpha, -1, -1, 0, 0);
226 template <
typename Scalar,
typename Index,
int Mode,
227 int LhsStorageOrder,
bool ConjugateLhs,
228 int RhsStorageOrder,
bool ConjugateRhs,
int Version>
229 struct product_triangular_matrix_matrix<Scalar,Index,Mode,false,
230 LhsStorageOrder,ConjugateLhs,
231 RhsStorageOrder,ConjugateRhs,ColMajor,Version>
233 typedef gebp_traits<Scalar,Scalar> Traits;
235 SmallPanelWidth = EIGEN_PLAIN_ENUM_MAX(Traits::mr,Traits::nr),
237 SetDiag = (Mode&(ZeroDiag|
UnitDiag)) ? 0 : 1
240 static EIGEN_DONT_INLINE
void run(
241 Index _rows, Index _cols, Index _depth,
242 const Scalar* _lhs, Index lhsStride,
243 const Scalar* _rhs, Index rhsStride,
244 Scalar* res, Index resStride,
245 const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking);
248 template <
typename Scalar,
typename Index,
int Mode,
249 int LhsStorageOrder,
bool ConjugateLhs,
250 int RhsStorageOrder,
bool ConjugateRhs,
int Version>
251 EIGEN_DONT_INLINE
void product_triangular_matrix_matrix<Scalar,Index,Mode,
false,
252 LhsStorageOrder,ConjugateLhs,
253 RhsStorageOrder,ConjugateRhs,
ColMajor,Version>::run(
254 Index _rows, Index _cols, Index _depth,
255 const Scalar* _lhs, Index lhsStride,
256 const Scalar* _rhs, Index rhsStride,
257 Scalar* _res, Index resStride,
258 const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking)
260 const Index PacketBytes = packet_traits<Scalar>::size*
sizeof(Scalar);
262 Index diagSize = (std::min)(_cols,_depth);
264 Index depth = IsLower ? _depth : diagSize;
265 Index cols = IsLower ? diagSize : _cols;
267 typedef const_blas_data_mapper<Scalar, Index, LhsStorageOrder> LhsMapper;
268 typedef const_blas_data_mapper<Scalar, Index, RhsStorageOrder> RhsMapper;
269 typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor> ResMapper;
270 LhsMapper lhs(_lhs,lhsStride);
271 RhsMapper rhs(_rhs,rhsStride);
272 ResMapper res(_res, resStride);
274 Index kc = blocking.kc();
275 Index mc = (std::min)(rows,blocking.mc());
277 std::size_t sizeA = kc*mc;
278 std::size_t sizeB = kc*cols+EIGEN_MAX_ALIGN_BYTES/
sizeof(Scalar);
280 ei_declare_aligned_stack_constructed_variable(Scalar, blockA, sizeA, blocking.blockA());
281 ei_declare_aligned_stack_constructed_variable(Scalar, blockB, sizeB, blocking.blockB());
283 Matrix<Scalar,SmallPanelWidth,SmallPanelWidth,RhsStorageOrder> triangularBuffer;
284 triangularBuffer.setZero();
285 if((Mode&ZeroDiag)==ZeroDiag)
286 triangularBuffer.diagonal().setZero();
288 triangularBuffer.diagonal().setOnes();
290 gebp_kernel<Scalar, Scalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp_kernel;
291 gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, LhsStorageOrder> pack_lhs;
292 gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr,RhsStorageOrder> pack_rhs;
293 gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr,RhsStorageOrder,false,true> pack_rhs_panel;
295 for(Index k2=IsLower ? 0 : depth;
296 IsLower ? k2<depth : k2>0;
297 IsLower ? k2+=kc : k2-=kc)
299 Index actual_kc = (std::min)(IsLower ? depth-k2 : k2, kc);
300 Index actual_k2 = IsLower ? k2 : k2-actual_kc;
303 if(IsLower && (k2<cols) && (actual_k2+actual_kc>cols))
306 k2 = actual_k2 + actual_kc - kc;
310 Index rs = IsLower ? (std::min)(cols,actual_k2) : cols - k2;
312 Index ts = (IsLower && actual_k2>=cols) ? 0 : actual_kc;
314 Scalar* geb = blockB+ts*ts;
315 geb = geb + internal::first_aligned<PacketBytes>(geb,PacketBytes/
sizeof(Scalar));
317 pack_rhs(geb, rhs.getSubMapper(actual_k2,IsLower ? 0 : k2), actual_kc, rs);
322 for (Index j2=0; j2<actual_kc; j2+=SmallPanelWidth)
324 Index actualPanelWidth = std::min<Index>(actual_kc-j2, SmallPanelWidth);
325 Index actual_j2 = actual_k2 + j2;
326 Index panelOffset = IsLower ? j2+actualPanelWidth : 0;
327 Index panelLength = IsLower ? actual_kc-j2-actualPanelWidth : j2;
329 pack_rhs_panel(blockB+j2*actual_kc,
330 rhs.getSubMapper(actual_k2+panelOffset, actual_j2),
331 panelLength, actualPanelWidth,
332 actual_kc, panelOffset);
335 for (Index j=0;j<actualPanelWidth;++j)
338 triangularBuffer.coeffRef(j,j) = rhs(actual_j2+j,actual_j2+j);
339 for (Index k=IsLower ? j+1 : 0; IsLower ? k<actualPanelWidth : k<j; ++k)
340 triangularBuffer.coeffRef(k,j) = rhs(actual_j2+k,actual_j2+j);
343 pack_rhs_panel(blockB+j2*actual_kc,
344 RhsMapper(triangularBuffer.data(), triangularBuffer.outerStride()),
345 actualPanelWidth, actualPanelWidth,
350 for (Index i2=0; i2<rows; i2+=mc)
352 const Index actual_mc = (std::min)(mc,rows-i2);
353 pack_lhs(blockA, lhs.getSubMapper(i2, actual_k2), actual_kc, actual_mc);
358 for (Index j2=0; j2<actual_kc; j2+=SmallPanelWidth)
360 Index actualPanelWidth = std::min<Index>(actual_kc-j2, SmallPanelWidth);
361 Index panelLength = IsLower ? actual_kc-j2 : j2+actualPanelWidth;
362 Index blockOffset = IsLower ? j2 : 0;
364 gebp_kernel(res.getSubMapper(i2, actual_k2 + j2),
365 blockA, blockB+j2*actual_kc,
366 actual_mc, panelLength, actualPanelWidth,
368 actual_kc, actual_kc,
369 blockOffset, blockOffset);
372 gebp_kernel(res.getSubMapper(i2, IsLower ? 0 : k2),
373 blockA, geb, actual_mc, actual_kc, rs,
387 template<
int Mode,
bool LhsIsTriangular,
typename Lhs,
typename Rhs>
388 struct triangular_product_impl<Mode,LhsIsTriangular,Lhs,false,Rhs,false>
390 template<
typename Dest>
static void run(Dest& dst,
const Lhs &a_lhs,
const Rhs &a_rhs,
const typename Dest::Scalar& alpha)
392 typedef typename Dest::Scalar Scalar;
394 typedef internal::blas_traits<Lhs> LhsBlasTraits;
395 typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType;
396 typedef typename internal::remove_all<ActualLhsType>::type ActualLhsTypeCleaned;
397 typedef internal::blas_traits<Rhs> RhsBlasTraits;
398 typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType;
399 typedef typename internal::remove_all<ActualRhsType>::type ActualRhsTypeCleaned;
401 typename internal::add_const_on_value_type<ActualLhsType>::type lhs = LhsBlasTraits::extract(a_lhs);
402 typename internal::add_const_on_value_type<ActualRhsType>::type rhs = RhsBlasTraits::extract(a_rhs);
404 Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(a_lhs)
405 * RhsBlasTraits::extractScalarFactor(a_rhs);
407 typedef internal::gemm_blocking_space<(Dest::Flags&
RowMajorBit) ?
RowMajor : ColMajor,Scalar,Scalar,
408 Lhs::MaxRowsAtCompileTime, Rhs::MaxColsAtCompileTime, Lhs::MaxColsAtCompileTime,4> BlockingType;
411 Index stripedRows = ((!LhsIsTriangular) || (IsLower)) ? lhs.rows() : (std::min)(lhs.rows(),lhs.cols());
412 Index stripedCols = ((LhsIsTriangular) || (!IsLower)) ? rhs.cols() : (std::min)(rhs.cols(),rhs.rows());
413 Index stripedDepth = LhsIsTriangular ? ((!IsLower) ? lhs.cols() : (std::min)(lhs.cols(),lhs.rows()))
414 : ((IsLower) ? rhs.rows() : (
std::min)(rhs.rows(),rhs.cols()));
416 BlockingType blocking(stripedRows, stripedCols, stripedDepth, 1,
false);
418 internal::product_triangular_matrix_matrix<Scalar, Index,
419 Mode, LhsIsTriangular,
420 (internal::traits<ActualLhsTypeCleaned>::Flags&
RowMajorBit) ?
RowMajor : ColMajor, LhsBlasTraits::NeedToConjugate,
424 stripedRows, stripedCols, stripedDepth,
425 &lhs.coeffRef(0,0), lhs.outerStride(),
426 &rhs.coeffRef(0,0), rhs.outerStride(),
427 &dst.coeffRef(0,0), dst.outerStride(),
428 actualAlpha, blocking
437 #endif // EIGEN_TRIANGULAR_MATRIX_MATRIX_H Definition: Constants.h:210
Definition: StdDeque.h:58
const unsigned int RowMajorBit
Definition: Constants.h:61
Definition: Constants.h:320
Definition: Constants.h:204
Definition: Constants.h:322
Definition: Eigen_Colamd.h:54
Definition: Constants.h:208
Definition: Constants.h:206