13 #ifndef EIGEN_PRODUCTEVALUATORS_H
14 #define EIGEN_PRODUCTEVALUATORS_H
28 template<
typename Lhs,
typename Rhs,
int Options>
40 template<
typename Lhs,
typename Rhs,
typename Scalar1,
typename Scalar2,
typename Plain1>
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>
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> >
56 typedef evaluator<
Product<EIGEN_SCALAR_BINARYOP_EXPR_RETURN_TYPE(Scalar1,Lhs,product), Rhs, DefaultProduct> >
Base;
59 :
Base(xpr.
lhs().functor().m_other * xpr.
rhs().lhs() * xpr.
rhs().rhs())
64 template<
typename Lhs,
typename Rhs,
int DiagIndex>
66 :
public evaluator<Diagonal<const Product<Lhs, Rhs, LazyProduct>, DiagIndex> >
82 template<
typename Lhs,
typename Rhs,
83 typename LhsShape =
typename evaluator_traits<Lhs>::Shape,
84 typename RhsShape =
typename evaluator_traits<Rhs>::Shape,
88 template<
typename Lhs,
typename Rhs>
90 static const bool value =
true;
95 template<
typename Lhs,
typename Rhs,
int Options,
int ProductTag,
typename LhsShape,
typename RhsShape>
97 :
public evaluator<typename Product<Lhs, Rhs, Options>::PlainObject>
100 typedef typename XprType::PlainObject PlainObject;
106 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
108 : m_result(xpr.rows(), xpr.cols())
110 ::new (
static_cast<Base*
>(
this))
Base(m_result);
128 PlainObject m_result;
135 template<
typename DstXprType,
typename Lhs,
typename Rhs,
int Options,
typename Scalar>
137 typename
enable_if<(Options==DefaultProduct || Options==AliasFreeProduct)>::type>
140 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
143 Index dstRows = src.rows();
144 Index dstCols = src.cols();
145 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
146 dst.resize(dstRows, dstCols);
153 template<
typename DstXprType,
typename Lhs,
typename Rhs,
int Options,
typename Scalar>
155 typename
enable_if<(Options==DefaultProduct || Options==AliasFreeProduct)>::type>
158 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
161 eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
168 template<
typename DstXprType,
typename Lhs,
typename Rhs,
int Options,
typename Scalar>
170 typename
enable_if<(Options==DefaultProduct || Options==AliasFreeProduct)>::type>
173 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
176 eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
186 template<
typename DstXprType,
typename Lhs,
typename Rhs,
typename AssignFunc,
typename Scalar,
typename ScalarBis,
typename Plain>
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>
207 static const bool value =
true;
210 template<
typename OtherXpr,
typename Lhs,
typename Rhs>
213 static const bool value =
true;
216 template<
typename DstXprType,
typename OtherXpr,
typename ProductType,
typename Func1,
typename Func2>
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> > \
245 template<
typename Lhs,
typename Rhs>
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&)
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>
299 template<
typename T>
struct is_row_major :
internal::conditional<(int(T::Flags)&RowMajorBit), internal::true_type, internal::false_type>::type {};
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>
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>
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));
388 >::run(actual_lhs, actual_rhs, dst, alpha);
392 template<
typename Lhs,
typename Rhs>
397 template<
typename Dst>
398 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs)
405 template<
typename Dst>
406 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void addTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs)
412 template<
typename Dst>
413 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void subTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs)
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)
446 eval_dynamic_impl(dst,
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>
484 template<
int Traversal,
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename RetScalar>
487 template<
int StorageOrder,
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
490 template<
typename Lhs,
typename Rhs,
int ProductTag>
495 typedef typename XprType::Scalar Scalar;
496 typedef typename XprType::CoeffReturnType CoeffReturnType;
498 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
505 m_innerDim(xpr.lhs().cols())
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";
529 typedef typename internal::remove_all<LhsNested>::type LhsNestedCleaned;
530 typedef typename internal::remove_all<RhsNested>::type RhsNestedCleaned;
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,
555 Unroll = CoeffReadCost <= EIGEN_UNROLLING_LIMIT,
557 LhsFlags = LhsEtorType::Flags,
558 RhsFlags = RhsEtorType::Flags,
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))),
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 = ((
unsigned int)(LhsFlags | 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
600 && (LhsFlags & RhsFlags & ActualPacketAccessBit)
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
627 Unroll ? int(InnerSize) :
Dynamic,
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;
653 template<
typename Lhs,
typename Rhs>
655 :
product_evaluator<Product<Lhs, Rhs, LazyProduct>, CoeffBasedProductMode, DenseShape, DenseShape>
663 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
673 template<
int UnrollingIndex,
typename Lhs,
typename Rhs,
typename Packet,
int 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>
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>
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>
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>
714 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(
Index ,
Index ,
const Lhs& ,
const Rhs& ,
Index ,
Packet &res)
720 template<
typename Lhs,
typename Rhs,
typename Packet,
int LoadMode>
723 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(
Index ,
Index ,
const Lhs& ,
const Rhs& ,
Index ,
Packet &res)
729 template<
typename Lhs,
typename Rhs,
typename Packet,
int 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)
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>
743 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(
Index row,
Index col,
const Lhs& lhs,
const Rhs& rhs,
Index innerDim,
Packet& res)
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>
760 template<
typename Lhs,
typename Rhs,
int ProductTag>
766 template<
typename Dest>
767 static void scaleAndAddTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
770 ::run(dst, lhs.nestedExpression(), rhs, alpha);
774 template<
typename Lhs,
typename Rhs,
int ProductTag>
780 template<
typename Dest>
781 static void scaleAndAddTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
791 template <
typename Lhs,
int LhsMode,
bool LhsIsVector,
792 typename Rhs,
int RhsMode,
bool RhsIsVector>
795 template<
typename Lhs,
typename Rhs,
int ProductTag>
801 template<
typename Dest>
802 static EIGEN_DEVICE_FUNC
803 void scaleAndAddTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
809 template<
typename Lhs,
typename Rhs,
int ProductTag>
815 template<
typename Dest>
816 static void scaleAndAddTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
827 template<
typename MatrixType,
typename DiagonalType,
typename Derived,
int ProductOrder>
839 _StorageOrder = (Derived::MaxRowsAtCompileTime==1 && Derived::MaxColsAtCompileTime!=1) ?
RowMajor
840 : (Derived::MaxColsAtCompileTime==1 && Derived::MaxRowsAtCompileTime!=1) ?
ColMajor
844 _ScalarAccessOnDiag = !((
int(_StorageOrder) ==
ColMajor && int(ProductOrder) ==
OnTheLeft)
853 _LinearAccessMask = (MatrixType::RowsAtCompileTime==1 || MatrixType::ColsAtCompileTime==1) ?
LinearAccessBit : 0,
854 Flags = ((HereditaryBits|_LinearAccessMask) & (
unsigned int)(MatrixFlags)) | (_Vectorizable ?
PacketAccessBit : 0),
857 AsScalarProduct = (DiagonalType::SizeAtCompileTime==1)
858 || (DiagonalType::SizeAtCompileTime==
Dynamic && MatrixType::RowsAtCompileTime==1 && ProductOrder==
OnTheLeft)
859 || (DiagonalType::SizeAtCompileTime==
Dynamic && MatrixType::ColsAtCompileTime==1 && ProductOrder==
OnTheRight)
863 : m_diagImpl(diag), m_matImpl(mat)
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>
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>
889 InnerSize = (MatrixType::Flags &
RowMajorBit) ? MatrixType::ColsAtCompileTime : MatrixType::RowsAtCompileTime,
892 return internal::pmul(m_matImpl.template packet<LoadMode,PacketType>(row, col),
893 m_diagImpl.template packet<DiagonalPacketLoadMode,PacketType>(
id));
901 template<
typename Lhs,
typename Rhs,
int ProductKind,
int ProductTag>
906 using Base::m_diagImpl;
907 using Base::m_matImpl;
909 typedef typename Base::Scalar Scalar;
912 typedef typename XprType::PlainObject PlainObject;
913 typedef typename Lhs::DiagonalVectorType DiagonalType;
916 enum { StorageOrder = Base::_StorageOrder };
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,
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>
952 using Base::m_diagImpl;
953 using Base::m_matImpl;
955 typedef typename Base::Scalar Scalar;
958 typedef typename XprType::PlainObject PlainObject;
960 enum { StorageOrder = Base::_StorageOrder };
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,
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>
1000 template<
typename ExpressionType,
int S
ide,
bool Transposed>
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)
1014 if(is_same_dense(dst, mat))
1020 while(r < perm.size())
1023 while(r<perm.size() && mask[r]) r++;
1030 for(
Index k=perm.indices().coeff(k0); k!=k0; k=perm.indices().coeff(k))
1034 (dst,((Side==
OnTheLeft) ^ Transposed) ? k0 : kPrev));
1043 for(
Index i = 0; i < n; ++i)
1046 (dst, ((Side==
OnTheLeft) ^ Transposed) ? perm.indices().coeff(i) : i)
1051 (mat, ((Side==
OnTheRight) ^ Transposed) ? perm.indices().coeff(i) : i);
1057 template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1060 template<
typename Dest>
1061 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs)
1067 template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1070 template<
typename Dest>
1071 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs)
1077 template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1080 template<
typename Dest>
1081 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dest& dst,
const Inverse<Lhs>& lhs,
const Rhs& rhs)
1087 template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1090 template<
typename Dest>
1091 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dest& dst,
const Lhs& lhs,
const Inverse<Rhs>& rhs)
1108 template<
typename ExpressionType,
int S
ide,
bool Transposed,
typename ExpressionShape>
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)
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>
1137 template<
typename Dest>
1138 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs)
1144 template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1147 template<
typename Dest>
1148 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs)
1155 template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1158 template<
typename Dest>
1159 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dest& dst,
const Transpose<Lhs>& lhs,
const Rhs& rhs)
1165 template<
typename Lhs,
typename Rhs,
int ProductTag,
typename MatrixShape>
1168 template<
typename Dest>
1169 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalTo(Dest& dst,
const Lhs& lhs,
const Transpose<Rhs>& rhs)
1179 #endif // EIGEN_PRODUCT_EVALUATORS_H