10 #ifndef EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_H
11 #define EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_H
15 template<
typename Scalar,
typename Index,
int StorageOrder,
int UpLo,
bool ConjLhs,
bool ConjRhs>
16 struct selfadjoint_rank1_update;
28 template<
typename LhsScalar,
typename RhsScalar,
typename Index,
int mr,
int nr,
bool ConjLhs,
bool ConjRhs,
int UpLo>
32 template <
typename Index,
33 typename LhsScalar,
int LhsStorageOrder,
bool ConjugateLhs,
34 typename RhsScalar,
int RhsStorageOrder,
bool ConjugateRhs,
35 int ResStorageOrder,
int UpLo,
int Version = Specialized>
36 struct general_matrix_matrix_triangular_product;
39 template <
typename Index,
typename LhsScalar,
int LhsStorageOrder,
bool ConjugateLhs,
40 typename RhsScalar,
int RhsStorageOrder,
bool ConjugateRhs,
int UpLo,
int Version>
41 struct general_matrix_matrix_triangular_product<Index,LhsScalar,LhsStorageOrder,ConjugateLhs,RhsScalar,RhsStorageOrder,ConjugateRhs,
RowMajor,UpLo,Version>
43 typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType ResScalar;
44 static EIGEN_STRONG_INLINE
void run(Index size, Index depth,
const LhsScalar* lhs, Index lhsStride,
45 const RhsScalar* rhs, Index rhsStride, ResScalar* res, Index resStride,
const ResScalar& alpha)
47 general_matrix_matrix_triangular_product<Index,
51 ::run(size,depth,rhs,rhsStride,lhs,lhsStride,res,resStride,alpha);
55 template <
typename Index,
typename LhsScalar,
int LhsStorageOrder,
bool ConjugateLhs,
56 typename RhsScalar,
int RhsStorageOrder,
bool ConjugateRhs,
int UpLo,
int Version>
57 struct general_matrix_matrix_triangular_product<Index,LhsScalar,LhsStorageOrder,ConjugateLhs,RhsScalar,RhsStorageOrder,ConjugateRhs,
ColMajor,UpLo,Version>
59 typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType ResScalar;
60 static EIGEN_STRONG_INLINE
void run(Index size, Index depth,
const LhsScalar* _lhs, Index lhsStride,
61 const RhsScalar* _rhs, Index rhsStride, ResScalar* res, Index resStride,
const ResScalar& alpha)
63 const_blas_data_mapper<LhsScalar, Index, LhsStorageOrder> lhs(_lhs,lhsStride);
64 const_blas_data_mapper<RhsScalar, Index, RhsStorageOrder> rhs(_rhs,rhsStride);
66 typedef gebp_traits<LhsScalar,RhsScalar> Traits;
71 computeProductBlockingSizes<LhsScalar,RhsScalar>(kc, mc, nc);
74 mc = (mc/Traits::nr)*Traits::nr;
76 std::size_t sizeW = kc*Traits::WorkSpaceFactor;
77 std::size_t sizeB = sizeW + kc*size;
78 ei_declare_aligned_stack_constructed_variable(LhsScalar, blockA, kc*mc, 0);
79 ei_declare_aligned_stack_constructed_variable(RhsScalar, allocatedBlockB, sizeB, 0);
80 RhsScalar* blockB = allocatedBlockB + sizeW;
82 gemm_pack_lhs<LhsScalar, Index, Traits::mr, Traits::LhsProgress, LhsStorageOrder> pack_lhs;
83 gemm_pack_rhs<RhsScalar, Index, Traits::nr, RhsStorageOrder> pack_rhs;
84 gebp_kernel <LhsScalar, RhsScalar, Index, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp;
85 tribb_kernel<LhsScalar, RhsScalar, Index, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs, UpLo> sybb;
87 for(Index k2=0; k2<depth; k2+=kc)
89 const Index actual_kc = (std::min)(k2+kc,depth)-k2;
92 pack_rhs(blockB, &rhs(k2,0), rhsStride, actual_kc, size);
94 for(Index i2=0; i2<size; i2+=mc)
96 const Index actual_mc = (std::min)(i2+mc,size)-i2;
98 pack_lhs(blockA, &lhs(i2, k2), lhsStride, actual_kc, actual_mc);
105 gebp(res+i2, resStride, blockA, blockB, actual_mc, actual_kc, (std::min)(size,i2), alpha,
106 -1, -1, 0, 0, allocatedBlockB);
108 sybb(res+resStride*i2 + i2, resStride, blockA, blockB + actual_kc*i2, actual_mc, actual_kc, alpha, allocatedBlockB);
112 Index j2 = i2+actual_mc;
113 gebp(res+resStride*j2+i2, resStride, blockA, blockB+actual_kc*j2, actual_mc, actual_kc, (std::max)(Index(0), size-j2), alpha,
114 -1, -1, 0, 0, allocatedBlockB);
130 template<
typename LhsScalar,
typename RhsScalar,
typename Index,
int mr,
int nr,
bool ConjLhs,
bool ConjRhs,
int UpLo>
133 typedef gebp_traits<LhsScalar,RhsScalar,ConjLhs,ConjRhs> Traits;
134 typedef typename Traits::ResScalar ResScalar;
137 BlockSize = EIGEN_PLAIN_ENUM_MAX(mr,nr)
139 void operator()(ResScalar* res, Index resStride,
const LhsScalar* blockA,
const RhsScalar* blockB, Index size, Index depth,
const ResScalar& alpha, RhsScalar* workspace)
141 gebp_kernel<LhsScalar, RhsScalar, Index, mr, nr, ConjLhs, ConjRhs> gebp_kernel;
142 Matrix<ResScalar,BlockSize,BlockSize,ColMajor> buffer;
146 for (Index j=0; j<size; j+=BlockSize)
148 Index actualBlockSize = std::min<Index>(BlockSize,size - j);
149 const RhsScalar* actual_b = blockB+j*depth;
152 gebp_kernel(res+j*resStride, resStride, blockA, actual_b, j, depth, actualBlockSize, alpha,
153 -1, -1, 0, 0, workspace);
160 gebp_kernel(buffer.data(), BlockSize, blockA+depth*i, actual_b, actualBlockSize, depth, actualBlockSize, alpha,
161 -1, -1, 0, 0, workspace);
163 for(Index j1=0; j1<actualBlockSize; ++j1)
165 ResScalar* r = res + (j+j1)*resStride + i;
166 for(Index i1=UpLo==
Lower ? j1 : 0;
167 UpLo==
Lower ? i1<actualBlockSize : i1<=j1; ++i1)
168 r[i1] += buffer(i1,j1);
174 Index i = j+actualBlockSize;
175 gebp_kernel(res+j*resStride+i, resStride, blockA+depth*i, actual_b, size-i, depth, actualBlockSize, alpha,
176 -1, -1, 0, 0, workspace);
186 template<
typename MatrixType,
typename ProductType,
int UpLo,
bool IsOuterProduct>
187 struct general_product_to_triangular_selector;
190 template<
typename MatrixType,
typename ProductType,
int UpLo>
191 struct general_product_to_triangular_selector<MatrixType,ProductType,UpLo,true>
193 static void run(MatrixType& mat,
const ProductType& prod,
const typename MatrixType::Scalar& alpha)
195 typedef typename MatrixType::Scalar Scalar;
196 typedef typename MatrixType::Index Index;
198 typedef typename internal::remove_all<typename ProductType::LhsNested>::type Lhs;
199 typedef internal::blas_traits<Lhs> LhsBlasTraits;
200 typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhs;
201 typedef typename internal::remove_all<ActualLhs>::type _ActualLhs;
202 typename internal::add_const_on_value_type<ActualLhs>::type actualLhs = LhsBlasTraits::extract(prod.lhs());
204 typedef typename internal::remove_all<typename ProductType::RhsNested>::type Rhs;
205 typedef internal::blas_traits<Rhs> RhsBlasTraits;
206 typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhs;
207 typedef typename internal::remove_all<ActualRhs>::type _ActualRhs;
208 typename internal::add_const_on_value_type<ActualRhs>::type actualRhs = RhsBlasTraits::extract(prod.rhs());
210 Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(prod.lhs().derived()) * RhsBlasTraits::extractScalarFactor(prod.rhs().derived());
214 UseLhsDirectly = _ActualLhs::InnerStrideAtCompileTime==1,
215 UseRhsDirectly = _ActualRhs::InnerStrideAtCompileTime==1
218 internal::gemv_static_vector_if<Scalar,Lhs::SizeAtCompileTime,Lhs::MaxSizeAtCompileTime,!UseLhsDirectly> static_lhs;
219 ei_declare_aligned_stack_constructed_variable(Scalar, actualLhsPtr, actualLhs.size(),
220 (UseLhsDirectly ?
const_cast<Scalar*
>(actualLhs.data()) : static_lhs.data()));
221 if(!UseLhsDirectly) Map<typename _ActualLhs::PlainObject>(actualLhsPtr, actualLhs.size()) = actualLhs;
223 internal::gemv_static_vector_if<Scalar,Rhs::SizeAtCompileTime,Rhs::MaxSizeAtCompileTime,!UseRhsDirectly> static_rhs;
224 ei_declare_aligned_stack_constructed_variable(Scalar, actualRhsPtr, actualRhs.size(),
225 (UseRhsDirectly ?
const_cast<Scalar*
>(actualRhs.data()) : static_rhs.data()));
226 if(!UseRhsDirectly) Map<typename _ActualRhs::PlainObject>(actualRhsPtr, actualRhs.size()) = actualRhs;
229 selfadjoint_rank1_update<Scalar,Index,StorageOrder,UpLo,
230 LhsBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex,
231 RhsBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex>
232 ::run(actualLhs.size(), mat.data(), mat.outerStride(), actualLhsPtr, actualRhsPtr, actualAlpha);
236 template<
typename MatrixType,
typename ProductType,
int UpLo>
237 struct general_product_to_triangular_selector<MatrixType,ProductType,UpLo,false>
239 static void run(MatrixType& mat,
const ProductType& prod,
const typename MatrixType::Scalar& alpha)
241 typedef typename MatrixType::Index Index;
243 typedef typename internal::remove_all<typename ProductType::LhsNested>::type Lhs;
244 typedef internal::blas_traits<Lhs> LhsBlasTraits;
245 typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhs;
246 typedef typename internal::remove_all<ActualLhs>::type _ActualLhs;
247 typename internal::add_const_on_value_type<ActualLhs>::type actualLhs = LhsBlasTraits::extract(prod.lhs());
249 typedef typename internal::remove_all<typename ProductType::RhsNested>::type Rhs;
250 typedef internal::blas_traits<Rhs> RhsBlasTraits;
251 typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhs;
252 typedef typename internal::remove_all<ActualRhs>::type _ActualRhs;
253 typename internal::add_const_on_value_type<ActualRhs>::type actualRhs = RhsBlasTraits::extract(prod.rhs());
255 typename ProductType::Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(prod.lhs().derived()) * RhsBlasTraits::extractScalarFactor(prod.rhs().derived());
257 internal::general_matrix_matrix_triangular_product<Index,
261 ::run(mat.cols(), actualLhs.cols(),
262 &actualLhs.coeffRef(0,0), actualLhs.outerStride(), &actualRhs.coeffRef(0,0), actualRhs.outerStride(),
263 mat.data(), mat.outerStride(), actualAlpha);
267 template<
typename MatrixType,
unsigned int UpLo>
268 template<
typename ProductDerived,
typename _Lhs,
typename _Rhs>
269 TriangularView<MatrixType,UpLo>& TriangularView<MatrixType,UpLo>::assignProduct(
const ProductBase<ProductDerived, _Lhs,_Rhs>& prod,
const Scalar& alpha)
271 general_product_to_triangular_selector<MatrixType, ProductDerived, UpLo, (_Lhs::ColsAtCompileTime==1) || (_Rhs::RowsAtCompileTime==1)>::run(m_matrix.const_cast_derived(), prod.derived(), alpha);
278 #endif // EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_H
Definition: Constants.h:167
Definition: Constants.h:264
Definition: Constants.h:169
Definition: Constants.h:266
const unsigned int RowMajorBit
Definition: Constants.h:53