13 #ifndef EIGEN_PRODUCTEVALUATORS_H 14 #define EIGEN_PRODUCTEVALUATORS_H 28 template<
typename Lhs,
typename Rhs,
int Options>
29 struct evaluator<Product<Lhs, Rhs, Options> >
30 :
public product_evaluator<Product<Lhs, Rhs, Options> >
32 typedef Product<Lhs, Rhs, Options> XprType;
33 typedef product_evaluator<XprType> Base;
35 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
explicit evaluator(
const XprType& xpr) : Base(xpr) {}
40 template<
typename Lhs,
typename Rhs,
typename Scalar1,
typename Scalar2,
typename Plain1>
41 struct evaluator_assume_aliasing<CwiseBinaryOp<
internal::scalar_product_op<Scalar1,Scalar2>,
42 const CwiseNullaryOp<internal::scalar_constant_op<Scalar1>, Plain1>,
43 const Product<Lhs, Rhs, DefaultProduct> > >
45 static const bool value =
true;
47 template<
typename Lhs,
typename Rhs,
typename Scalar1,
typename Scalar2,
typename Plain1>
48 struct evaluator<CwiseBinaryOp<
internal::scalar_product_op<Scalar1,Scalar2>,
49 const CwiseNullaryOp<internal::scalar_constant_op<Scalar1>, Plain1>,
50 const Product<Lhs, Rhs, DefaultProduct> > >
51 :
public evaluator<Product<EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar1,Lhs,product), Rhs, DefaultProduct> >
53 typedef CwiseBinaryOp<internal::scalar_product_op<Scalar1,Scalar2>,
54 const CwiseNullaryOp<internal::scalar_constant_op<Scalar1>, Plain1>,
55 const Product<Lhs, Rhs, DefaultProduct> > XprType;
56 typedef evaluator<Product<EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar1,Lhs,product), Rhs, DefaultProduct> > Base;
58 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
explicit evaluator(
const XprType& xpr)
59 : Base(xpr.lhs().functor().m_other * xpr.rhs().lhs() * xpr.rhs().rhs())
64 template<
typename Lhs,
typename Rhs,
int DiagIndex>
65 struct evaluator<Diagonal<const Product<Lhs, Rhs, DefaultProduct>, DiagIndex> >
66 :
public evaluator<Diagonal<const Product<Lhs, Rhs, LazyProduct>, DiagIndex> >
68 typedef Diagonal<const Product<Lhs, Rhs, DefaultProduct>, DiagIndex> XprType;
69 typedef evaluator<Diagonal<const Product<Lhs, Rhs, LazyProduct>, DiagIndex> > Base;
71 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
explicit evaluator(
const XprType& xpr)
72 : Base(Diagonal<const Product<Lhs, Rhs, LazyProduct>, DiagIndex>(
73 Product<Lhs, Rhs, LazyProduct>(xpr.nestedExpression().lhs(), xpr.nestedExpression().rhs()),
82 template<
typename Lhs,
typename Rhs,
83 typename LhsShape =
typename evaluator_traits<Lhs>::Shape,
84 typename RhsShape =
typename evaluator_traits<Rhs>::Shape,
85 int ProductType = internal::product_type<Lhs,Rhs>::value>
86 struct generic_product_impl;
88 template<
typename Lhs,
typename Rhs>
89 struct evaluator_assume_aliasing<Product<Lhs, Rhs, DefaultProduct> > {
90 static const bool value =
true;
95 template<
typename Lhs,
typename Rhs,
int Options,
int ProductTag,
typename LhsShape,
typename RhsShape>
96 struct product_evaluator<Product<Lhs, Rhs, Options>, ProductTag, LhsShape, RhsShape>
97 :
public evaluator<typename Product<Lhs, Rhs, Options>::PlainObject>
99 typedef Product<Lhs, Rhs, Options> XprType;
100 typedef typename XprType::PlainObject PlainObject;
101 typedef evaluator<PlainObject> Base;
106 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
107 explicit product_evaluator(
const XprType& xpr)
108 : m_result(xpr.rows(), xpr.cols())
110 ::new (static_cast<Base*>(
this)) Base(m_result);
124 generic_product_impl<Lhs, Rhs, LhsShape, RhsShape, ProductTag>::evalTo(m_result, xpr.lhs(), xpr.rhs());
128 PlainObject m_result;
135 template< typename DstXprType, typename Lhs, typename Rhs,
int Options, typename Scalar>
136 struct Assignment<DstXprType, Product<Lhs,Rhs,Options>,
internal::assign_op<Scalar,Scalar>, Dense2Dense,
137 typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct)>::type>
139 typedef Product<Lhs,Rhs,Options> SrcXprType;
140 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
141 void run(DstXprType &dst,
const SrcXprType &src,
const internal::assign_op<Scalar,Scalar> &)
143 Index dstRows = src.rows();
144 Index dstCols = src.cols();
145 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
146 dst.resize(dstRows, dstCols);
148 generic_product_impl<Lhs, Rhs>::evalTo(dst, src.lhs(), src.rhs());
153 template<
typename DstXprType,
typename Lhs,
typename Rhs,
int Options,
typename Scalar>
154 struct Assignment<DstXprType, Product<Lhs,Rhs,Options>,
internal::add_assign_op<Scalar,Scalar>, Dense2Dense,
155 typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct)>::type>
157 typedef Product<Lhs,Rhs,Options> SrcXprType;
158 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
159 void run(DstXprType &dst,
const SrcXprType &src,
const internal::add_assign_op<Scalar,Scalar> &)
161 eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
163 generic_product_impl<Lhs, Rhs>::addTo(dst, src.lhs(), src.rhs());
168 template<
typename DstXprType,
typename Lhs,
typename Rhs,
int Options,
typename Scalar>
169 struct Assignment<DstXprType, Product<Lhs,Rhs,Options>,
internal::sub_assign_op<Scalar,Scalar>, Dense2Dense,
170 typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct)>::type>
172 typedef Product<Lhs,Rhs,Options> SrcXprType;
173 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
174 void run(DstXprType &dst,
const SrcXprType &src,
const internal::sub_assign_op<Scalar,Scalar> &)
176 eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
178 generic_product_impl<Lhs, Rhs>::subTo(dst, src.lhs(), src.rhs());
186 template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename AssignFunc,
typename Scalar,
typename ScalarBis,
typename Plain>
187 struct Assignment<DstXprType, CwiseBinaryOp<
internal::scalar_product_op<ScalarBis,Scalar>, const CwiseNullaryOp<internal::scalar_constant_op<ScalarBis>,Plain>,
188 const Product<Lhs,Rhs,DefaultProduct> >, AssignFunc, Dense2Dense>
190 typedef CwiseBinaryOp<internal::scalar_product_op<ScalarBis,Scalar>,
191 const CwiseNullaryOp<internal::scalar_constant_op<ScalarBis>,Plain>,
192 const Product<Lhs,Rhs,DefaultProduct> > SrcXprType;
193 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
194 void run(DstXprType &dst,
const SrcXprType &src,
const AssignFunc& func)
196 call_assignment_no_alias(dst, (src.lhs().functor().m_other * src.rhs().lhs())*src.rhs().rhs(), func);
204 template<
typename OtherXpr,
typename Lhs,
typename Rhs>
205 struct evaluator_assume_aliasing<CwiseBinaryOp<
internal::scalar_sum_op<typename OtherXpr::Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, const OtherXpr,
206 const Product<Lhs,Rhs,DefaultProduct> >, DenseShape > {
207 static const bool value =
true;
210 template<
typename OtherXpr,
typename Lhs,
typename Rhs>
211 struct evaluator_assume_aliasing<CwiseBinaryOp<
internal::scalar_difference_op<typename OtherXpr::Scalar,typename Product<Lhs,Rhs,DefaultProduct>::Scalar>, const OtherXpr,
212 const Product<Lhs,Rhs,DefaultProduct> >, DenseShape > {
213 static const bool value =
true;
216 template<
typename DstXprType,
typename OtherXpr,
typename ProductType,
typename Func1,
typename Func2>
217 struct assignment_from_xpr_op_product
219 template<
typename SrcXprType,
typename InitialFunc>
220 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
221 void run(DstXprType &dst,
const SrcXprType &src,
const InitialFunc& )
223 call_assignment_no_alias(dst, src.lhs(), Func1());
224 call_assignment_no_alias(dst, src.rhs(), Func2());
228 #define EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(ASSIGN_OP,BINOP,ASSIGN_OP2) \ 229 template< typename DstXprType, typename OtherXpr, typename Lhs, typename Rhs, typename DstScalar, typename SrcScalar, typename OtherScalar,typename ProdScalar> \ 230 struct Assignment<DstXprType, CwiseBinaryOp<internal::BINOP<OtherScalar,ProdScalar>, const OtherXpr, \ 231 const Product<Lhs,Rhs,DefaultProduct> >, internal::ASSIGN_OP<DstScalar,SrcScalar>, Dense2Dense> \ 232 : assignment_from_xpr_op_product<DstXprType, OtherXpr, Product<Lhs,Rhs,DefaultProduct>, internal::ASSIGN_OP<DstScalar,OtherScalar>, internal::ASSIGN_OP2<DstScalar,ProdScalar> > \ 235 EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(assign_op, scalar_sum_op,add_assign_op);
236 EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(add_assign_op,scalar_sum_op,add_assign_op);
237 EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(sub_assign_op,scalar_sum_op,sub_assign_op);
239 EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(assign_op, scalar_difference_op,sub_assign_op);
240 EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(add_assign_op,scalar_difference_op,sub_assign_op);
241 EIGEN_CATCH_ASSIGN_XPR_OP_PRODUCT(sub_assign_op,scalar_difference_op,add_assign_op);
245 template<
typename Lhs,
typename Rhs>
246 struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,InnerProduct>
248 template<
typename Dst>
249 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs)
251 dst.coeffRef(0,0) = (lhs.transpose().cwiseProduct(rhs)).sum();
254 template<
typename Dst>
255 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void addTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs)
257 dst.coeffRef(0,0) += (lhs.transpose().cwiseProduct(rhs)).sum();
260 template<
typename Dst>
261 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void subTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs)
262 { dst.coeffRef(0,0) -= (lhs.transpose().cwiseProduct(rhs)).sum(); }
271 template<
typename Dst,
typename Lhs,
typename Rhs,
typename Func>
272 void EIGEN_DEVICE_FUNC outer_product_selector_run(Dst& dst,
const Lhs &lhs,
const Rhs &rhs,
const Func& func,
const false_type&)
274 evaluator<Rhs> rhsEval(rhs);
275 ei_declare_local_nested_eval(Lhs,lhs,Rhs::SizeAtCompileTime,actual_lhs);
278 const Index cols = dst.cols();
279 for (
Index j=0; j<cols; ++j)
280 func(dst.col(j), rhsEval.coeff(
Index(0),j) * actual_lhs);
284 template<
typename Dst,
typename Lhs,
typename Rhs,
typename Func>
285 void EIGEN_DEVICE_FUNC outer_product_selector_run(Dst& dst,
const Lhs &lhs,
const Rhs &rhs,
const Func& func,
const true_type&)
287 evaluator<Lhs> lhsEval(lhs);
288 ei_declare_local_nested_eval(Rhs,rhs,Lhs::SizeAtCompileTime,actual_rhs);
291 const Index rows = dst.rows();
292 for (
Index i=0; i<rows; ++i)
293 func(dst.row(i), lhsEval.coeff(i,
Index(0)) * actual_rhs);
296 template<
typename Lhs,
typename Rhs>
297 struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,OuterProduct>
299 template<
typename T>
struct is_row_major : internal::conditional<(int(T::Flags)&RowMajorBit), internal::true_type, internal::false_type>::type {};
300 typedef typename Product<Lhs,Rhs>::Scalar Scalar;
303 struct set {
template<
typename Dst,
typename Src> EIGEN_DEVICE_FUNC
void operator()(
const Dst& dst,
const Src& src)
const { dst.const_cast_derived() = src; } };
304 struct add {
template<
typename Dst,
typename Src> EIGEN_DEVICE_FUNC
void operator()(
const Dst& dst,
const Src& src)
const { dst.const_cast_derived() += src; } };
305 struct sub {
template<
typename Dst,
typename Src> EIGEN_DEVICE_FUNC
void operator()(
const Dst& dst,
const Src& src)
const { dst.const_cast_derived() -= src; } };
308 explicit adds(
const Scalar& s) : m_scale(s) {}
309 template<
typename Dst,
typename Src>
void EIGEN_DEVICE_FUNC operator()(
const Dst& dst,
const Src& src)
const {
310 dst.const_cast_derived() += m_scale * src;
314 template<
typename Dst>
315 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs)
317 internal::outer_product_selector_run(dst, lhs, rhs,
set(), is_row_major<Dst>());
320 template<
typename Dst>
321 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void addTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs)
323 internal::outer_product_selector_run(dst, lhs, rhs, add(), is_row_major<Dst>());
326 template<
typename Dst>
327 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void subTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs)
329 internal::outer_product_selector_run(dst, lhs, rhs, sub(), is_row_major<Dst>());
332 template<
typename Dst>
333 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void scaleAndAddTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
335 internal::outer_product_selector_run(dst, lhs, rhs, adds(alpha), is_row_major<Dst>());
342 template<
typename Lhs,
typename Rhs,
typename Derived>
343 struct generic_product_impl_base
345 typedef typename Product<Lhs,Rhs>::Scalar Scalar;
347 template<
typename Dst>
348 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs)
349 { dst.setZero(); scaleAndAddTo(dst, lhs, rhs, Scalar(1)); }
351 template<
typename Dst>
352 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void addTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs)
353 { scaleAndAddTo(dst,lhs, rhs, Scalar(1)); }
355 template<
typename Dst>
356 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void subTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs)
357 { scaleAndAddTo(dst, lhs, rhs, Scalar(-1)); }
359 template<
typename Dst>
360 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void scaleAndAddTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
361 { Derived::scaleAndAddTo(dst,lhs,rhs,alpha); }
365 template<
typename Lhs,
typename Rhs>
366 struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemvProduct>
367 : generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemvProduct> >
369 typedef typename nested_eval<Lhs,1>::type LhsNested;
370 typedef typename nested_eval<Rhs,1>::type RhsNested;
371 typedef typename Product<Lhs,Rhs>::Scalar Scalar;
373 typedef typename internal::remove_all<typename internal::conditional<int(Side)==OnTheRight,LhsNested,RhsNested>::type>::type MatrixType;
375 template<
typename Dest>
376 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void scaleAndAddTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
379 if (lhs.rows() == 1 && rhs.cols() == 1) {
380 dst.coeffRef(0,0) += alpha * lhs.row(0).conjugate().dot(rhs.col(0));
383 LhsNested actual_lhs(lhs);
384 RhsNested actual_rhs(rhs);
385 internal::gemv_dense_selector<Side,
387 bool(internal::blas_traits<MatrixType>::HasUsableDirectAccess)
388 >::run(actual_lhs, actual_rhs, dst, alpha);
392 template<
typename Lhs,
typename Rhs>
393 struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,CoeffBasedProductMode>
395 typedef typename Product<Lhs,Rhs>::Scalar Scalar;
397 template<
typename Dst>
398 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs)
402 call_assignment_no_alias(dst, lhs.lazyProduct(rhs), internal::assign_op<typename Dst::Scalar,Scalar>());
405 template<
typename Dst>
406 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void addTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs)
409 call_assignment_no_alias(dst, lhs.lazyProduct(rhs), internal::add_assign_op<typename Dst::Scalar,Scalar>());
412 template<
typename Dst>
413 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void subTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs)
416 call_assignment_no_alias(dst, lhs.lazyProduct(rhs), internal::sub_assign_op<typename Dst::Scalar,Scalar>());
433 template<
typename Dst,
typename Func>
434 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
435 void eval_dynamic(Dst& dst,
const Lhs& lhs,
const Rhs& rhs,
const Func &func)
438 HasScalarFactor = blas_traits<Lhs>::HasScalarFactor || blas_traits<Rhs>::HasScalarFactor,
439 ConjLhs = blas_traits<Lhs>::NeedToConjugate,
440 ConjRhs = blas_traits<Rhs>::NeedToConjugate
444 Scalar actualAlpha = combine_scalar_factors<Scalar>(lhs, rhs);
446 eval_dynamic_impl(dst,
447 blas_traits<Lhs>::extract(lhs).
template conjugateIf<ConjLhs>(),
448 blas_traits<Rhs>::extract(rhs).
template conjugateIf<ConjRhs>(),
451 typename conditional<HasScalarFactor,true_type,false_type>::type());
456 template<
typename Dst,
typename LhsT,
typename RhsT,
typename Func,
typename Scalar>
457 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
458 void eval_dynamic_impl(Dst& dst,
const LhsT& lhs,
const RhsT& rhs,
const Func &func,
const Scalar& s , false_type)
460 EIGEN_UNUSED_VARIABLE(s);
461 eigen_internal_assert(s==Scalar(1));
462 call_restricted_packet_assignment_no_alias(dst, lhs.lazyProduct(rhs), func);
465 template<
typename Dst,
typename LhsT,
typename RhsT,
typename Func,
typename Scalar>
466 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
467 void eval_dynamic_impl(Dst& dst,
const LhsT& lhs,
const RhsT& rhs,
const Func &func,
const Scalar& s, true_type)
469 call_restricted_packet_assignment_no_alias(dst, s * lhs.lazyProduct(rhs), func);
474 template<
typename Lhs,
typename Rhs>
475 struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,LazyCoeffBasedProductMode>
476 : generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,CoeffBasedProductMode> {};
484 template<
int Traversal,
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename RetScalar>
485 struct etor_product_coeff_impl;
487 template<
int StorageOrder,
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
488 struct etor_product_packet_impl;
490 template<
typename Lhs,
typename Rhs,
int ProductTag>
491 struct product_evaluator<Product<Lhs, Rhs, LazyProduct>, ProductTag, DenseShape, DenseShape>
492 : evaluator_base<Product<Lhs, Rhs, LazyProduct> >
494 typedef Product<Lhs, Rhs, LazyProduct> XprType;
495 typedef typename XprType::Scalar Scalar;
496 typedef typename XprType::CoeffReturnType CoeffReturnType;
498 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
499 explicit product_evaluator(
const XprType& xpr)
505 m_innerDim(xpr.lhs().cols())
507 EIGEN_INTERNAL_CHECK_COST_VALUE(NumTraits<Scalar>::MulCost);
508 EIGEN_INTERNAL_CHECK_COST_VALUE(NumTraits<Scalar>::AddCost);
509 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
511 std::cerr <<
"LhsOuterStrideBytes= " << LhsOuterStrideBytes <<
"\n";
512 std::cerr <<
"RhsOuterStrideBytes= " << RhsOuterStrideBytes <<
"\n";
513 std::cerr <<
"LhsAlignment= " << LhsAlignment <<
"\n";
514 std::cerr <<
"RhsAlignment= " << RhsAlignment <<
"\n";
515 std::cerr <<
"CanVectorizeLhs= " << CanVectorizeLhs <<
"\n";
516 std::cerr <<
"CanVectorizeRhs= " << CanVectorizeRhs <<
"\n";
517 std::cerr <<
"CanVectorizeInner= " << CanVectorizeInner <<
"\n";
518 std::cerr <<
"EvalToRowMajor= " << EvalToRowMajor <<
"\n";
519 std::cerr <<
"Alignment= " << Alignment <<
"\n";
520 std::cerr <<
"Flags= " << Flags <<
"\n";
526 typedef typename internal::nested_eval<Lhs,Rhs::ColsAtCompileTime>::type LhsNested;
527 typedef typename internal::nested_eval<Rhs,Lhs::RowsAtCompileTime>::type RhsNested;
529 typedef typename internal::remove_all<LhsNested>::type LhsNestedCleaned;
530 typedef typename internal::remove_all<RhsNested>::type RhsNestedCleaned;
532 typedef evaluator<LhsNestedCleaned> LhsEtorType;
533 typedef evaluator<RhsNestedCleaned> RhsEtorType;
536 RowsAtCompileTime = LhsNestedCleaned::RowsAtCompileTime,
537 ColsAtCompileTime = RhsNestedCleaned::ColsAtCompileTime,
538 InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(LhsNestedCleaned::ColsAtCompileTime, RhsNestedCleaned::RowsAtCompileTime),
539 MaxRowsAtCompileTime = LhsNestedCleaned::MaxRowsAtCompileTime,
540 MaxColsAtCompileTime = RhsNestedCleaned::MaxColsAtCompileTime
543 typedef typename find_best_packet<Scalar,RowsAtCompileTime>::type LhsVecPacketType;
544 typedef typename find_best_packet<Scalar,ColsAtCompileTime>::type RhsVecPacketType;
548 LhsCoeffReadCost = LhsEtorType::CoeffReadCost,
549 RhsCoeffReadCost = RhsEtorType::CoeffReadCost,
550 CoeffReadCost = InnerSize==0 ? NumTraits<Scalar>::ReadCost
552 : InnerSize * (NumTraits<Scalar>::MulCost + int(LhsCoeffReadCost) + int(RhsCoeffReadCost))
553 + (InnerSize - 1) * NumTraits<Scalar>::AddCost,
555 Unroll = CoeffReadCost <= EIGEN_UNROLLING_LIMIT,
557 LhsFlags = LhsEtorType::Flags,
558 RhsFlags = RhsEtorType::Flags,
563 LhsVecPacketSize = unpacket_traits<LhsVecPacketType>::size,
564 RhsVecPacketSize = unpacket_traits<RhsVecPacketType>::size,
567 LhsAlignment = EIGEN_PLAIN_ENUM_MIN(LhsEtorType::Alignment,LhsVecPacketSize*
int(
sizeof(
typename LhsNestedCleaned::Scalar))),
568 RhsAlignment = EIGEN_PLAIN_ENUM_MIN(RhsEtorType::Alignment,RhsVecPacketSize*
int(
sizeof(
typename RhsNestedCleaned::Scalar))),
570 SameType = is_same<typename LhsNestedCleaned::Scalar,typename RhsNestedCleaned::Scalar>::value,
572 CanVectorizeRhs = bool(RhsRowMajor) && (RhsFlags &
PacketAccessBit) && (ColsAtCompileTime!=1),
573 CanVectorizeLhs = (!LhsRowMajor) && (LhsFlags &
PacketAccessBit) && (RowsAtCompileTime!=1),
575 EvalToRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
576 : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
577 : (
bool(RhsRowMajor) && !CanVectorizeLhs),
579 Flags = ((
int(LhsFlags) | int(RhsFlags)) & HereditaryBits & ~RowMajorBit)
582 | (SameType && (CanVectorizeLhs || CanVectorizeRhs) ?
PacketAccessBit : 0)
585 LhsOuterStrideBytes = int(LhsNestedCleaned::OuterStrideAtCompileTime) * int(
sizeof(
typename LhsNestedCleaned::Scalar)),
586 RhsOuterStrideBytes = int(RhsNestedCleaned::OuterStrideAtCompileTime) * int(
sizeof(
typename RhsNestedCleaned::Scalar)),
588 Alignment = bool(CanVectorizeLhs) ? (LhsOuterStrideBytes<=0 || (int(LhsOuterStrideBytes) % EIGEN_PLAIN_ENUM_MAX(1,LhsAlignment))!=0 ? 0 : LhsAlignment)
589 : bool(CanVectorizeRhs) ? (RhsOuterStrideBytes<=0 || (int(RhsOuterStrideBytes) % EIGEN_PLAIN_ENUM_MAX(1,RhsAlignment))!=0 ? 0 : RhsAlignment)
597 CanVectorizeInner = SameType
601 && (
int(InnerSize) % packet_traits<Scalar>::size == 0)
604 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const CoeffReturnType coeff(
Index row,
Index col)
const 606 return (m_lhs.row(row).transpose().cwiseProduct( m_rhs.col(col) )).sum();
613 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
614 const CoeffReturnType coeff(
Index index)
const 616 const Index row = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime==1) ? 0 : index;
617 const Index col = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime==1) ? index : 0;
618 return (m_lhs.row(row).transpose().cwiseProduct( m_rhs.col(col) )).sum();
621 template<
int LoadMode,
typename PacketType>
622 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
623 const PacketType packet(
Index row,
Index col)
const 626 typedef etor_product_packet_impl<bool(
int(Flags)&RowMajorBit) ?
RowMajor :
ColMajor,
627 Unroll ? int(InnerSize) :
Dynamic,
628 LhsEtorType, RhsEtorType, PacketType, LoadMode> PacketImpl;
629 PacketImpl::run(row, col, m_lhsImpl, m_rhsImpl, m_innerDim, res);
633 template<
int LoadMode,
typename PacketType>
634 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
635 const PacketType packet(
Index index)
const 637 const Index row = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime==1) ? 0 : index;
638 const Index col = (RowsAtCompileTime == 1 || MaxRowsAtCompileTime==1) ? index : 0;
639 return packet<LoadMode,PacketType>(row,col);
643 typename internal::add_const_on_value_type<LhsNested>::type m_lhs;
644 typename internal::add_const_on_value_type<RhsNested>::type m_rhs;
646 LhsEtorType m_lhsImpl;
647 RhsEtorType m_rhsImpl;
653 template<
typename Lhs,
typename Rhs>
654 struct product_evaluator<Product<Lhs, Rhs, DefaultProduct>, LazyCoeffBasedProductMode, DenseShape, DenseShape>
655 : product_evaluator<Product<Lhs, Rhs, LazyProduct>, CoeffBasedProductMode, DenseShape, DenseShape>
657 typedef Product<Lhs, Rhs, DefaultProduct> XprType;
658 typedef Product<Lhs, Rhs, LazyProduct> BaseProduct;
659 typedef product_evaluator<BaseProduct, CoeffBasedProductMode, DenseShape, DenseShape> Base;
663 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
664 explicit product_evaluator(
const XprType& xpr)
665 : Base(BaseProduct(xpr.lhs(),xpr.rhs()))
673 template<
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
674 struct etor_product_packet_impl<
RowMajor, UnrollingIndex, Lhs, Rhs, Packet, LoadMode>
676 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(
Index row,
Index col,
const Lhs& lhs,
const Rhs& rhs,
Index innerDim, Packet &res)
678 etor_product_packet_impl<RowMajor, UnrollingIndex-1, Lhs, Rhs, Packet, LoadMode>::run(row, col, lhs, rhs, innerDim, res);
679 res = pmadd(pset1<Packet>(lhs.coeff(row,
Index(UnrollingIndex-1))), rhs.template packet<LoadMode,Packet>(
Index(UnrollingIndex-1), col), res);
683 template<
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
684 struct etor_product_packet_impl<
ColMajor, UnrollingIndex, Lhs, Rhs, Packet, LoadMode>
686 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(
Index row,
Index col,
const Lhs& lhs,
const Rhs& rhs,
Index innerDim, Packet &res)
688 etor_product_packet_impl<ColMajor, UnrollingIndex-1, Lhs, Rhs, Packet, LoadMode>::run(row, col, lhs, rhs, innerDim, res);
689 res = pmadd(lhs.template packet<LoadMode,Packet>(row,
Index(UnrollingIndex-1)), pset1<Packet>(rhs.coeff(
Index(UnrollingIndex-1), col)), res);
693 template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
694 struct etor_product_packet_impl<
RowMajor, 1, Lhs, Rhs, Packet, LoadMode>
696 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(
Index row,
Index col,
const Lhs& lhs,
const Rhs& rhs,
Index , Packet &res)
698 res = pmul(pset1<Packet>(lhs.coeff(row,
Index(0))),rhs.template packet<LoadMode,Packet>(
Index(0), col));
702 template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
703 struct etor_product_packet_impl<
ColMajor, 1, Lhs, Rhs, Packet, LoadMode>
705 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(
Index row,
Index col,
const Lhs& lhs,
const Rhs& rhs,
Index , Packet &res)
707 res = pmul(lhs.template packet<LoadMode,Packet>(row,
Index(0)), pset1<Packet>(rhs.coeff(
Index(0), col)));
711 template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
712 struct etor_product_packet_impl<
RowMajor, 0, Lhs, Rhs, Packet, LoadMode>
714 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(
Index ,
Index ,
const Lhs& ,
const Rhs& ,
Index , Packet &res)
716 res = pset1<Packet>(
typename unpacket_traits<Packet>::type(0));
720 template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
721 struct etor_product_packet_impl<
ColMajor, 0, Lhs, Rhs, Packet, LoadMode>
723 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(
Index ,
Index ,
const Lhs& ,
const Rhs& ,
Index , Packet &res)
725 res = pset1<Packet>(
typename unpacket_traits<Packet>::type(0));
729 template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
730 struct etor_product_packet_impl<
RowMajor,
Dynamic, Lhs, Rhs, Packet, LoadMode>
732 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(
Index row,
Index col,
const Lhs& lhs,
const Rhs& rhs,
Index innerDim, Packet& res)
734 res = pset1<Packet>(
typename unpacket_traits<Packet>::type(0));
735 for(
Index i = 0; i < innerDim; ++i)
736 res = pmadd(pset1<Packet>(lhs.coeff(row, i)), rhs.template packet<LoadMode,Packet>(i, col), res);
740 template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
741 struct etor_product_packet_impl<
ColMajor,
Dynamic, Lhs, Rhs, Packet, LoadMode>
743 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(
Index row,
Index col,
const Lhs& lhs,
const Rhs& rhs,
Index innerDim, Packet& res)
745 res = pset1<Packet>(
typename unpacket_traits<Packet>::type(0));
746 for(
Index i = 0; i < innerDim; ++i)
747 res = pmadd(lhs.template packet<LoadMode,Packet>(row, i), pset1<Packet>(rhs.coeff(i, col)), res);
755 template<
int Mode,
bool LhsIsTriangular,
756 typename Lhs,
bool LhsIsVector,
757 typename Rhs,
bool RhsIsVector>
758 struct triangular_product_impl;
760 template<
typename Lhs,
typename Rhs,
int ProductTag>
761 struct generic_product_impl<Lhs,Rhs,TriangularShape,DenseShape,ProductTag>
762 : generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,TriangularShape,DenseShape,ProductTag> >
764 typedef typename Product<Lhs,Rhs>::Scalar Scalar;
766 template<
typename Dest>
767 static void scaleAndAddTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
769 triangular_product_impl<Lhs::Mode,true,typename Lhs::MatrixType,false,Rhs, Rhs::ColsAtCompileTime==1>
770 ::run(dst, lhs.nestedExpression(), rhs, alpha);
774 template<
typename Lhs,
typename Rhs,
int ProductTag>
775 struct generic_product_impl<Lhs,Rhs,DenseShape,TriangularShape,ProductTag>
776 : generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,DenseShape,TriangularShape,ProductTag> >
778 typedef typename Product<Lhs,Rhs>::Scalar Scalar;
780 template<
typename Dest>
781 static void scaleAndAddTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
783 triangular_product_impl<Rhs::Mode,false,Lhs,Lhs::RowsAtCompileTime==1, typename Rhs::MatrixType, false>::run(dst, lhs, rhs.nestedExpression(), alpha);
791 template <
typename Lhs,
int LhsMode,
bool LhsIsVector,
792 typename Rhs,
int RhsMode,
bool RhsIsVector>
793 struct selfadjoint_product_impl;
795 template<
typename Lhs,
typename Rhs,
int ProductTag>
796 struct generic_product_impl<Lhs,Rhs,SelfAdjointShape,DenseShape,ProductTag>
797 : generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,SelfAdjointShape,DenseShape,ProductTag> >
799 typedef typename Product<Lhs,Rhs>::Scalar Scalar;
801 template<
typename Dest>
802 static EIGEN_DEVICE_FUNC
803 void scaleAndAddTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
805 selfadjoint_product_impl<typename Lhs::MatrixType,Lhs::Mode,false,Rhs,0,Rhs::IsVectorAtCompileTime>::run(dst, lhs.nestedExpression(), rhs, alpha);
809 template<
typename Lhs,
typename Rhs,
int ProductTag>
810 struct generic_product_impl<Lhs,Rhs,DenseShape,SelfAdjointShape,ProductTag>
811 : generic_product_impl_base<Lhs,Rhs,generic_product_impl<Lhs,Rhs,DenseShape,SelfAdjointShape,ProductTag> >
813 typedef typename Product<Lhs,Rhs>::Scalar Scalar;
815 template<
typename Dest>
816 static void scaleAndAddTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
818 selfadjoint_product_impl<Lhs,0,Lhs::IsVectorAtCompileTime,typename Rhs::MatrixType,Rhs::Mode,false>::run(dst, lhs, rhs.nestedExpression(), alpha);
827 template<
typename MatrixType,
typename DiagonalType,
typename Derived,
int ProductOrder>
828 struct diagonal_product_evaluator_base
829 : evaluator_base<Derived>
831 typedef typename ScalarBinaryOpTraits<typename MatrixType::Scalar, typename DiagonalType::Scalar>::ReturnType Scalar;
834 CoeffReadCost = int(NumTraits<Scalar>::MulCost) + int(evaluator<MatrixType>::CoeffReadCost) + int(evaluator<DiagonalType>::CoeffReadCost),
836 MatrixFlags = evaluator<MatrixType>::Flags,
837 DiagFlags = evaluator<DiagonalType>::Flags,
839 _StorageOrder = (Derived::MaxRowsAtCompileTime==1 && Derived::MaxColsAtCompileTime!=1) ?
RowMajor 840 : (Derived::MaxColsAtCompileTime==1 && Derived::MaxRowsAtCompileTime!=1) ?
ColMajor 842 _SameStorageOrder = _StorageOrder == (MatrixFlags & RowMajorBit ?
RowMajor :
ColMajor),
844 _ScalarAccessOnDiag = !((
int(_StorageOrder) ==
ColMajor && int(ProductOrder) ==
OnTheLeft)
846 _SameTypes = is_same<typename MatrixType::Scalar, typename DiagonalType::Scalar>::value,
849 _Vectorizable = bool(
int(MatrixFlags)&PacketAccessBit)
851 && (_SameStorageOrder || (MatrixFlags&
LinearAccessBit)==LinearAccessBit)
852 && (_ScalarAccessOnDiag || (bool(
int(DiagFlags)&PacketAccessBit))),
853 _LinearAccessMask = (MatrixType::RowsAtCompileTime==1 || MatrixType::ColsAtCompileTime==1) ? LinearAccessBit : 0,
854 Flags = ((HereditaryBits|_LinearAccessMask) & (
unsigned int)(MatrixFlags)) | (_Vectorizable ? PacketAccessBit : 0),
855 Alignment = evaluator<MatrixType>::Alignment,
857 AsScalarProduct = (DiagonalType::SizeAtCompileTime==1)
858 || (DiagonalType::SizeAtCompileTime==
Dynamic && MatrixType::RowsAtCompileTime==1 && ProductOrder==
OnTheLeft)
859 || (DiagonalType::SizeAtCompileTime==
Dynamic && MatrixType::ColsAtCompileTime==1 && ProductOrder==
OnTheRight)
862 EIGEN_DEVICE_FUNC diagonal_product_evaluator_base(
const MatrixType &mat,
const DiagonalType &diag)
863 : m_diagImpl(diag), m_matImpl(mat)
865 EIGEN_INTERNAL_CHECK_COST_VALUE(NumTraits<Scalar>::MulCost);
866 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
869 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar coeff(
Index idx)
const 872 return m_diagImpl.coeff(0) * m_matImpl.coeff(idx);
874 return m_diagImpl.coeff(idx) * m_matImpl.coeff(idx);
878 template<
int LoadMode,
typename PacketType>
879 EIGEN_STRONG_INLINE PacketType packet_impl(
Index row,
Index col,
Index id, internal::true_type)
const 881 return internal::pmul(m_matImpl.template packet<LoadMode,PacketType>(row, col),
882 internal::pset1<PacketType>(m_diagImpl.coeff(
id)));
885 template<
int LoadMode,
typename PacketType>
886 EIGEN_STRONG_INLINE PacketType packet_impl(
Index row,
Index col,
Index id, internal::false_type)
const 889 InnerSize = (MatrixType::Flags &
RowMajorBit) ? MatrixType::ColsAtCompileTime : MatrixType::RowsAtCompileTime,
890 DiagonalPacketLoadMode = EIGEN_PLAIN_ENUM_MIN(LoadMode,((InnerSize%16) == 0) ? int(
Aligned16) : int(evaluator<DiagonalType>::Alignment))
892 return internal::pmul(m_matImpl.template packet<LoadMode,PacketType>(row, col),
893 m_diagImpl.template packet<DiagonalPacketLoadMode,PacketType>(
id));
896 evaluator<DiagonalType> m_diagImpl;
897 evaluator<MatrixType> m_matImpl;
901 template<
typename Lhs,
typename Rhs,
int ProductKind,
int ProductTag>
902 struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DiagonalShape, DenseShape>
903 : diagonal_product_evaluator_base<Rhs, typename Lhs::DiagonalVectorType, Product<Lhs, Rhs, LazyProduct>, OnTheLeft>
905 typedef diagonal_product_evaluator_base<Rhs, typename Lhs::DiagonalVectorType, Product<Lhs, Rhs, LazyProduct>,
OnTheLeft> Base;
906 using Base::m_diagImpl;
907 using Base::m_matImpl;
909 typedef typename Base::Scalar Scalar;
911 typedef Product<Lhs, Rhs, ProductKind> XprType;
912 typedef typename XprType::PlainObject PlainObject;
913 typedef typename Lhs::DiagonalVectorType DiagonalType;
916 enum { StorageOrder = Base::_StorageOrder };
918 EIGEN_DEVICE_FUNC
explicit product_evaluator(
const XprType& xpr)
919 : Base(xpr.rhs(), xpr.lhs().diagonal())
923 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar coeff(
Index row,
Index col)
const 925 return m_diagImpl.coeff(row) * m_matImpl.coeff(row, col);
929 template<
int LoadMode,
typename PacketType>
930 EIGEN_STRONG_INLINE PacketType packet(
Index row,
Index col)
const 934 return this->
template packet_impl<LoadMode,PacketType>(row,col, row,
935 typename internal::conditional<int(StorageOrder)==RowMajor, internal::true_type, internal::false_type>::type());
938 template<
int LoadMode,
typename PacketType>
939 EIGEN_STRONG_INLINE PacketType packet(
Index idx)
const 941 return packet<LoadMode,PacketType>(int(StorageOrder)==
ColMajor?idx:0,int(StorageOrder)==
ColMajor?0:idx);
947 template<
typename Lhs,
typename Rhs,
int ProductKind,
int ProductTag>
948 struct product_evaluator<Product<Lhs, Rhs, ProductKind>, ProductTag, DenseShape, DiagonalShape>
949 : diagonal_product_evaluator_base<Lhs, typename Rhs::DiagonalVectorType, Product<Lhs, Rhs, LazyProduct>,
OnTheRight>
951 typedef diagonal_product_evaluator_base<Lhs, typename Rhs::DiagonalVectorType, Product<Lhs, Rhs, LazyProduct>,
OnTheRight> Base;
952 using Base::m_diagImpl;
953 using Base::m_matImpl;
955 typedef typename Base::Scalar Scalar;
957 typedef Product<Lhs, Rhs, ProductKind> XprType;
958 typedef typename XprType::PlainObject PlainObject;
960 enum { StorageOrder = Base::_StorageOrder };
962 EIGEN_DEVICE_FUNC
explicit product_evaluator(
const XprType& xpr)
963 : Base(xpr.lhs(), xpr.rhs().diagonal())
967 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar coeff(
Index row,
Index col)
const 969 return m_matImpl.coeff(row, col) * m_diagImpl.coeff(col);
973 template<
int LoadMode,
typename PacketType>
974 EIGEN_STRONG_INLINE PacketType packet(
Index row,
Index col)
const 976 return this->
template packet_impl<LoadMode,PacketType>(row,col, col,
977 typename internal::conditional<int(StorageOrder)==ColMajor, internal::true_type, internal::false_type>::type());
980 template<
int LoadMode,
typename PacketType>
981 EIGEN_STRONG_INLINE PacketType packet(
Index idx)
const 983 return packet<LoadMode,PacketType>(int(StorageOrder)==
ColMajor?idx:0,int(StorageOrder)==
ColMajor?0:idx);
997 template<
typename ExpressionType,
int S
ide,
bool Transposed,
typename ExpressionShape>
998 struct permutation_matrix_product;
1000 template<
typename ExpressionType,
int S
ide,
bool Transposed>
1001 struct permutation_matrix_product<ExpressionType, Side, Transposed, DenseShape>
1003 typedef typename nested_eval<ExpressionType, 1>::type MatrixType;
1004 typedef typename remove_all<MatrixType>::type MatrixTypeCleaned;
1006 template<
typename Dest,
typename PermutationType>
1007 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(Dest& dst,
const PermutationType& perm,
const ExpressionType& xpr)
1009 MatrixType mat(xpr);
1014 if(is_same_dense(dst, mat))
1017 Matrix<bool,PermutationType::RowsAtCompileTime,1,0,PermutationType::MaxRowsAtCompileTime> mask(perm.size());
1020 while(r < perm.size())
1023 while(r<perm.size() && mask[r]) r++;
1029 mask.coeffRef(k0) =
true;
1030 for(
Index k=perm.indices().coeff(k0); k!=k0; k=perm.indices().coeff(k))
1032 Block<Dest, Side==OnTheLeft ? 1 : Dest::RowsAtCompileTime, Side==OnTheRight ? 1 : Dest::ColsAtCompileTime>(dst, k)
1033 .swap(Block<Dest, Side==OnTheLeft ? 1 : Dest::RowsAtCompileTime, Side==OnTheRight ? 1 : Dest::ColsAtCompileTime>
1034 (dst,((Side==
OnTheLeft) ^ Transposed) ? k0 : kPrev));
1036 mask.coeffRef(k) =
true;
1043 for(
Index i = 0; i < n; ++i)
1045 Block<Dest, Side==OnTheLeft ? 1 : Dest::RowsAtCompileTime, Side==OnTheRight ? 1 : Dest::ColsAtCompileTime>
1046 (dst, ((Side==
OnTheLeft) ^ Transposed) ? perm.indices().coeff(i) : i)
1050 Block<const MatrixTypeCleaned,Side==OnTheLeft ? 1 : MatrixTypeCleaned::RowsAtCompileTime,Side==OnTheRight ? 1 : MatrixTypeCleaned::ColsAtCompileTime>
1051 (mat, ((Side==
OnTheRight) ^ Transposed) ? perm.indices().coeff(i) : i);
1057 template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1058 struct generic_product_impl<Lhs, Rhs, PermutationShape, MatrixShape, ProductTag>
1060 template<
typename Dest>
1061 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs)
1063 permutation_matrix_product<Rhs, OnTheLeft, false, MatrixShape>::run(dst, lhs, rhs);
1067 template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1068 struct generic_product_impl<Lhs, Rhs, MatrixShape, PermutationShape, ProductTag>
1070 template<
typename Dest>
1071 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs)
1073 permutation_matrix_product<Lhs, OnTheRight, false, MatrixShape>::run(dst, rhs, lhs);
1077 template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1078 struct generic_product_impl<Inverse<Lhs>, Rhs, PermutationShape, MatrixShape, ProductTag>
1080 template<
typename Dest>
1081 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dest& dst,
const Inverse<Lhs>& lhs,
const Rhs& rhs)
1083 permutation_matrix_product<Rhs, OnTheLeft, true, MatrixShape>::run(dst, lhs.nestedExpression(), rhs);
1087 template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1088 struct generic_product_impl<Lhs, Inverse<Rhs>, MatrixShape, PermutationShape, ProductTag>
1090 template<
typename Dest>
1091 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dest& dst,
const Lhs& lhs,
const Inverse<Rhs>& rhs)
1093 permutation_matrix_product<Lhs, OnTheRight, true, MatrixShape>::run(dst, rhs.nestedExpression(), lhs);
1108 template<
typename ExpressionType,
int S
ide,
bool Transposed,
typename ExpressionShape>
1109 struct transposition_matrix_product
1111 typedef typename nested_eval<ExpressionType, 1>::type MatrixType;
1112 typedef typename remove_all<MatrixType>::type MatrixTypeCleaned;
1114 template<
typename Dest,
typename TranspositionType>
1115 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(Dest& dst,
const TranspositionType& tr,
const ExpressionType& xpr)
1117 MatrixType mat(xpr);
1118 typedef typename TranspositionType::StorageIndex StorageIndex;
1119 const Index size = tr.size();
1122 if(!is_same_dense(dst,mat))
1125 for(
Index k=(Transposed?size-1:0) ; Transposed?k>=0:k<size ; Transposed?--k:++k)
1126 if(
Index(j=tr.coeff(k))!=k)
1128 if(Side==
OnTheLeft) dst.row(k).swap(dst.row(j));
1129 else if(Side==
OnTheRight) dst.col(k).swap(dst.col(j));
1134 template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1135 struct generic_product_impl<Lhs, Rhs, TranspositionsShape, MatrixShape, ProductTag>
1137 template<
typename Dest>
1138 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs)
1140 transposition_matrix_product<Rhs, OnTheLeft, false, MatrixShape>::run(dst, lhs, rhs);
1144 template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1145 struct generic_product_impl<Lhs, Rhs, MatrixShape, TranspositionsShape, ProductTag>
1147 template<
typename Dest>
1148 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs)
1150 transposition_matrix_product<Lhs, OnTheRight, false, MatrixShape>::run(dst, rhs, lhs);
1155 template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1156 struct generic_product_impl<Transpose<Lhs>, Rhs, TranspositionsShape, MatrixShape, ProductTag>
1158 template<
typename Dest>
1159 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dest& dst,
const Transpose<Lhs>& lhs,
const Rhs& rhs)
1161 transposition_matrix_product<Rhs, OnTheLeft, true, MatrixShape>::run(dst, lhs.nestedExpression(), rhs);
1165 template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1166 struct generic_product_impl<Lhs, Transpose<Rhs>, MatrixShape, TranspositionsShape, ProductTag>
1168 template<
typename Dest>
1169 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dest& dst,
const Lhs& lhs,
const Transpose<Rhs>& rhs)
1171 transposition_matrix_product<Lhs, OnTheRight, true, MatrixShape>::run(dst, rhs.nestedExpression(), lhs);
1179 #endif // EIGEN_PRODUCT_EVALUATORS_H Definition: Constants.h:319
const int HugeCost
Definition: Constants.h:44
Definition: Constants.h:334
Definition: Constants.h:235
Namespace containing all symbols from the Eigen library.
Definition: Core:141
const unsigned int RowMajorBit
Definition: Constants.h:66
const unsigned int PacketAccessBit
Definition: Constants.h:94
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Definition: Constants.h:332
Definition: Eigen_Colamd.h:50
Definition: Constants.h:321
const int Dynamic
Definition: Constants.h:22
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:70
const unsigned int ActualPacketAccessBit
Definition: Constants.h:105
const unsigned int LinearAccessBit
Definition: Constants.h:130