12 #ifndef EIGEN_ASSIGN_EVALUATOR_H
13 #define EIGEN_ASSIGN_EVALUATOR_H
27 template <
typename DstEvaluator,
typename SrcEvaluator,
typename AssignFunc,
int MaxPacketSize = -1>
48 InnerSize =
int(Dst::IsVectorAtCompileTime) ?
int(Dst::SizeAtCompileTime)
122 MayUnrollCompletely =
int(Dst::SizeAtCompileTime) !=
Dynamic
151 #ifdef EIGEN_DEBUG_ASSIGN
156 std::cerr.setf(std::ios::hex, std::ios::basefield);
157 std::cerr <<
"DstFlags" <<
" = " <<
DstFlags <<
" (" << demangle_flags(
DstFlags) <<
" )" << std::endl;
158 std::cerr <<
"SrcFlags" <<
" = " <<
SrcFlags <<
" (" << demangle_flags(
SrcFlags) <<
" )" << std::endl;
159 std::cerr.unsetf(std::ios::hex);
176 std::cerr <<
"Traversal" <<
" = " <<
Traversal <<
" (" << demangle_traversal(
Traversal) <<
")" << std::endl;
183 std::cerr <<
"Unrolling" <<
" = " <<
Unrolling <<
" (" << demangle_unrolling(
Unrolling) <<
")" << std::endl;
184 std::cerr << std::endl;
197 template<
typename Kernel,
int Index,
int Stop>
205 outer =
Index / DstXprType::InnerSizeAtCompileTime,
206 inner =
Index % DstXprType::InnerSizeAtCompileTime
211 kernel.assignCoeffByOuterInner(outer, inner);
216 template<
typename Kernel,
int Stop>
222 template<
typename Kernel,
int Index_,
int Stop>
227 kernel.assignCoeffByOuterInner(outer, Index_);
232 template<
typename Kernel,
int Stop>
242 template<
typename Kernel,
int Index,
int Stop>
252 template<
typename Kernel,
int Stop>
262 template<
typename Kernel,
int Index,
int Stop>
271 outer =
Index / DstXprType::InnerSizeAtCompileTime,
272 inner =
Index % DstXprType::InnerSizeAtCompileTime,
279 kernel.template assignPacketByOuterInner<DstAlignment, SrcAlignment, PacketType>(outer, inner);
285 template<
typename Kernel,
int Stop>
291 template<
typename Kernel,
int Index_,
int Stop,
int SrcAlignment,
int DstAlignment>
297 kernel.template assignPacketByOuterInner<DstAlignment, SrcAlignment, PacketType>(outer, Index_);
303 template<
typename Kernel,
int Stop,
int SrcAlignment,
int DstAlignment>
315 template<
typename Kernel,
316 int Traversal = Kernel::AssignmentTraits::Traversal,
317 int Unrolling = Kernel::AssignmentTraits::Unrolling>
325 template<
typename Kernel,
int Unrolling>
332 EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT)
340 template<
typename Kernel>
345 for(
Index outer = 0; outer < kernel.outerSize(); ++outer) {
346 for(
Index inner = 0; inner < kernel.innerSize(); ++inner) {
347 kernel.assignCoeffByOuterInner(outer, inner);
353 template<
typename Kernel>
363 template<
typename Kernel>
370 const Index outerSize = kernel.outerSize();
371 for(
Index outer = 0; outer < outerSize; ++outer)
384 template <
bool IsAligned = false>
388 template <
typename Kernel>
399 template <
typename Kernel>
404 template <
typename Kernel>
410 for (
Index index = start; index <
end; ++index)
411 kernel.assignCoeff(index);
415 template<
typename Kernel>
422 typedef typename Kernel::PacketType
PacketType;
424 requestedAlignment = Kernel::AssignmentTraits::LinearRequiredAlignment,
426 dstIsAligned =
int(Kernel::AssignmentTraits::DstAlignment)>=
int(requestedAlignment),
428 :
int(Kernel::AssignmentTraits::DstAlignment),
429 srcAlignment = Kernel::AssignmentTraits::JointAlignment
431 const Index alignedStart = dstIsAligned ? 0 : internal::first_aligned<requestedAlignment>(kernel.dstDataPtr(),
size);
432 const Index alignedEnd = alignedStart + ((
size-alignedStart)/packetSize)*packetSize;
436 for(
Index index = alignedStart; index < alignedEnd; index += packetSize)
437 kernel.template assignPacket<dstAlignment, srcAlignment, PacketType>(index);
443 template<
typename Kernel>
449 typedef typename Kernel::PacketType
PacketType;
451 enum {
size = DstXprType::SizeAtCompileTime,
453 alignedSize = (
int(
size)/packetSize)*packetSize };
464 template<
typename Kernel>
467 typedef typename Kernel::PacketType
PacketType;
474 const Index innerSize = kernel.innerSize();
475 const Index outerSize = kernel.outerSize();
477 for(
Index outer = 0; outer < outerSize; ++outer)
478 for(
Index inner = 0; inner < innerSize; inner+=packetSize)
479 kernel.template assignPacketByOuterInner<DstAlignment, SrcAlignment, PacketType>(outer, inner);
483 template<
typename Kernel>
493 template<
typename Kernel>
499 typedef typename Kernel::AssignmentTraits Traits;
500 const Index outerSize = kernel.outerSize();
501 for(
Index outer = 0; outer < outerSize; ++outer)
503 Traits::SrcAlignment, Traits::DstAlignment>::
run(kernel, outer);
511 template<
typename Kernel>
518 kernel.assignCoeff(
i);
522 template<
typename Kernel>
536 template<
typename Kernel>
542 typedef typename Kernel::PacketType
PacketType;
545 requestedAlignment =
int(Kernel::AssignmentTraits::InnerRequiredAlignment),
547 dstIsAligned =
int(Kernel::AssignmentTraits::DstAlignment)>=
int(requestedAlignment),
548 dstAlignment = alignable ?
int(requestedAlignment)
549 :
int(Kernel::AssignmentTraits::DstAlignment)
551 const Scalar *dst_ptr = kernel.dstDataPtr();
552 if((!
bool(dstIsAligned)) && (
UIntPtr(dst_ptr) %
sizeof(
Scalar))>0)
557 const Index packetAlignedMask = packetSize - 1;
558 const Index innerSize = kernel.innerSize();
559 const Index outerSize = kernel.outerSize();
560 const Index alignedStep = alignable ? (packetSize - kernel.outerStride() % packetSize) & packetAlignedMask : 0;
561 Index alignedStart = ((!alignable) ||
bool(dstIsAligned)) ? 0 : internal::first_aligned<requestedAlignment>(dst_ptr, innerSize);
563 for(
Index outer = 0; outer < outerSize; ++outer)
565 const Index alignedEnd = alignedStart + ((innerSize-alignedStart) & ~packetAlignedMask);
567 for(
Index inner = 0; inner<alignedStart ; ++inner)
568 kernel.assignCoeffByOuterInner(outer, inner);
571 for(
Index inner = alignedStart; inner<alignedEnd; inner+=packetSize)
572 kernel.template assignPacketByOuterInner<dstAlignment, Unaligned, PacketType>(outer, inner);
575 for(
Index inner = alignedEnd; inner<innerSize ; ++inner)
576 kernel.assignCoeffByOuterInner(outer, inner);
578 alignedStart =
numext::mini((alignedStart+alignedStep)%packetSize, innerSize);
583 #if EIGEN_UNALIGNED_VECTORIZE
584 template<
typename Kernel>
590 typedef typename Kernel::PacketType
PacketType;
592 enum { innerSize = DstXprType::InnerSizeAtCompileTime,
594 vectorizableSize = (
int(innerSize) /
int(packetSize)) *
int(packetSize),
595 size = DstXprType::SizeAtCompileTime };
597 for(
Index outer = 0; outer < kernel.outerSize(); ++outer)
617 template<
typename DstEvaluatorTypeT,
typename SrcEvaluatorTypeT,
typename Functor,
int Version = Specialized>
625 typedef DstEvaluatorTypeT DstEvaluatorType;
626 typedef SrcEvaluatorTypeT SrcEvaluatorType;
634 : m_dst(dst), m_src(src), m_functor(
func), m_dstExpr(dstExpr)
636 #ifdef EIGEN_DEBUG_ASSIGN
660 m_functor.assignCoeff(m_dst.coeffRef(index), m_src.coeff(index));
667 Index col = colIndexByOuterInner(outer, inner);
672 template<
int StoreMode,
int LoadMode,
typename PacketType>
675 m_functor.template assignPacket<StoreMode>(&m_dst.coeffRef(
row,
col), m_src.template packet<LoadMode,PacketType>(
row,
col));
678 template<
int StoreMode,
int LoadMode,
typename PacketType>
681 m_functor.template assignPacket<StoreMode>(&m_dst.coeffRef(index), m_src.template packet<LoadMode,PacketType>(index));
684 template<
int StoreMode,
int LoadMode,
typename PacketType>
688 Index col = colIndexByOuterInner(outer, inner);
689 assignPacket<StoreMode,LoadMode,PacketType>(
row,
col);
694 typedef typename DstEvaluatorType::ExpressionTraits Traits;
695 return int(Traits::RowsAtCompileTime) == 1 ? 0
696 :
int(Traits::ColsAtCompileTime) == 1 ? inner
703 typedef typename DstEvaluatorType::ExpressionTraits Traits;
704 return int(Traits::ColsAtCompileTime) == 1 ? 0
705 :
int(Traits::RowsAtCompileTime) == 1 ? inner
712 return m_dstExpr.data();
716 DstEvaluatorType& m_dst;
717 const SrcEvaluatorType& m_src;
727 template<
typename DstEvaluatorTypeT,
typename SrcEvaluatorTypeT,
typename Functor>
748 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
754 eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
757 template<
typename DstXprType,
typename SrcXprType,
typename T1,
typename T2>
761 Index dstRows = src.rows();
762 Index dstCols = src.cols();
763 if(((dst.rows()!=dstRows) || (dst.cols()!=dstCols)))
764 dst.resize(dstRows, dstCols);
765 eigen_assert(dst.rows() == dstRows && dst.cols() == dstCols);
768 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
774 SrcEvaluatorType srcEvaluator(src);
780 DstEvaluatorType dstEvaluator(dst);
783 Kernel kernel(dstEvaluator, srcEvaluator,
func, dst.const_cast_derived());
789 #ifndef EIGEN_GPU_COMPILE_PHASE
790 template<
typename DstXprType>
794 std::fill_n(dst.data(), dst.size(), src.functor()());
798 template<
typename DstXprType,
typename SrcXprType>
821 template<
typename DstXprType,
typename SrcXprType,
typename Functor,
832 template<
typename Dst,
typename Src>
838 template<
typename Dst,
typename Src>
846 template<
typename Dst,
typename Src,
typename Func>
854 template<
typename Dst,
typename Src,
typename Func>
863 template<
typename Dst,
template <
typename>
class StorageBase,
typename Src,
typename Func>
871 template<
typename Dst,
typename Src,
typename Func>
876 NeedToTranspose = ( (
int(Dst::RowsAtCompileTime) == 1 &&
int(Src::ColsAtCompileTime) == 1)
877 || (
int(Dst::ColsAtCompileTime) == 1 &&
int(Src::RowsAtCompileTime) == 1)
878 ) &&
int(Dst::SizeAtCompileTime) != 1
883 ActualDstType actualDst(dst);
893 template<
typename Dst,
typename Src,
typename Func>
904 SrcEvaluatorType srcEvaluator(src);
907 DstEvaluatorType dstEvaluator(dst);
908 Kernel kernel(dstEvaluator, srcEvaluator,
func, dst.const_cast_derived());
913 template<
typename Dst,
typename Src>
920 template<
typename Dst,
typename Src,
typename Func>
931 template<
typename Dst,
typename Src>
944 template<
typename DstXprType,
typename SrcXprType,
typename Functor,
typename Weak>
950 #ifndef EIGEN_NO_DEBUG
962 template<
typename DstXprType,
typename SrcXprType,
typename Functor,
typename Weak>
968 Index dstRows = src.rows();
969 Index dstCols = src.cols();
970 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
971 dst.resize(dstRows, dstCols);
973 eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
979 template<
typename SrcScalarType>
983 Index dstRows = src.rows();
984 Index dstCols = src.cols();
985 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
986 dst.resize(dstRows, dstCols);
988 eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
992 template<
typename SrcScalarType>
996 Index dstRows = src.rows();
997 Index dstCols = src.cols();
998 if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
999 dst.resize(dstRows, dstCols);
1001 eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
1010 #endif // EIGEN_ASSIGN_EVALUATOR_H