10#ifndef EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_H
11#define EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_H
15template<
typename Scalar,
typename Index,
int StorageOrder,
int UpLo,
bool ConjLhs,
bool ConjRhs>
16struct selfadjoint_rank1_update;
28template<
typename LhsScalar,
typename RhsScalar,
typename Index,
int mr,
int nr,
bool ConjLhs,
bool ConjRhs,
int ResInnerStr
ide,
int UpLo>
32template <
typename Index,
33 typename LhsScalar,
int LhsStorageOrder,
bool ConjugateLhs,
34 typename RhsScalar,
int RhsStorageOrder,
bool ConjugateRhs,
35 int ResStorageOrder,
int ResInnerStride,
int UpLo,
int Version = Specialized>
36struct general_matrix_matrix_triangular_product;
39template <
typename Index,
typename LhsScalar,
int LhsStorageOrder,
bool ConjugateLhs,
40 typename RhsScalar,
int RhsStorageOrder,
bool ConjugateRhs,
41 int ResInnerStride,
int UpLo,
int Version>
42struct general_matrix_matrix_triangular_product<
Index,LhsScalar,LhsStorageOrder,ConjugateLhs,RhsScalar,RhsStorageOrder,ConjugateRhs,
RowMajor,ResInnerStride,UpLo,Version>
44 typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar;
45 static EIGEN_STRONG_INLINE
void run(
Index size,
Index depth,
const LhsScalar* lhs,
Index lhsStride,
46 const RhsScalar* rhs,
Index rhsStride, ResScalar* res,
Index resIncr,
Index resStride,
47 const ResScalar& alpha, level3_blocking<RhsScalar,LhsScalar>& blocking)
49 general_matrix_matrix_triangular_product<
Index,
53 ::run(size,depth,rhs,rhsStride,lhs,lhsStride,res,resIncr,resStride,alpha,blocking);
57template <
typename Index,
typename LhsScalar,
int LhsStorageOrder,
bool ConjugateLhs,
58 typename RhsScalar,
int RhsStorageOrder,
bool ConjugateRhs,
59 int ResInnerStride,
int UpLo,
int Version>
60struct general_matrix_matrix_triangular_product<
Index,LhsScalar,LhsStorageOrder,ConjugateLhs,RhsScalar,RhsStorageOrder,ConjugateRhs,
ColMajor,ResInnerStride,UpLo,Version>
62 typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar;
63 static EIGEN_STRONG_INLINE
void run(
Index size,
Index depth,
const LhsScalar* _lhs,
Index lhsStride,
64 const RhsScalar* _rhs,
Index rhsStride,
65 ResScalar* _res,
Index resIncr,
Index resStride,
66 const ResScalar& alpha, level3_blocking<LhsScalar,RhsScalar>& blocking)
68 typedef gebp_traits<LhsScalar,RhsScalar> Traits;
70 typedef const_blas_data_mapper<LhsScalar, Index, LhsStorageOrder> LhsMapper;
71 typedef const_blas_data_mapper<RhsScalar, Index, RhsStorageOrder> RhsMapper;
72 typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor, Unaligned, ResInnerStride> ResMapper;
73 LhsMapper lhs(_lhs,lhsStride);
74 RhsMapper rhs(_rhs,rhsStride);
75 ResMapper res(_res, resStride, resIncr);
77 Index kc = blocking.kc();
78 Index mc = (std::min)(size,blocking.mc());
82 mc = (mc/Traits::nr)*Traits::nr;
84 std::size_t sizeA = kc*mc;
85 std::size_t sizeB = kc*size;
87 ei_declare_aligned_stack_constructed_variable(LhsScalar, blockA, sizeA, blocking.blockA());
88 ei_declare_aligned_stack_constructed_variable(RhsScalar, blockB, sizeB, blocking.blockB());
90 gemm_pack_lhs<LhsScalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, LhsStorageOrder> pack_lhs;
91 gemm_pack_rhs<RhsScalar, Index, RhsMapper, Traits::nr, RhsStorageOrder> pack_rhs;
92 gebp_kernel<LhsScalar, RhsScalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp;
93 tribb_kernel<LhsScalar, RhsScalar, Index, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs, ResInnerStride, UpLo> sybb;
95 for(
Index k2=0; k2<depth; k2+=kc)
97 const Index actual_kc = (std::min)(k2+kc,depth)-k2;
100 pack_rhs(blockB, rhs.getSubMapper(k2,0), actual_kc, size);
102 for(
Index i2=0; i2<size; i2+=mc)
104 const Index actual_mc = (std::min)(i2+mc,size)-i2;
106 pack_lhs(blockA, lhs.getSubMapper(i2, k2), actual_kc, actual_mc);
113 gebp(res.getSubMapper(i2, 0), blockA, blockB, actual_mc, actual_kc,
114 (std::min)(size,i2), alpha, -1, -1, 0, 0);
116 sybb(_res+resStride*i2 + resIncr*i2, resIncr, resStride, blockA, blockB + actual_kc*i2, actual_mc, actual_kc, alpha);
120 Index j2 = i2+actual_mc;
121 gebp(res.getSubMapper(i2, j2), blockA, blockB+actual_kc*j2, actual_mc,
122 actual_kc, (std::max)(
Index(0), size-j2), alpha, -1, -1, 0, 0);
138template<
typename LhsScalar,
typename RhsScalar,
typename Index,
int mr,
int nr,
bool ConjLhs,
bool ConjRhs,
int ResInnerStr
ide,
int UpLo>
141 typedef gebp_traits<LhsScalar,RhsScalar,ConjLhs,ConjRhs> Traits;
142 typedef typename Traits::ResScalar ResScalar;
145 BlockSize = meta_least_common_multiple<EIGEN_PLAIN_ENUM_MAX(mr,nr),EIGEN_PLAIN_ENUM_MIN(mr,nr)>::ret
147 void operator()(ResScalar* _res,
Index resIncr,
Index resStride,
const LhsScalar* blockA,
const RhsScalar* blockB,
Index size,
Index depth,
const ResScalar& alpha)
149 typedef blas_data_mapper<ResScalar, Index, ColMajor, Unaligned, ResInnerStride> ResMapper;
150 typedef blas_data_mapper<ResScalar, Index, ColMajor, Unaligned> BufferMapper;
151 ResMapper res(_res, resStride, resIncr);
152 gebp_kernel<LhsScalar, RhsScalar, Index, ResMapper, mr, nr, ConjLhs, ConjRhs> gebp_kernel1;
153 gebp_kernel<LhsScalar, RhsScalar, Index, BufferMapper, mr, nr, ConjLhs, ConjRhs> gebp_kernel2;
155 Matrix<ResScalar,BlockSize,BlockSize,ColMajor> buffer((internal::constructor_without_unaligned_array_assert()));
159 for (
Index j=0; j<size; j+=BlockSize)
161 Index actualBlockSize = std::min<Index>(BlockSize,size - j);
162 const RhsScalar* actual_b = blockB+j*depth;
165 gebp_kernel1(res.getSubMapper(0, j), blockA, actual_b, j, depth, actualBlockSize, alpha,
173 gebp_kernel2(BufferMapper(buffer.data(), BlockSize), blockA+depth*i, actual_b, actualBlockSize, depth, actualBlockSize, alpha,
177 for(
Index j1=0; j1<actualBlockSize; ++j1)
179 typename ResMapper::LinearMapper r = res.getLinearMapper(i,j+j1);
181 UpLo==
Lower ? i1<actualBlockSize : i1<=j1; ++i1)
182 r(i1) += buffer(i1,j1);
188 Index i = j+actualBlockSize;
189 gebp_kernel1(res.getSubMapper(i, j), blockA+depth*i, actual_b, size-i,
190 depth, actualBlockSize, alpha, -1, -1, 0, 0);
200template<
typename MatrixType,
typename ProductType,
int UpLo,
bool IsOuterProduct>
201struct general_product_to_triangular_selector;
204template<
typename MatrixType,
typename ProductType,
int UpLo>
205struct general_product_to_triangular_selector<
MatrixType,ProductType,UpLo,true>
207 static void run(MatrixType& mat,
const ProductType& prod,
const typename MatrixType::Scalar& alpha,
bool beta)
209 typedef typename MatrixType::Scalar Scalar;
211 typedef typename internal::remove_all<typename ProductType::LhsNested>::type Lhs;
212 typedef internal::blas_traits<Lhs> LhsBlasTraits;
213 typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhs;
214 typedef typename internal::remove_all<ActualLhs>::type _ActualLhs;
215 typename internal::add_const_on_value_type<ActualLhs>::type actualLhs = LhsBlasTraits::extract(prod.lhs());
217 typedef typename internal::remove_all<typename ProductType::RhsNested>::type Rhs;
218 typedef internal::blas_traits<Rhs> RhsBlasTraits;
219 typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhs;
220 typedef typename internal::remove_all<ActualRhs>::type _ActualRhs;
221 typename internal::add_const_on_value_type<ActualRhs>::type actualRhs = RhsBlasTraits::extract(prod.rhs());
223 Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(prod.lhs().derived()) * RhsBlasTraits::extractScalarFactor(prod.rhs().derived());
226 mat.template triangularView<UpLo>().setZero();
230 UseLhsDirectly = _ActualLhs::InnerStrideAtCompileTime==1,
231 UseRhsDirectly = _ActualRhs::InnerStrideAtCompileTime==1
234 internal::gemv_static_vector_if<Scalar,Lhs::SizeAtCompileTime,Lhs::MaxSizeAtCompileTime,!UseLhsDirectly> static_lhs;
235 ei_declare_aligned_stack_constructed_variable(Scalar, actualLhsPtr, actualLhs.size(),
236 (UseLhsDirectly ?
const_cast<Scalar*
>(actualLhs.data()) : static_lhs.data()));
237 if(!UseLhsDirectly) Map<typename _ActualLhs::PlainObject>(actualLhsPtr, actualLhs.size()) = actualLhs;
239 internal::gemv_static_vector_if<Scalar,Rhs::SizeAtCompileTime,Rhs::MaxSizeAtCompileTime,!UseRhsDirectly> static_rhs;
240 ei_declare_aligned_stack_constructed_variable(Scalar, actualRhsPtr, actualRhs.size(),
241 (UseRhsDirectly ?
const_cast<Scalar*
>(actualRhs.data()) : static_rhs.data()));
242 if(!UseRhsDirectly) Map<typename _ActualRhs::PlainObject>(actualRhsPtr, actualRhs.size()) = actualRhs;
245 selfadjoint_rank1_update<Scalar,
Index,StorageOrder,UpLo,
246 LhsBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex,
247 RhsBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex>
248 ::run(actualLhs.size(), mat.data(), mat.outerStride(), actualLhsPtr, actualRhsPtr, actualAlpha);
252template<
typename MatrixType,
typename ProductType,
int UpLo>
253struct general_product_to_triangular_selector<MatrixType,ProductType,UpLo,false>
255 static void run(MatrixType& mat,
const ProductType& prod,
const typename MatrixType::Scalar& alpha,
bool beta)
257 typedef typename internal::remove_all<typename ProductType::LhsNested>::type Lhs;
258 typedef internal::blas_traits<Lhs> LhsBlasTraits;
259 typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhs;
260 typedef typename internal::remove_all<ActualLhs>::type _ActualLhs;
261 typename internal::add_const_on_value_type<ActualLhs>::type actualLhs = LhsBlasTraits::extract(prod.lhs());
263 typedef typename internal::remove_all<typename ProductType::RhsNested>::type Rhs;
264 typedef internal::blas_traits<Rhs> RhsBlasTraits;
265 typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhs;
266 typedef typename internal::remove_all<ActualRhs>::type _ActualRhs;
267 typename internal::add_const_on_value_type<ActualRhs>::type actualRhs = RhsBlasTraits::extract(prod.rhs());
269 typename ProductType::Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(prod.lhs().derived()) * RhsBlasTraits::extractScalarFactor(prod.rhs().derived());
272 mat.template triangularView<UpLo>().setZero();
275 IsRowMajor = (internal::traits<MatrixType>::Flags&
RowMajorBit) ? 1 : 0,
276 LhsIsRowMajor = _ActualLhs::Flags&
RowMajorBit ? 1 : 0,
277 RhsIsRowMajor = _ActualRhs::Flags&
RowMajorBit ? 1 : 0,
281 Index size = mat.cols();
284 Index depth = actualLhs.cols();
286 typedef internal::gemm_blocking_space<IsRowMajor ?
RowMajor :
ColMajor,
typename Lhs::Scalar,
typename Rhs::Scalar,
287 MatrixType::MaxColsAtCompileTime, MatrixType::MaxColsAtCompileTime, _ActualRhs::MaxColsAtCompileTime> BlockingType;
289 BlockingType blocking(size, size, depth, 1,
false);
291 internal::general_matrix_matrix_triangular_product<
Index,
292 typename Lhs::Scalar, LhsIsRowMajor ?
RowMajor :
ColMajor, LhsBlasTraits::NeedToConjugate,
293 typename Rhs::Scalar, RhsIsRowMajor ?
RowMajor :
ColMajor, RhsBlasTraits::NeedToConjugate,
296 &actualLhs.coeffRef(SkipDiag&&(UpLo&Lower)==Lower ? 1 : 0,0), actualLhs.outerStride(),
297 &actualRhs.coeffRef(0,SkipDiag&&(UpLo&Upper)==Upper ? 1 : 0), actualRhs.outerStride(),
298 mat.data() + (SkipDiag ? (
bool(IsRowMajor) != ((UpLo&Lower)==Lower) ? mat.innerStride() : mat.outerStride() ) : 0),
299 mat.innerStride(), mat.outerStride(), actualAlpha, blocking);
303template<
typename _MatrixType,
unsigned int _Mode>
304template<
typename ProductType>
305EIGEN_DEVICE_FUNC TriangularView<_MatrixType,_Mode>& TriangularViewImpl<_MatrixType,_Mode,Dense>::_assignProduct(
const ProductType& prod,
const Scalar& alpha,
bool beta)
307 EIGEN_STATIC_ASSERT((_Mode&UnitDiag)==0, WRITING_TO_TRIANGULAR_PART_WITH_UNIT_DIAGONAL_IS_NOT_SUPPORTED);
308 eigen_assert(derived().nestedExpression().rows() == prod.rows() && derived().cols() == prod.cols());
310 general_product_to_triangular_selector<_MatrixType, ProductType, _Mode, internal::traits<ProductType>::InnerSize==1>::run(derived().nestedExpression().const_cast_derived(), prod, alpha, beta);
@ UnitDiag
Definition Constants.h:208
@ ZeroDiag
Definition Constants.h:210
@ Lower
Definition Constants.h:204
@ Upper
Definition Constants.h:206
@ ColMajor
Definition Constants.h:320
@ RowMajor
Definition Constants.h:322
const unsigned int RowMajorBit
Definition Constants.h:61
Namespace containing all symbols from the Eigen library.
Definition A05_PortingFrom2To3.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:65