10 #ifndef EIGEN_TRIANGULAR_MATRIX_MATRIX_H
11 #define EIGEN_TRIANGULAR_MATRIX_MATRIX_H
13 #include "../InternalHeaderCheck.h"
46 template <
typename Scalar,
typename Index,
47 int Mode,
bool LhsIsTriangular,
48 int LhsStorageOrder,
bool ConjugateLhs,
49 int RhsStorageOrder,
bool ConjugateRhs,
50 int ResStorageOrder,
int ResInnerStride,
52 struct product_triangular_matrix_matrix;
54 template <
typename Scalar,
typename Index,
55 int Mode,
bool LhsIsTriangular,
56 int LhsStorageOrder,
bool ConjugateLhs,
57 int RhsStorageOrder,
bool ConjugateRhs,
58 int ResInnerStride,
int Version>
59 struct product_triangular_matrix_matrix<Scalar,
Index,Mode,LhsIsTriangular,
60 LhsStorageOrder,ConjugateLhs,
61 RhsStorageOrder,ConjugateRhs,
RowMajor,ResInnerStride,Version>
63 static EIGEN_STRONG_INLINE
void run(
65 const Scalar* lhs,
Index lhsStride,
66 const Scalar* rhs,
Index rhsStride,
68 const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking)
70 product_triangular_matrix_matrix<Scalar,
Index,
78 ::run(
cols,
rows, depth, rhs, rhsStride, lhs, lhsStride,
res, resIncr, resStride, alpha, blocking);
83 template <
typename Scalar,
typename Index,
int Mode,
84 int LhsStorageOrder,
bool ConjugateLhs,
85 int RhsStorageOrder,
bool ConjugateRhs,
86 int ResInnerStride,
int Version>
87 struct product_triangular_matrix_matrix<Scalar,
Index,Mode,true,
88 LhsStorageOrder,ConjugateLhs,
89 RhsStorageOrder,ConjugateRhs,
ColMajor,ResInnerStride,Version>
92 typedef gebp_traits<Scalar,Scalar> Traits;
101 const Scalar* lhs_,
Index lhsStride,
102 const Scalar* rhs_,
Index rhsStride,
104 const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking);
107 template <
typename Scalar,
typename Index,
int Mode,
108 int LhsStorageOrder,
bool ConjugateLhs,
109 int RhsStorageOrder,
bool ConjugateRhs,
110 int ResInnerStride,
int Version>
112 LhsStorageOrder,ConjugateLhs,
113 RhsStorageOrder,ConjugateRhs,
ColMajor,ResInnerStride,Version>::run(
115 const Scalar* lhs_,
Index lhsStride,
116 const Scalar* rhs_,
Index rhsStride,
118 const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking)
123 Index depth = IsLower ? diagSize : _depth;
126 typedef const_blas_data_mapper<Scalar, Index, LhsStorageOrder> LhsMapper;
127 typedef const_blas_data_mapper<Scalar, Index, RhsStorageOrder> RhsMapper;
128 typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor, Unaligned, ResInnerStride> ResMapper;
129 LhsMapper lhs(lhs_,lhsStride);
130 RhsMapper rhs(rhs_,rhsStride);
131 ResMapper
res(res_, resStride, resIncr);
133 Index kc = blocking.kc();
140 std::size_t sizeA = kc*mc;
141 std::size_t sizeB = kc*
cols;
151 internal::constructor_without_unaligned_array_assert
a;
152 Matrix<Scalar,SmallPanelWidth,SmallPanelWidth,LhsStorageOrder> triangularBuffer(
a);
153 triangularBuffer.setZero();
155 triangularBuffer.diagonal().setZero();
157 triangularBuffer.diagonal().setOnes();
159 gebp_kernel<Scalar, Scalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp_kernel;
160 gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder> pack_lhs;
161 gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr,RhsStorageOrder> pack_rhs;
163 for(
Index k2=IsLower ? depth : 0;
164 IsLower ? k2>0 : k2<depth;
165 IsLower ? k2-=kc : k2+=kc)
168 Index actual_k2 = IsLower ? k2-actual_kc : k2;
171 if((!IsLower)&&(k2<
rows)&&(k2+actual_kc>
rows))
174 k2 = k2+actual_kc-kc;
177 pack_rhs(blockB, rhs.getSubMapper(actual_k2,0), actual_kc,
cols);
185 if(IsLower || actual_k2<
rows)
188 for (
Index k1=0; k1<actual_kc; k1+=panelWidth)
190 Index actualPanelWidth = std::min<Index>(actual_kc-k1, panelWidth);
191 Index lengthTarget = IsLower ? actual_kc-k1-actualPanelWidth : k1;
192 Index startBlock = actual_k2+k1;
193 Index blockBOffset = k1;
198 for (
Index k=0;k<actualPanelWidth;++k)
201 triangularBuffer.coeffRef(k,k) = lhs(startBlock+k,startBlock+k);
202 for (
Index i=IsLower ? k+1 : 0; IsLower ?
i<actualPanelWidth :
i<k; ++
i)
203 triangularBuffer.coeffRef(
i,k) = lhs(startBlock+
i,startBlock+k);
205 pack_lhs(blockA, LhsMapper(triangularBuffer.data(), triangularBuffer.outerStride()), actualPanelWidth, actualPanelWidth);
207 gebp_kernel(
res.getSubMapper(startBlock, 0), blockA, blockB,
208 actualPanelWidth, actualPanelWidth,
cols, alpha,
209 actualPanelWidth, actual_kc, 0, blockBOffset);
214 Index startTarget = IsLower ? actual_k2+k1+actualPanelWidth : actual_k2;
216 pack_lhs(blockA, lhs.getSubMapper(startTarget,startBlock), actualPanelWidth, lengthTarget);
218 gebp_kernel(
res.getSubMapper(startTarget, 0), blockA, blockB,
219 lengthTarget, actualPanelWidth,
cols, alpha,
220 actualPanelWidth, actual_kc, 0, blockBOffset);
226 Index start = IsLower ? k2 : 0;
231 gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr,Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder,false>()
232 (blockA, lhs.getSubMapper(i2, actual_k2), actual_kc, actual_mc);
234 gebp_kernel(
res.getSubMapper(i2, 0), blockA, blockB, actual_mc,
235 actual_kc,
cols, alpha, -1, -1, 0, 0);
242 template <
typename Scalar,
typename Index,
int Mode,
243 int LhsStorageOrder,
bool ConjugateLhs,
244 int RhsStorageOrder,
bool ConjugateRhs,
245 int ResInnerStride,
int Version>
246 struct product_triangular_matrix_matrix<Scalar,
Index,Mode,false,
247 LhsStorageOrder,ConjugateLhs,
248 RhsStorageOrder,ConjugateRhs,
ColMajor,ResInnerStride,Version>
250 typedef gebp_traits<Scalar,Scalar> Traits;
259 const Scalar* lhs_,
Index lhsStride,
260 const Scalar* rhs_,
Index rhsStride,
262 const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking);
265 template <
typename Scalar,
typename Index,
int Mode,
266 int LhsStorageOrder,
bool ConjugateLhs,
267 int RhsStorageOrder,
bool ConjugateRhs,
268 int ResInnerStride,
int Version>
270 LhsStorageOrder,ConjugateLhs,
271 RhsStorageOrder,ConjugateRhs,
ColMajor,ResInnerStride,Version>::run(
273 const Scalar* lhs_,
Index lhsStride,
274 const Scalar* rhs_,
Index rhsStride,
276 const Scalar& alpha, level3_blocking<Scalar,Scalar>& blocking)
282 Index depth = IsLower ? _depth : diagSize;
285 typedef const_blas_data_mapper<Scalar, Index, LhsStorageOrder> LhsMapper;
286 typedef const_blas_data_mapper<Scalar, Index, RhsStorageOrder> RhsMapper;
287 typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor, Unaligned, ResInnerStride> ResMapper;
288 LhsMapper lhs(lhs_,lhsStride);
289 RhsMapper rhs(rhs_,rhsStride);
290 ResMapper
res(res_, resStride, resIncr);
292 Index kc = blocking.kc();
295 std::size_t sizeA = kc*mc;
301 internal::constructor_without_unaligned_array_assert
a;
302 Matrix<Scalar,SmallPanelWidth,SmallPanelWidth,RhsStorageOrder> triangularBuffer(
a);
303 triangularBuffer.setZero();
305 triangularBuffer.diagonal().setZero();
307 triangularBuffer.diagonal().setOnes();
309 gebp_kernel<Scalar, Scalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp_kernel;
310 gemm_pack_lhs<Scalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, typename Traits::LhsPacket4Packing, LhsStorageOrder> pack_lhs;
311 gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr,RhsStorageOrder> pack_rhs;
312 gemm_pack_rhs<Scalar, Index, RhsMapper, Traits::nr,RhsStorageOrder,false,true> pack_rhs_panel;
314 for(
Index k2=IsLower ? 0 : depth;
315 IsLower ? k2<depth : k2>0;
316 IsLower ? k2+=kc : k2-=kc)
319 Index actual_k2 = IsLower ? k2 : k2-actual_kc;
322 if(IsLower && (k2<
cols) && (actual_k2+actual_kc>
cols))
325 k2 = actual_k2 + actual_kc - kc;
331 Index ts = (IsLower && actual_k2>=
cols) ? 0 : actual_kc;
333 Scalar* geb = blockB+ts*ts;
334 geb = geb + internal::first_aligned<PacketBytes>(geb,PacketBytes/
sizeof(Scalar));
336 pack_rhs(geb, rhs.getSubMapper(actual_k2,IsLower ? 0 : k2), actual_kc, rs);
341 for (
Index j2=0; j2<actual_kc; j2+=SmallPanelWidth)
343 Index actualPanelWidth = std::min<Index>(actual_kc-j2, SmallPanelWidth);
344 Index actual_j2 = actual_k2 + j2;
345 Index panelOffset = IsLower ? j2+actualPanelWidth : 0;
346 Index panelLength = IsLower ? actual_kc-j2-actualPanelWidth : j2;
348 pack_rhs_panel(blockB+j2*actual_kc,
349 rhs.getSubMapper(actual_k2+panelOffset, actual_j2),
350 panelLength, actualPanelWidth,
351 actual_kc, panelOffset);
354 for (
Index j=0;
j<actualPanelWidth;++
j)
357 triangularBuffer.coeffRef(
j,
j) = rhs(actual_j2+
j,actual_j2+
j);
358 for (
Index k=IsLower ?
j+1 : 0; IsLower ? k<actualPanelWidth : k<
j; ++k)
359 triangularBuffer.coeffRef(k,
j) = rhs(actual_j2+k,actual_j2+
j);
362 pack_rhs_panel(blockB+j2*actual_kc,
363 RhsMapper(triangularBuffer.data(), triangularBuffer.outerStride()),
364 actualPanelWidth, actualPanelWidth,
372 pack_lhs(blockA, lhs.getSubMapper(i2, actual_k2), actual_kc, actual_mc);
377 for (
Index j2=0; j2<actual_kc; j2+=SmallPanelWidth)
379 Index actualPanelWidth = std::min<Index>(actual_kc-j2, SmallPanelWidth);
380 Index panelLength = IsLower ? actual_kc-j2 : j2+actualPanelWidth;
381 Index blockOffset = IsLower ? j2 : 0;
383 gebp_kernel(
res.getSubMapper(i2, actual_k2 + j2),
384 blockA, blockB+j2*actual_kc,
385 actual_mc, panelLength, actualPanelWidth,
387 actual_kc, actual_kc,
388 blockOffset, blockOffset);
391 gebp_kernel(
res.getSubMapper(i2, IsLower ? 0 : k2),
392 blockA, geb, actual_mc, actual_kc, rs,
406 template<
int Mode,
bool LhsIsTriangular,
typename Lhs,
typename Rhs>
407 struct triangular_product_impl<Mode,LhsIsTriangular,Lhs,false,Rhs,false>
409 template<
typename Dest>
static void run(Dest& dst,
const Lhs &a_lhs,
const Rhs &a_rhs,
const typename Dest::Scalar& alpha)
411 typedef typename Lhs::Scalar LhsScalar;
412 typedef typename Rhs::Scalar RhsScalar;
413 typedef typename Dest::Scalar Scalar;
415 typedef internal::blas_traits<Lhs> LhsBlasTraits;
416 typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhsType;
417 typedef internal::remove_all_t<ActualLhsType> ActualLhsTypeCleaned;
418 typedef internal::blas_traits<Rhs> RhsBlasTraits;
419 typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhsType;
420 typedef internal::remove_all_t<ActualRhsType> ActualRhsTypeCleaned;
422 internal::add_const_on_value_type_t<ActualLhsType> lhs = LhsBlasTraits::extract(a_lhs);
423 internal::add_const_on_value_type_t<ActualRhsType> rhs = RhsBlasTraits::extract(a_rhs);
425 LhsScalar lhs_alpha = LhsBlasTraits::extractScalarFactor(a_lhs);
426 RhsScalar rhs_alpha = RhsBlasTraits::extractScalarFactor(a_rhs);
427 Scalar actualAlpha = alpha * lhs_alpha * rhs_alpha;
430 Lhs::MaxRowsAtCompileTime, Rhs::MaxColsAtCompileTime, Lhs::MaxColsAtCompileTime,4> BlockingType;
433 Index stripedRows = ((!LhsIsTriangular) || (IsLower)) ? lhs.rows() : (
std::min)(lhs.rows(),lhs.cols());
434 Index stripedCols = ((LhsIsTriangular) || (!IsLower)) ? rhs.cols() : (
std::min)(rhs.cols(),rhs.rows());
435 Index stripedDepth = LhsIsTriangular ? ((!IsLower) ? lhs.cols() : (
std::min)(lhs.cols(),lhs.rows()))
438 BlockingType blocking(stripedRows, stripedCols, stripedDepth, 1,
false);
440 internal::product_triangular_matrix_matrix<Scalar,
Index,
441 Mode, LhsIsTriangular,
446 stripedRows, stripedCols, stripedDepth,
447 &lhs.coeffRef(0,0), lhs.outerStride(),
448 &rhs.coeffRef(0,0), rhs.outerStride(),
449 &dst.coeffRef(0,0), dst.innerStride(), dst.outerStride(),
450 actualAlpha, blocking
459 dst.topRows(diagSize) -= ((lhs_alpha-LhsScalar(1))*a_rhs).topRows(diagSize);
464 dst.leftCols(diagSize) -= (rhs_alpha-RhsScalar(1))*a_lhs.leftCols(diagSize);
#define EIGEN_DONT_INLINE
#define ei_declare_aligned_stack_constructed_variable(TYPE, NAME, SIZE, BUFFER)
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
static const lastp1_t end
const unsigned int RowMajorBit
bfloat16() min(const bfloat16 &a, const bfloat16 &b)
constexpr int plain_enum_max(A a, B b)
bool is_exactly_one(const X &x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.