12 #ifndef EIGEN_ASSIGN_EVALUATOR_H 13 #define EIGEN_ASSIGN_EVALUATOR_H 27 template <
typename DstEvaluator,
typename SrcEvaluator,
typename AssignFunc,
int MaxPacketSize = -1>
50 :
int(Dst::RowsAtCompileTime),
53 :
int(Dst::MaxRowsAtCompileTime),
122 MayUnrollCompletely =
int(Dst::SizeAtCompileTime) !=
Dynamic 123 &&
int(Dst::SizeAtCompileTime) * (
int(DstEvaluator::CoeffReadCost)+
int(SrcEvaluator::CoeffReadCost)) <=
int(
UnrollingLimit),
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>
247 kernel.assignCoeff(
Index);
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>
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>
634 : m_dst(dst), m_src(src), m_functor(func), m_dstExpr(dstExpr)
636 #ifdef EIGEN_DEBUG_ASSIGN 654 m_functor.assignCoeff(m_dst.coeffRef(row,col), m_src.coeff(row,col));
660 m_functor.assignCoeff(m_dst.coeffRef(index), m_src.coeff(index));
666 Index row = rowIndexByOuterInner(outer, inner);
667 Index col = colIndexByOuterInner(outer, inner);
668 assignCoeff(row, col);
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>
687 Index row = rowIndexByOuterInner(outer, inner);
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
697 :
int(DstEvaluatorType::Flags)&RowMajorBit ? outer
703 typedef typename DstEvaluatorType::ExpressionTraits Traits;
704 return int(Traits::ColsAtCompileTime) == 1 ? 0
705 :
int(Traits::RowsAtCompileTime) == 1 ? inner
706 :
int(DstEvaluatorType::Flags)&RowMajorBit ? inner
712 return m_dstExpr.data();
727 template<
typename DstEvaluatorTypeT,
typename SrcEvaluatorTypeT,
typename Functor>
739 : Base(dst, src, func, dstExpr)
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
882 typedef typename internal::conditional<NeedToTranspose, Transpose<Dst>, Dst&>
::type ActualDstType;
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>
939 template<
typename Dst,
typename Src>
void check_for_aliasing(
const Dst &dst,
const Src &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 Kernel::DstEvaluatorType DstEvaluatorType
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
find_best_packet_helper< Size, typename packet_traits< T >::type >::type type
Generic expression of a matrix where all coefficients are defined by a functor.
static EIGEN_DEVICE_FUNC void EIGEN_STRONG_INLINE run(Kernel &kernel)
copy_using_evaluator_traits< DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, 4 > AssignmentTraits
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_assignment_no_alias(Dst &dst, const Src &src, const Func &func)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &kernel, Index outer)
const unsigned int ActualPacketAccessBit
#define EIGEN_STRONG_INLINE
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &kernel)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &, Index)
SrcEvaluatorTypeT::XprType SrcXprType
EIGEN_DEVICE_FUNC ExpressionType & expression() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize_if_allowed(DstXprType &dst, const SrcXprType &src, const Functor &)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_dense_assignment_loop(DstXprType &dst, const SrcXprType &src, const Functor &func)
const SrcEvaluatorType & m_src
#define EIGEN_DEBUG_VAR(x)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &kernel)
Pseudo expression providing an operator = assuming no aliasing.
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &kernel)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &kernel)
const unsigned int DirectAccessBit
void check_for_aliasing(const Dst &dst, const Src &src)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &kernel)
AssignmentTraits::PacketType PacketType
find_best_packet< DstScalar, RestrictedLinearSize >::type LinearPacketType
DstEvaluatorType::Scalar Scalar
EIGEN_DEVICE_FUNC const SrcEvaluatorType & srcEvaluator() const EIGEN_NOEXCEPT
Namespace containing all symbols from the Eigen library.
EIGEN_DEVICE_FUNC const Scalar * dstDataPtr() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacketByOuterInner(Index outer, Index inner)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacket(Index row, Index col)
conditional< int(Traversal)==LinearVectorizedTraversal, LinearPacketType, InnerPacketType >::type PacketType
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &, Index, Index)
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &kernel)
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerSize() const EIGEN_NOEXCEPT
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(DstXprType &dst, const SrcXprType &src, const Functor &func)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &kernel)
const unsigned int RowMajorBit
Kernel::PacketType PacketType
#define EIGEN_SIZE_MIN_PREFER_FIXED(a, b)
EIGEN_DEVICE_FUNC restricted_packet_dense_assignment_kernel(DstEvaluatorTypeT &dst, const SrcEvaluatorTypeT &src, const Functor &func, DstXprType &dstExpr)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &kernel, Index outer)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &)
#define EIGEN_STATIC_ASSERT_LVALUE(Derived)
static constexpr bool debug
#define EIGEN_DONT_INLINE
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
static EIGEN_DEVICE_FUNC void EIGEN_STRONG_INLINE run(Kernel &)
SrcEvaluatorTypeT SrcEvaluatorType
const Functor & m_functor
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &kernel)
DstEvaluator::XprType Dst
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeffByOuterInner(Index outer, Index inner)
find_best_packet< DstScalar, RestrictedInnerSize >::type InnerPacketType
DstEvaluatorType::XprType DstXprType
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
DstEvaluatorTypeT DstEvaluatorType
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &, Index)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op< typename DstXprType::Scalar, typename SrcXprType::Scalar > &)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &kernel)
Base::DstXprType DstXprType
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(DstXprType &dst, const SrcXprType &src, const internal::sub_assign_op< typename DstXprType::Scalar, SrcScalarType > &)
copy_using_evaluator_traits< DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor > AssignmentTraits
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Index row, Index col)
Assign src(row,col) to dst(row,col) through the assignment functor.
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T mini(const T &x, const T &y)
EIGEN_DEVICE_FUNC DstEvaluatorType & dstEvaluator() EIGEN_NOEXCEPT
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index innerSize() const EIGEN_NOEXCEPT
generic_dense_assignment_kernel< DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, BuiltIn > Base
EIGEN_CONSTEXPR Index size(const T &x)
#define EIGEN_DEVICE_FUNC
DstEvaluatorTypeT::XprType DstXprType
CwiseBinaryOp< internal::scalar_sum_op< double, double >, const CpyMatrixXd, const CpyMatrixXd > XprType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_assignment_no_alias_no_transpose(Dst &dst, const Src &src, const Func &func)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_restricted_packet_assignment_no_alias(Dst &dst, const Src &src, const Func &func)
#define EIGEN_PLAIN_ENUM_MIN(a, b)
storage_kind_to_shape< typename traits< T >::StorageKind >::Shape Shape
static EIGEN_DEPRECATED const end_t end
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &kernel, Index start, Index end)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &)
Kernel::PacketType PacketType
#define EIGEN_CHECK_BINARY_COMPATIBILIY(BINOP, LHS, RHS)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index colIndexByOuterInner(Index outer, Index inner)
Kernel::DstEvaluatorType DstEvaluatorType
AssignmentTraits::PacketType PacketType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE generic_dense_assignment_kernel(DstEvaluatorType &dst, const SrcEvaluatorType &src, const Functor &func, DstXprType &dstExpr)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Index index)
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &kernel)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(DstXprType &dst, const SrcXprType &src, const internal::add_assign_op< typename DstXprType::Scalar, SrcScalarType > &)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &kernel)
Convenience specialization of Stride to specify only an outer stride See class Map for some examples...
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &kernel)
const unsigned int LinearAccessBit
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacket(Index index)
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerStride() const EIGEN_NOEXCEPT
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_assignment(Dst &dst, const Src &src)
#define EIGEN_UNROLLING_LIMIT
DstEvaluatorType::XprType DstXprType
Kernel::PacketType PacketType
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Kernel &kernel)
#define EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(TYPE0, TYPE1)