13#ifndef EIGEN_PRODUCTEVALUATORS_H
14#define EIGEN_PRODUCTEVALUATORS_H
28template<
typename Lhs,
typename Rhs,
int Options>
40template<
typename Lhs,
typename Rhs,
typename Scalar>
42 :
evaluator_traits_base<CwiseUnaryOp<internal::scalar_multiple_op<Scalar>, const Product<Lhs, Rhs, DefaultProduct> > >
44 enum { AssumeAliasing = 1 };
46template<
typename Lhs,
typename Rhs,
typename Scalar>
48 :
public evaluator<Product<CwiseUnaryOp<internal::scalar_multiple_op<Scalar>,const Lhs>, Rhs, DefaultProduct> >
54 :
Base(
xpr.functor().m_other *
xpr.nestedExpression().lhs() *
xpr.nestedExpression().rhs())
59template<
typename Lhs,
typename Rhs,
int DiagIndex>
61 :
public evaluator<Diagonal<const Product<Lhs, Rhs, LazyProduct>, DiagIndex> >
77template<
typename Lhs,
typename Rhs,
78 typename LhsShape =
typename evaluator_traits<Lhs>::Shape,
79 typename RhsShape =
typename evaluator_traits<Rhs>::Shape,
83template<
typename Lhs,
typename Rhs>
87 enum { AssumeAliasing = 1 };
90template<
typename Lhs,
typename Rhs>
94 enum { AssumeAliasing = 0 };
99template<
typename Lhs,
typename Rhs,
int Options,
int ProductTag,
typename LhsShape,
typename RhsShape>
101 :
public evaluator<typename Product<Lhs, Rhs, Options>::PlainObject>
104 typedef typename XprType::PlainObject PlainObject;
111 : m_result(
xpr.rows(),
xpr.cols())
113 ::new (
static_cast<Base*
>(
this))
Base(m_result);
131 PlainObject m_result;
135template<
typename DstXprType,
typename Lhs,
typename Rhs,
int Options,
typename Scalar>
137 typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct),Scalar>::type>
148template<
typename DstXprType,
typename Lhs,
typename Rhs,
int Options,
typename Scalar>
150 typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct),Scalar>::type>
161template<
typename DstXprType,
typename Lhs,
typename Rhs,
int Options,
typename Scalar>
163 typename enable_if<(Options==DefaultProduct || Options==AliasFreeProduct),Scalar>::type>
177template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename AssignFunc,
typename Scalar,
typename ScalarBis>
185 call_assignment_no_alias(
dst, (
src.functor().m_other *
src.nestedExpression().lhs())*
src.nestedExpression().rhs(), func);
193template<
typename DstXprType,
typename OtherXpr,
typename ProductType,
typename Scalar,
typename Func1,
typename Func2>
199 call_assignment_no_alias(
dst,
src.lhs(), func);
204template<
typename DstXprType,
typename OtherXpr,
typename Lhs,
typename Rhs,
typename Scalar>
207 :
assignment_from_xpr_plus_product<DstXprType, OtherXpr, Product<Lhs,Rhs,DefaultProduct>, Scalar, internal::assign_op<Scalar>, internal::add_assign_op<Scalar> >
209template<
typename DstXprType,
typename OtherXpr,
typename Lhs,
typename Rhs,
typename Scalar>
212 :
assignment_from_xpr_plus_product<DstXprType, OtherXpr, Product<Lhs,Rhs,DefaultProduct>, Scalar, internal::add_assign_op<Scalar>, internal::add_assign_op<Scalar> >
214template<
typename DstXprType,
typename OtherXpr,
typename Lhs,
typename Rhs,
typename Scalar>
217 :
assignment_from_xpr_plus_product<DstXprType, OtherXpr, Product<Lhs,Rhs,DefaultProduct>, Scalar, internal::sub_assign_op<Scalar>, internal::sub_assign_op<Scalar> >
221template<
typename Lhs,
typename Rhs>
224 template<
typename Dst>
225 static inline void evalTo(Dst&
dst,
const Lhs& lhs,
const Rhs& rhs)
227 dst.coeffRef(0,0) = (lhs.transpose().cwiseProduct(rhs)).sum();
230 template<
typename Dst>
231 static inline void addTo(Dst&
dst,
const Lhs& lhs,
const Rhs& rhs)
233 dst.coeffRef(0,0) += (lhs.transpose().cwiseProduct(rhs)).sum();
236 template<
typename Dst>
237 static void subTo(Dst&
dst,
const Lhs& lhs,
const Rhs& rhs)
238 {
dst.coeffRef(0,0) -= (lhs.transpose().cwiseProduct(rhs)).sum(); }
247template<
typename Dst,
typename Lhs,
typename Rhs,
typename Func>
248EIGEN_DONT_INLINE
void outer_product_selector_run(Dst&
dst,
const Lhs &lhs,
const Rhs &rhs,
const Func& func,
const false_type&)
254 const Index cols =
dst.cols();
255 for (Index
j=0;
j<cols; ++
j)
260template<
typename Dst,
typename Lhs,
typename Rhs,
typename Func>
261EIGEN_DONT_INLINE
void outer_product_selector_run(Dst&
dst,
const Lhs &lhs,
const Rhs &rhs,
const Func& func,
const true_type&)
264 typename nested_eval<Rhs,Lhs::SizeAtCompileTime>::type
actual_rhs(rhs);
267 const Index rows =
dst.rows();
268 for (Index i=0; i<rows; ++i)
272template<
typename Lhs,
typename Rhs>
279 struct set {
template<
typename Dst,
typename Src>
void operator()(
const Dst&
dst,
const Src&
src)
const {
dst.const_cast_derived() =
src; } };
280 struct add {
template<
typename Dst,
typename Src>
void operator()(
const Dst&
dst,
const Src&
src)
const {
dst.const_cast_derived() +=
src; } };
281 struct sub {
template<
typename Dst,
typename Src>
void operator()(
const Dst&
dst,
const Src&
src)
const {
dst.const_cast_derived() -=
src; } };
284 explicit adds(
const Scalar& s) : m_scale(s) {}
285 template<
typename Dst,
typename Src>
void operator()(
const Dst&
dst,
const Src&
src)
const {
286 dst.const_cast_derived() += m_scale *
src;
290 template<
typename Dst>
291 static inline void evalTo(Dst&
dst,
const Lhs& lhs,
const Rhs& rhs)
296 template<
typename Dst>
297 static inline void addTo(Dst&
dst,
const Lhs& lhs,
const Rhs& rhs)
302 template<
typename Dst>
303 static inline void subTo(Dst&
dst,
const Lhs& lhs,
const Rhs& rhs)
308 template<
typename Dst>
309 static inline void scaleAndAddTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
311 internal::outer_product_selector_run(dst, lhs, rhs, adds(alpha), is_row_major<Dst>());
318template<
typename Lhs,
typename Rhs,
typename Derived>
323 template<
typename Dst>
324 static void evalTo(Dst&
dst,
const Lhs& lhs,
const Rhs& rhs)
325 {
dst.setZero(); scaleAndAddTo(
dst, lhs, rhs,
Scalar(1)); }
327 template<
typename Dst>
328 static void addTo(Dst&
dst,
const Lhs& lhs,
const Rhs& rhs)
329 { scaleAndAddTo(
dst,lhs, rhs,
Scalar(1)); }
331 template<
typename Dst>
332 static void subTo(Dst&
dst,
const Lhs& lhs,
const Rhs& rhs)
333 { scaleAndAddTo(
dst, lhs, rhs,
Scalar(-1)); }
335 template<
typename Dst>
336 static void scaleAndAddTo(Dst&
dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
337 { Derived::scaleAndAddTo(
dst,lhs,rhs,alpha); }
341template<
typename Lhs,
typename Rhs>
349 template<
typename Dest>
350 static void scaleAndAddTo(
Dest&
dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
355 >::run(lhs, rhs,
dst, alpha);
359template<
typename Lhs,
typename Rhs>
364 template<
typename Dst>
365 static inline void evalTo(Dst&
dst,
const Lhs& lhs,
const Rhs& rhs)
372 template<
typename Dst>
373 static inline void addTo(Dst&
dst,
const Lhs& lhs,
const Rhs& rhs)
379 template<
typename Dst>
380 static inline void subTo(Dst&
dst,
const Lhs& lhs,
const Rhs& rhs)
392template<
typename Lhs,
typename Rhs>
402template<
int Traversal,
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename RetScalar>
405template<
int StorageOrder,
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
408template<
typename Lhs,
typename Rhs,
int ProductTag>
413 typedef typename XprType::Scalar Scalar;
414 typedef typename XprType::CoeffReturnType CoeffReturnType;
415 typedef typename XprType::PacketScalar PacketScalar;
416 typedef typename XprType::PacketReturnType PacketReturnType;
424 m_innerDim(
xpr.lhs().cols())
428 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
443 RowsAtCompileTime = LhsNestedCleaned::RowsAtCompileTime,
444 ColsAtCompileTime = RhsNestedCleaned::ColsAtCompileTime,
445 InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(LhsNestedCleaned::ColsAtCompileTime, RhsNestedCleaned::RowsAtCompileTime),
446 MaxRowsAtCompileTime = LhsNestedCleaned::MaxRowsAtCompileTime,
447 MaxColsAtCompileTime = RhsNestedCleaned::MaxColsAtCompileTime,
451 LhsCoeffReadCost = LhsEtorType::CoeffReadCost,
452 RhsCoeffReadCost = RhsEtorType::CoeffReadCost,
454 : InnerSize == Dynamic ? HugeCost
458 Unroll = CoeffReadCost <= EIGEN_UNROLLING_LIMIT,
460 LhsFlags = LhsEtorType::Flags,
461 RhsFlags = RhsEtorType::Flags,
472 && (ColsAtCompileTime == Dynamic || ((ColsAtCompileTime % PacketSize) == 0) ),
475 && (RowsAtCompileTime == Dynamic || ((RowsAtCompileTime % PacketSize) == 0) ),
477 EvalToRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
478 : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
481 Flags = ((
unsigned int)(LhsFlags | RhsFlags) & HereditaryBits & ~
RowMajorBit)
487 LhsOuterStrideBytes =
int(LhsNestedCleaned::OuterStrideAtCompileTime) * int(
sizeof(
typename LhsNestedCleaned::Scalar)),
488 RhsOuterStrideBytes = int(RhsNestedCleaned::OuterStrideAtCompileTime) * int(
sizeof(
typename RhsNestedCleaned::Scalar)),
502 && (LhsFlags & RhsFlags & ActualPacketAccessBit)
506 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const CoeffReturnType coeff(Index row, Index col)
const
508 return (m_lhs.row(row).transpose().cwiseProduct( m_rhs.col(col) )).sum();
517 const Index row = RowsAtCompileTime == 1 ? 0 : index;
518 const Index col = RowsAtCompileTime == 1 ? index : 0;
519 return (m_lhs.row(row).transpose().cwiseProduct( m_rhs.col(col) )).sum();
522 template<
int LoadMode,
typename PacketType>
523 const PacketType packet(Index row, Index col)
const
527 Unroll ? int(InnerSize) : Dynamic,
529 PacketImpl::run(row, col, m_lhsImpl, m_rhsImpl, m_innerDim, res);
533 template<
int LoadMode,
typename PacketType>
534 const PacketType packet(Index index)
const
536 const Index row = RowsAtCompileTime == 1 ? 0 : index;
537 const Index col = RowsAtCompileTime == 1 ? index : 0;
552template<
typename Lhs,
typename Rhs>
554 :
product_evaluator<Product<Lhs, Rhs, LazyProduct>, CoeffBasedProductMode, DenseShape, DenseShape>
571template<
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
574 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs, Index
innerDim, Packet &res)
576 etor_product_packet_impl<RowMajor, UnrollingIndex-1, Lhs, Rhs, Packet, LoadMode>::run(row, col, lhs, rhs,
innerDim, res);
581template<
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
584 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs, Index
innerDim, Packet &res)
586 etor_product_packet_impl<ColMajor, UnrollingIndex-1, Lhs, Rhs, Packet, LoadMode>::run(row, col, lhs, rhs,
innerDim, res);
591template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
594 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs, Index , Packet &res)
600template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
603 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs, Index , Packet &res)
609template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
612 static EIGEN_STRONG_INLINE
void run(Index , Index ,
const Lhs& ,
const Rhs& , Index , Packet &res)
618template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
621 static EIGEN_STRONG_INLINE
void run(Index , Index ,
const Lhs& ,
const Rhs& , Index , Packet &res)
627template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
630 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs, Index
innerDim, Packet& res)
638template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
641 static EIGEN_STRONG_INLINE
void run(Index row, Index col,
const Lhs& lhs,
const Rhs& rhs, Index
innerDim, Packet& res)
658template<
typename Lhs,
typename Rhs,
int ProductTag>
664 template<
typename Dest>
665 static void scaleAndAddTo(
Dest&
dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
668 ::run(
dst, lhs.nestedExpression(), rhs, alpha);
672template<
typename Lhs,
typename Rhs,
int ProductTag>
678 template<
typename Dest>
679 static void scaleAndAddTo(
Dest&
dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
693template<
typename Lhs,
typename Rhs,
int ProductTag>
699 template<
typename Dest>
700 static void scaleAndAddTo(
Dest&
dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
706template<
typename Lhs,
typename Rhs,
int ProductTag>
712 template<
typename Dest>
713 static void scaleAndAddTo(
Dest&
dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
724template<
typename MatrixType,
typename DiagonalType,
typename Derived,
int ProductOrder>
742 _LinearAccessMask = (MatrixType::RowsAtCompileTime==1 || MatrixType::ColsAtCompileTime==1) ?
LinearAccessBit : 0,
743 Flags = ((HereditaryBits|_LinearAccessMask) & (
unsigned int)(MatrixFlags)) | (_Vectorizable ?
PacketAccessBit : 0),
748 : m_diagImpl(
diag), m_matImpl(
mat)
751 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
756 return m_diagImpl.coeff(idx) * m_matImpl.coeff(idx);
760 template<
int LoadMode,
typename PacketType>
761 EIGEN_STRONG_INLINE PacketType packet_impl(Index row, Index col, Index
id,
internal::true_type)
const
764 internal::pset1<PacketType>(m_diagImpl.coeff(
id)));
767 template<
int LoadMode,
typename PacketType>
768 EIGEN_STRONG_INLINE PacketType packet_impl(Index row, Index col, Index
id,
internal::false_type)
const
771 InnerSize = (MatrixType::Flags &
RowMajorBit) ? MatrixType::ColsAtCompileTime : MatrixType::RowsAtCompileTime,
783template<
typename Lhs,
typename Rhs,
int ProductKind,
int ProductTag>
788 using Base::m_diagImpl;
789 using Base::m_matImpl;
791 typedef typename Base::Scalar Scalar;
794 typedef typename XprType::PlainObject PlainObject;
805 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar coeff(Index row, Index col)
const
807 return m_diagImpl.coeff(row) * m_matImpl.coeff(row, col);
811 template<
int LoadMode,
typename PacketType>
812 EIGEN_STRONG_INLINE PacketType packet(Index row, Index col)
const
820 template<
int LoadMode,
typename PacketType>
821 EIGEN_STRONG_INLINE PacketType packet(Index idx)
const
829template<
typename Lhs,
typename Rhs,
int ProductKind,
int ProductTag>
834 using Base::m_diagImpl;
835 using Base::m_matImpl;
837 typedef typename Base::Scalar Scalar;
840 typedef typename XprType::PlainObject PlainObject;
849 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar coeff(Index row, Index col)
const
851 return m_matImpl.coeff(row, col) * m_diagImpl.coeff(col);
855 template<
int LoadMode,
typename PacketType>
856 EIGEN_STRONG_INLINE PacketType packet(Index row, Index col)
const
862 template<
int LoadMode,
typename PacketType>
863 EIGEN_STRONG_INLINE PacketType packet(Index idx)
const
879template<
typename ExpressionType,
int S
ide,
bool Transposed,
typename ExpressionShape>
882template<
typename ExpressionType,
int S
ide,
bool Transposed>
888 template<
typename Dest,
typename PermutationType>
889 static inline void run(
Dest&
dst,
const PermutationType& perm,
const ExpressionType&
xpr)
896 if(is_same_dense(
dst,
mat))
902 while(r < perm.size())
905 while(r<perm.size() &&
mask[r]) r++;
912 for(Index k=perm.indices().coeff(
k0); k!=
k0; k=perm.indices().coeff(k))
918 mask.coeffRef(k) =
true;
925 for(Index i = 0; i < n; ++i)
939template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
942 template<
typename Dest>
943 static void evalTo(
Dest&
dst,
const Lhs& lhs,
const Rhs& rhs)
949template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
952 template<
typename Dest>
953 static void evalTo(
Dest&
dst,
const Lhs& lhs,
const Rhs& rhs)
959template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
962 template<
typename Dest>
969template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
972 template<
typename Dest>
990template<
typename ExpressionType,
int S
ide,
bool Transposed,
typename ExpressionShape>
996 template<
typename Dest,
typename TranspositionType>
997 static inline void run(
Dest&
dst,
const TranspositionType&
tr,
const ExpressionType&
xpr)
1000 typedef typename TranspositionType::StorageIndex StorageIndex;
1001 const Index size =
tr.size();
1008 if(Index(
j=
tr.coeff(k))!=k)
1016template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1019 template<
typename Dest>
1020 static void evalTo(
Dest&
dst,
const Lhs& lhs,
const Rhs& rhs)
1026template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1029 template<
typename Dest>
1030 static void evalTo(
Dest&
dst,
const Lhs& lhs,
const Rhs& rhs)
1037template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1040 template<
typename Dest>
1047template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1050 template<
typename Dest>
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:85
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition CwiseUnaryOp.h:57
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition Diagonal.h:65
Expression of the inverse of another expression.
Definition Inverse.h:44
Expression of the product of two arbitrary matrices or vectors.
Definition Product.h:111
Pseudo expression representing a solving operation.
Definition Solve.h:63
Expression of the transpose of a matrix.
Definition Transpose.h:55
@ Aligned16
Data pointer is aligned on a 16 bytes boundary.
Definition Constants.h:230
@ ColMajor
Storage order is column major (see TopicStorageOrders).
Definition Constants.h:320
@ RowMajor
Storage order is row major (see TopicStorageOrders).
Definition Constants.h:322
@ OnTheLeft
Apply transformation on the left.
Definition Constants.h:333
@ OnTheRight
Apply transformation on the right.
Definition Constants.h:335
const unsigned int PacketAccessBit
Short version: means the expression might be vectorized.
Definition Constants.h:88
const unsigned int LinearAccessBit
Short version: means the expression can be seen as 1D vector.
Definition Constants.h:124
const unsigned int EvalBeforeNestingBit
means the expression should be evaluated by the calling expression
Definition Constants.h:65
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition Constants.h:61
Definition Constants.h:511
Definition Constants.h:514
Holds information about the various numeric (i.e.
Definition NumTraits.h:108
Definition Constants.h:518
Definition Constants.h:517
Definition Constants.h:519
Definition Constants.h:516
Definition AssignEvaluator.h:684
Definition AssignEvaluator.h:674
Definition AssignmentFunctors.h:42
Definition AssignmentFunctors.h:21
Definition ProductEvaluators.h:195
Definition BlasUtil.h:257
Definition ProductEvaluators.h:727
Definition ProductEvaluators.h:403
Definition ProductEvaluators.h:406
Definition CoreEvaluators.h:101
Definition CoreEvaluators.h:62
Definition CoreEvaluators.h:75
Definition CoreEvaluators.h:82
Definition GeneralProduct.h:163
Definition ProductEvaluators.h:320
Definition ProductEvaluators.h:81
Definition GenericPacketMath.h:90
Definition ProductEvaluators.h:880
Definition ForwardDeclarations.h:165
Definition GeneralProduct.h:36
Definition BinaryFunctors.h:358
Definition BinaryFunctors.h:24
Definition ProductEvaluators.h:691
Definition AssignmentFunctors.h:63
Definition ProductEvaluators.h:992
Definition ProductEvaluators.h:656