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 ScalarBinaryOpTraits<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,
46 const ResScalar& alpha, level3_blocking<RhsScalar,LhsScalar>& blocking)
48 general_matrix_matrix_triangular_product<
Index,
52 ::run(size,depth,rhs,rhsStride,lhs,lhsStride,res,resStride,alpha,blocking);
56 template <
typename Index,
typename LhsScalar,
int LhsStorageOrder,
bool ConjugateLhs,
57 typename RhsScalar,
int RhsStorageOrder,
bool ConjugateRhs,
int UpLo,
int Version>
58 struct general_matrix_matrix_triangular_product<Index,LhsScalar,LhsStorageOrder,ConjugateLhs,RhsScalar,RhsStorageOrder,ConjugateRhs,
ColMajor,UpLo,Version>
60 typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResScalar;
61 static EIGEN_STRONG_INLINE
void run(Index size, Index depth,
const LhsScalar* _lhs, Index lhsStride,
62 const RhsScalar* _rhs, Index rhsStride, ResScalar* _res, Index resStride,
63 const ResScalar& alpha, level3_blocking<LhsScalar,RhsScalar>& blocking)
65 typedef gebp_traits<LhsScalar,RhsScalar> Traits;
67 typedef const_blas_data_mapper<LhsScalar, Index, LhsStorageOrder> LhsMapper;
68 typedef const_blas_data_mapper<RhsScalar, Index, RhsStorageOrder> RhsMapper;
69 typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor> ResMapper;
70 LhsMapper lhs(_lhs,lhsStride);
71 RhsMapper rhs(_rhs,rhsStride);
72 ResMapper res(_res, resStride);
74 Index kc = blocking.kc();
75 Index mc = (std::min)(size,blocking.mc());
79 mc = (mc/Traits::nr)*Traits::nr;
81 std::size_t sizeA = kc*mc;
82 std::size_t sizeB = kc*size;
84 ei_declare_aligned_stack_constructed_variable(LhsScalar, blockA, sizeA, blocking.blockA());
85 ei_declare_aligned_stack_constructed_variable(RhsScalar, blockB, sizeB, blocking.blockB());
87 gemm_pack_lhs<LhsScalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, LhsStorageOrder> pack_lhs;
88 gemm_pack_rhs<RhsScalar, Index, RhsMapper, Traits::nr, RhsStorageOrder> pack_rhs;
89 gebp_kernel<LhsScalar, RhsScalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp;
90 tribb_kernel<LhsScalar, RhsScalar, Index, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs, UpLo> sybb;
92 for(Index k2=0; k2<depth; k2+=kc)
94 const Index actual_kc = (std::min)(k2+kc,depth)-k2;
97 pack_rhs(blockB, rhs.getSubMapper(k2,0), actual_kc, size);
99 for(Index i2=0; i2<size; i2+=mc)
101 const Index actual_mc = (std::min)(i2+mc,size)-i2;
103 pack_lhs(blockA, lhs.getSubMapper(i2, k2), actual_kc, actual_mc);
110 gebp(res.getSubMapper(i2, 0), blockA, blockB, actual_mc, actual_kc,
111 (std::min)(size,i2), alpha, -1, -1, 0, 0);
114 sybb(_res+resStride*i2 + i2, resStride, blockA, blockB + actual_kc*i2, actual_mc, actual_kc, alpha);
118 Index j2 = i2+actual_mc;
119 gebp(res.getSubMapper(i2, j2), blockA, blockB+actual_kc*j2, actual_mc,
120 actual_kc, (std::max)(
Index(0), size-j2), alpha, -1, -1, 0, 0);
136 template<
typename LhsScalar,
typename RhsScalar,
typename Index,
int mr,
int nr,
bool ConjLhs,
bool ConjRhs,
int UpLo>
139 typedef gebp_traits<LhsScalar,RhsScalar,ConjLhs,ConjRhs> Traits;
140 typedef typename Traits::ResScalar ResScalar;
143 BlockSize = meta_least_common_multiple<EIGEN_PLAIN_ENUM_MAX(mr,nr),EIGEN_PLAIN_ENUM_MIN(mr,nr)>::ret
145 void operator()(ResScalar* _res, Index resStride,
const LhsScalar* blockA,
const RhsScalar* blockB, Index size, Index depth,
const ResScalar& alpha)
147 typedef blas_data_mapper<ResScalar, Index, ColMajor> ResMapper;
148 ResMapper res(_res, resStride);
149 gebp_kernel<LhsScalar, RhsScalar, Index, ResMapper, mr, nr, ConjLhs, ConjRhs> gebp_kernel;
151 Matrix<ResScalar,BlockSize,BlockSize,ColMajor> buffer;
155 for (Index j=0; j<size; j+=BlockSize)
157 Index actualBlockSize = std::min<Index>(BlockSize,size - j);
158 const RhsScalar* actual_b = blockB+j*depth;
161 gebp_kernel(res.getSubMapper(0, j), blockA, actual_b, j, depth, actualBlockSize, alpha,
169 gebp_kernel(ResMapper(buffer.data(), BlockSize), blockA+depth*i, actual_b, actualBlockSize, depth, actualBlockSize, alpha,
172 for(Index j1=0; j1<actualBlockSize; ++j1)
174 ResScalar* r = &res(i, j + j1);
175 for(Index i1=UpLo==
Lower ? j1 : 0;
176 UpLo==
Lower ? i1<actualBlockSize : i1<=j1; ++i1)
177 r[i1] += buffer(i1,j1);
183 Index i = j+actualBlockSize;
184 gebp_kernel(res.getSubMapper(i, j), blockA+depth*i, actual_b, size-i,
185 depth, actualBlockSize, alpha, -1, -1, 0, 0);
195 template<
typename MatrixType,
typename ProductType,
int UpLo,
bool IsOuterProduct>
196 struct general_product_to_triangular_selector;
199 template<
typename MatrixType,
typename ProductType,
int UpLo>
200 struct general_product_to_triangular_selector<MatrixType,ProductType,UpLo,true>
202 static void run(MatrixType& mat,
const ProductType& prod,
const typename MatrixType::Scalar& alpha)
204 typedef typename MatrixType::Scalar Scalar;
206 typedef typename internal::remove_all<typename ProductType::LhsNested>::type Lhs;
207 typedef internal::blas_traits<Lhs> LhsBlasTraits;
208 typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhs;
209 typedef typename internal::remove_all<ActualLhs>::type _ActualLhs;
210 typename internal::add_const_on_value_type<ActualLhs>::type actualLhs = LhsBlasTraits::extract(prod.lhs());
212 typedef typename internal::remove_all<typename ProductType::RhsNested>::type Rhs;
213 typedef internal::blas_traits<Rhs> RhsBlasTraits;
214 typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhs;
215 typedef typename internal::remove_all<ActualRhs>::type _ActualRhs;
216 typename internal::add_const_on_value_type<ActualRhs>::type actualRhs = RhsBlasTraits::extract(prod.rhs());
218 Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(prod.lhs().derived()) * RhsBlasTraits::extractScalarFactor(prod.rhs().derived());
222 UseLhsDirectly = _ActualLhs::InnerStrideAtCompileTime==1,
223 UseRhsDirectly = _ActualRhs::InnerStrideAtCompileTime==1
226 internal::gemv_static_vector_if<Scalar,Lhs::SizeAtCompileTime,Lhs::MaxSizeAtCompileTime,!UseLhsDirectly> static_lhs;
227 ei_declare_aligned_stack_constructed_variable(Scalar, actualLhsPtr, actualLhs.size(),
228 (UseLhsDirectly ?
const_cast<Scalar*
>(actualLhs.data()) : static_lhs.data()));
229 if(!UseLhsDirectly) Map<typename _ActualLhs::PlainObject>(actualLhsPtr, actualLhs.size()) = actualLhs;
231 internal::gemv_static_vector_if<Scalar,Rhs::SizeAtCompileTime,Rhs::MaxSizeAtCompileTime,!UseRhsDirectly> static_rhs;
232 ei_declare_aligned_stack_constructed_variable(Scalar, actualRhsPtr, actualRhs.size(),
233 (UseRhsDirectly ?
const_cast<Scalar*
>(actualRhs.data()) : static_rhs.data()));
234 if(!UseRhsDirectly) Map<typename _ActualRhs::PlainObject>(actualRhsPtr, actualRhs.size()) = actualRhs;
237 selfadjoint_rank1_update<Scalar,
Index,StorageOrder,UpLo,
238 LhsBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex,
239 RhsBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex>
240 ::run(actualLhs.size(), mat.data(), mat.outerStride(), actualLhsPtr, actualRhsPtr, actualAlpha);
244 template<
typename MatrixType,
typename ProductType,
int UpLo>
245 struct general_product_to_triangular_selector<MatrixType,ProductType,UpLo,false>
247 static void run(MatrixType& mat,
const ProductType& prod,
const typename MatrixType::Scalar& alpha)
249 typedef typename internal::remove_all<typename ProductType::LhsNested>::type Lhs;
250 typedef internal::blas_traits<Lhs> LhsBlasTraits;
251 typedef typename LhsBlasTraits::DirectLinearAccessType ActualLhs;
252 typedef typename internal::remove_all<ActualLhs>::type _ActualLhs;
253 typename internal::add_const_on_value_type<ActualLhs>::type actualLhs = LhsBlasTraits::extract(prod.lhs());
255 typedef typename internal::remove_all<typename ProductType::RhsNested>::type Rhs;
256 typedef internal::blas_traits<Rhs> RhsBlasTraits;
257 typedef typename RhsBlasTraits::DirectLinearAccessType ActualRhs;
258 typedef typename internal::remove_all<ActualRhs>::type _ActualRhs;
259 typename internal::add_const_on_value_type<ActualRhs>::type actualRhs = RhsBlasTraits::extract(prod.rhs());
261 typename ProductType::Scalar actualAlpha = alpha * LhsBlasTraits::extractScalarFactor(prod.lhs().derived()) * RhsBlasTraits::extractScalarFactor(prod.rhs().derived());
264 IsRowMajor = (internal::traits<MatrixType>::Flags&
RowMajorBit) ? 1 : 0,
265 LhsIsRowMajor = _ActualLhs::Flags&
RowMajorBit ? 1 : 0,
266 RhsIsRowMajor = _ActualRhs::Flags&RowMajorBit ? 1 : 0
269 Index size = mat.cols();
270 Index depth = actualLhs.cols();
272 typedef internal::gemm_blocking_space<IsRowMajor ?
RowMajor :
ColMajor,
typename Lhs::Scalar,
typename Rhs::Scalar,
273 MatrixType::MaxColsAtCompileTime, MatrixType::MaxColsAtCompileTime, _ActualRhs::MaxColsAtCompileTime> BlockingType;
275 BlockingType blocking(size, size, depth, 1,
false);
277 internal::general_matrix_matrix_triangular_product<
Index,
278 typename Lhs::Scalar, LhsIsRowMajor ?
RowMajor :
ColMajor, LhsBlasTraits::NeedToConjugate,
279 typename Rhs::Scalar, RhsIsRowMajor ?
RowMajor :
ColMajor, RhsBlasTraits::NeedToConjugate,
282 &actualLhs.coeffRef(0,0), actualLhs.outerStride(), &actualRhs.coeffRef(0,0), actualRhs.outerStride(),
283 mat.data(), mat.outerStride(), actualAlpha, blocking);
287 template<
typename MatrixType,
unsigned int UpLo>
288 template<
typename ProductType>
289 TriangularView<MatrixType,UpLo>& TriangularViewImpl<MatrixType,UpLo,Dense>::_assignProduct(
const ProductType& prod,
const Scalar& alpha)
291 eigen_assert(derived().nestedExpression().rows() == prod.rows() && derived().cols() == prod.cols());
293 general_product_to_triangular_selector<MatrixType, ProductType, UpLo, internal::traits<ProductType>::InnerSize==1>::run(derived().nestedExpression().const_cast_derived(), prod, alpha);
300 #endif // EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_H Definition: Constants.h:320
Namespace containing all symbols from the Eigen library.
Definition: Core:287
const unsigned int RowMajorBit
Definition: Constants.h:61
Definition: Constants.h:204
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Definition: Constants.h:206
Definition: Eigen_Colamd.h:50
Definition: Constants.h:322