12#ifndef EIGEN_ASSIGN_EVALUATOR_H
13#define EIGEN_ASSIGN_EVALUATOR_H
27 template <
typename DstEvaluator,
typename SrcEvaluator,
typename AssignFunc>
30 typedef typename DstEvaluator::XprType Dst;
31 typedef typename Dst::Scalar DstScalar;
33 typedef typename find_best_packet<DstScalar, Dst::SizeAtCompileTime>::type PacketType;
36 DstFlags = DstEvaluator::Flags,
37 SrcFlags = SrcEvaluator::Flags,
43 DstAlignment = DstEvaluator::Alignment,
44 SrcAlignment = SrcEvaluator::Alignment,
46 JointAlignment = EIGEN_PLAIN_ENUM_MIN(DstAlignment, SrcAlignment)
51 InnerSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::SizeAtCompileTime)
52 : int(DstFlags)&
RowMajorBit ? int(Dst::ColsAtCompileTime)
53 : int(Dst::RowsAtCompileTime),
54 InnerMaxSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::MaxSizeAtCompileTime)
55 : int(DstFlags)&
RowMajorBit ? int(Dst::MaxColsAtCompileTime)
56 : int(Dst::MaxRowsAtCompileTime),
58 MaxSizeAtCompileTime = Dst::SizeAtCompileTime,
65 StorageOrdersAgree = (int(DstIsRowMajor) == int(SrcIsRowMajor)),
66 MightVectorize = StorageOrdersAgree
67 && (
int(DstFlags) & int(SrcFlags) & ActualPacketAccessBit)
70 && int(InnerSize) != Dynamic && int(InnerSize) % int(PacketSize) == 0
72 && int(JointAlignment) >= int(RequiredAlignment),
74 MayLinearVectorize = MightVectorize != 0 &&
MayLinearize != 0 && DstHasDirectAccess != 0
75 && ((
int(DstAlignment) >=
int(RequiredAlignment)) || MaxSizeAtCompileTime == Dynamic),
79 && (
int(InnerMaxSize) == Dynamic || int(InnerMaxSize) >= 3 * PacketSize)
88 : int(MayLinearVectorize) ? int(LinearVectorizedTraversal)
91 : int(DefaultTraversal),
92 Vectorized = int(Traversal) == InnerVectorizedTraversal
93 || int(Traversal) == LinearVectorizedTraversal
94 || int(Traversal) == SliceVectorizedTraversal
99 UnrollingLimit = EIGEN_UNROLLING_LIMIT * (Vectorized ? int(PacketSize) : 1),
101 && int(Dst::SizeAtCompileTime) * int(SrcEvaluator::CoeffReadCost) <= int(UnrollingLimit),
103 && int(InnerSize) * int(SrcEvaluator::CoeffReadCost) <= int(UnrollingLimit)
108 Unrolling = (int(Traversal) == int(InnerVectorizedTraversal) || int(Traversal) == int(DefaultTraversal))
114 : int(Traversal) == int(LinearVectorizedTraversal)
115 ? (bool(
MayUnrollCompletely) && (int(DstAlignment) >= int(RequiredAlignment)) ?
int(CompleteUnrolling)
117 : int(Traversal) == int(LinearTraversal)
123#ifdef EIGEN_DEBUG_ASSIGN
126 std::cerr <<
"DstXpr: " <<
typeid(
typename DstEvaluator::XprType).name() << std::endl;
127 std::cerr <<
"SrcXpr: " <<
typeid(
typename SrcEvaluator::XprType).name() << std::endl;
128 std::cerr.setf(std::ios::hex, std::ios::basefield);
129 std::cerr <<
"DstFlags" <<
" = " << DstFlags <<
" (" <<
demangle_flags(DstFlags) <<
" )" << std::endl;
130 std::cerr <<
"SrcFlags" <<
" = " << SrcFlags <<
" (" <<
demangle_flags(SrcFlags) <<
" )" << std::endl;
131 std::cerr.unsetf(std::ios::hex);
132 EIGEN_DEBUG_VAR(DstAlignment)
133 EIGEN_DEBUG_VAR(SrcAlignment)
134 EIGEN_DEBUG_VAR(RequiredAlignment)
135 EIGEN_DEBUG_VAR(JointAlignment)
136 EIGEN_DEBUG_VAR(InnerSize)
137 EIGEN_DEBUG_VAR(InnerMaxSize)
138 EIGEN_DEBUG_VAR(PacketSize)
139 EIGEN_DEBUG_VAR(StorageOrdersAgree)
140 EIGEN_DEBUG_VAR(MightVectorize)
143 EIGEN_DEBUG_VAR(MayLinearVectorize)
145 std::cerr <<
"Traversal" <<
" = " << Traversal <<
" (" <<
demangle_traversal(Traversal) <<
")" << std::endl;
146 EIGEN_DEBUG_VAR(UnrollingLimit)
149 std::cerr <<
"Unrolling" <<
" = " << Unrolling <<
" (" <<
demangle_unrolling(Unrolling) <<
")" << std::endl;
150 std::cerr << std::endl;
163 template<
typename Kernel,
int Index,
int Stop>
167 typedef typename Kernel::DstEvaluatorType DstEvaluatorType;
168 typedef typename DstEvaluatorType::XprType DstXprType;
171 outer = Index / DstXprType::InnerSizeAtCompileTime,
172 inner = Index % DstXprType::InnerSizeAtCompileTime
177 kernel.assignCoeffByOuterInner(outer, inner);
182 template<
typename Kernel,
int Stop>
188 template<
typename Kernel,
int Index_,
int Stop>
193 kernel.assignCoeffByOuterInner(outer,
Index_);
198 template<
typename Kernel,
int Stop>
208 template<
typename Kernel,
int Index,
int Stop>
213 kernel.assignCoeff(Index);
218 template<
typename Kernel,
int Stop>
228 template<
typename Kernel,
int Index,
int Stop>
232 typedef typename Kernel::DstEvaluatorType DstEvaluatorType;
233 typedef typename DstEvaluatorType::XprType DstXprType;
234 typedef typename Kernel::PacketType PacketType;
237 outer = Index / DstXprType::InnerSizeAtCompileTime,
238 inner = Index % DstXprType::InnerSizeAtCompileTime,
239 JointAlignment = Kernel::AssignmentTraits::JointAlignment
250 template<
typename Kernel,
int Stop>
256 template<
typename Kernel,
int Index_,
int Stop>
259 typedef typename Kernel::PacketType PacketType;
268 template<
typename Kernel,
int Stop>
281 int Traversal = Kernel::AssignmentTraits::Traversal,
282 int Unrolling = Kernel::AssignmentTraits::Unrolling>
289 template<
typename Kernel>
294 for (Index outer = 0; outer < kernel.outerSize(); ++outer) {
295 for (Index inner = 0; inner < kernel.innerSize(); ++inner) {
296 kernel.assignCoeffByOuterInner(outer, inner);
302 template<
typename Kernel>
307 typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
312 template<
typename Kernel>
317 typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
319 const Index outerSize = kernel.outerSize();
320 for (Index outer = 0; outer < outerSize; ++outer)
333 template <
bool IsAligned = false>
337 template <
typename Kernel>
348 template <
typename Kernel>
349 static EIGEN_DONT_INLINE
void run(
Kernel &kernel,
353 template <
typename Kernel>
359 for (Index index = start; index < end; ++index)
360 kernel.assignCoeff(index);
364 template<
typename Kernel>
369 const Index size = kernel.size();
370 typedef typename Kernel::Scalar Scalar;
371 typedef typename Kernel::PacketType PacketType;
377 : int(Kernel::AssignmentTraits::DstAlignment),
380 const Index
alignedStart =
dstIsAligned ? 0 : internal::first_aligned<requestedAlignment>(&kernel.dstEvaluator().coeffRef(0), size);
392 template<
typename Kernel>
397 typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
400 size = DstXprType::SizeAtCompileTime,
414 template<
typename Kernel>
417 typedef typename Kernel::PacketType PacketType;
420 const Index innerSize = kernel.innerSize();
421 const Index outerSize = kernel.outerSize();
423 for (Index outer = 0; outer < outerSize; ++outer)
424 for (Index inner = 0; inner < innerSize; inner +=
packetSize)
429 template<
typename Kernel>
434 typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
439 template<
typename Kernel>
444 typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
445 const Index outerSize = kernel.outerSize();
446 for (Index outer = 0; outer < outerSize; ++outer)
455 template<
typename Kernel>
460 const Index size = kernel.size();
461 for (Index i = 0; i < size; ++i)
462 kernel.assignCoeff(i);
466 template<
typename Kernel>
471 typedef typename Kernel::DstEvaluatorType::XprType DstXprType;
480 template<
typename Kernel>
485 typedef typename Kernel::Scalar Scalar;
486 typedef typename Kernel::PacketType PacketType;
493 : int(Kernel::AssignmentTraits::DstAlignment)
495 const Scalar *
dst_ptr = &kernel.dstEvaluator().coeffRef(0, 0);
502 const Index innerSize = kernel.innerSize();
503 const Index outerSize = kernel.outerSize();
507 for (Index outer = 0; outer < outerSize; ++outer)
512 kernel.assignCoeffByOuterInner(outer, inner);
519 for (Index inner =
alignedEnd; inner < innerSize; ++inner)
520 kernel.assignCoeffByOuterInner(outer, inner);
537 template<
typename DstEvaluatorTypeT,
typename SrcEvaluatorTypeT,
typename Functor,
int Version = Specialized>
541 typedef typename DstEvaluatorTypeT::XprType DstXprType;
542 typedef typename SrcEvaluatorTypeT::XprType SrcXprType;
547 typedef typename DstEvaluatorType::Scalar Scalar;
549 typedef typename AssignmentTraits::PacketType PacketType;
553 : m_dst(
dst), m_src(
src), m_functor(func), m_dstExpr(
dstExpr)
555#ifdef EIGEN_DEBUG_ASSIGN
556 AssignmentTraits::debug();
573 m_functor.assignCoeff(m_dst.coeffRef(row, col), m_src.coeff(row, col));
579 m_functor.assignCoeff(m_dst.coeffRef(index), m_src.coeff(index));
585 Index row = rowIndexByOuterInner(outer, inner);
586 Index col = colIndexByOuterInner(outer, inner);
591 template<
int StoreMode,
int LoadMode,
typename PacketType>
597 template<
int StoreMode,
int LoadMode,
typename PacketType>
603 template<
int StoreMode,
int LoadMode,
typename PacketType>
604 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void assignPacketByOuterInner(Index outer, Index inner)
606 Index row = rowIndexByOuterInner(outer, inner);
607 Index col = colIndexByOuterInner(outer, inner);
608 assignPacket<StoreMode, LoadMode, PacketType>(row, col);
611 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner)
613 typedef typename DstEvaluatorType::ExpressionTraits Traits;
614 return int(Traits::RowsAtCompileTime) == 1 ? 0
615 : int(Traits::ColsAtCompileTime) == 1 ? inner
620 EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE Index colIndexByOuterInner(Index outer, Index inner)
622 typedef typename DstEvaluatorType::ExpressionTraits Traits;
623 return int(Traits::ColsAtCompileTime) == 1 ? 0
624 : int(Traits::RowsAtCompileTime) == 1 ? inner
630 DstEvaluatorType & m_dst;
631 const SrcEvaluatorType& m_src;
632 const Functor &m_functor;
634 DstXprType& m_dstExpr;
641 template<
typename DstXprType,
typename SrcXprType,
typename Functor>
642 EIGEN_DEVICE_FUNC
void call_dense_assignment_loop(
const DstXprType& dst,
const SrcXprType& src,
const Functor &func)
644 eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
646 typedef evaluator<DstXprType> DstEvaluatorType;
647 typedef evaluator<SrcXprType> SrcEvaluatorType;
649 DstEvaluatorType dstEvaluator(dst);
650 SrcEvaluatorType srcEvaluator(src);
652 typedef generic_dense_assignment_kernel<DstEvaluatorType, SrcEvaluatorType, Functor>
Kernel;
653 Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived());
655 dense_assignment_loop<Kernel>::run(kernel);
658 template<
typename DstXprType,
typename SrcXprType>
659 EIGEN_DEVICE_FUNC
void call_dense_assignment_loop(
const DstXprType& dst,
const SrcXprType& src)
661 call_dense_assignment_loop(dst, src, internal::assign_op<typename DstXprType::Scalar>());
671 template<
typename DstShape,
typename SrcShape>
struct AssignmentKind;
681 template<
typename DstXprType,
typename SrcXprType,
typename Functor,
683 typename Scalar =
typename DstXprType::Scalar>
692 template<
typename Dst,
typename Src>
697 template<
typename Dst,
typename Src>
704 template<
typename Dst,
typename Src,
typename Func>
705 EIGEN_DEVICE_FUNC void call_assignment(Dst&
dst,
const Src&
src,
const Func& func,
typename enable_if<evaluator_traits<Src>::AssumeAliasing == 1,
void*>::type = 0)
707 typename plain_matrix_type<Src>::type tmp(
src);
708 call_assignment_no_alias(
dst, tmp, func);
711 template<
typename Dst,
typename Src,
typename Func>
712 EIGEN_DEVICE_FUNC
void call_assignment(Dst& dst,
const Src& src,
const Func& func,
typename enable_if<evaluator_traits<Src>::AssumeAliasing == 0,
void*>::type = 0)
714 call_assignment_no_alias(dst, src, func);
719 template<
typename Dst,
template <
typename>
class StorageBase,
typename Src,
typename Func>
720 EIGEN_DEVICE_FUNC
void call_assignment(NoAlias<Dst, StorageBase>& dst,
const Src& src,
const Func& func)
722 call_assignment_no_alias(dst.expression(), src, func);
726 template<
typename Dst,
typename Src,
typename Func>
727 EIGEN_DEVICE_FUNC
void call_assignment_no_alias(Dst& dst,
const Src& src,
const Func& func)
730 NeedToTranspose = ((int(Dst::RowsAtCompileTime) == 1 && int(Src::ColsAtCompileTime) == 1)
731 || (
int(Dst::ColsAtCompileTime) == 1 && int(Src::RowsAtCompileTime) == 1)
732 ) && int(Dst::SizeAtCompileTime) != 1
735 Index dstRows = NeedToTranspose ? src.cols() : src.rows();
736 Index dstCols = NeedToTranspose ? src.rows() : src.cols();
737 if ((dst.rows() != dstRows) || (dst.cols() != dstCols))
738 dst.resize(dstRows, dstCols);
740 typedef typename internal::conditional<NeedToTranspose, Transpose<Dst>, Dst>::type ActualDstTypeCleaned;
741 typedef typename internal::conditional<NeedToTranspose, Transpose<Dst>, Dst&>::type ActualDstType;
742 ActualDstType actualDst(dst);
745 EIGEN_STATIC_ASSERT_LVALUE(Dst)
746 EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(ActualDstTypeCleaned, Src)
747 EIGEN_CHECK_BINARY_COMPATIBILIY(Func,
typename ActualDstTypeCleaned::Scalar,
typename Src::Scalar);
749 Assignment<ActualDstTypeCleaned, Src, Func>::run(actualDst, src, func);
751 template<
typename Dst,
typename Src>
752 EIGEN_DEVICE_FUNC
void call_assignment_no_alias(Dst& dst,
const Src& src)
754 call_assignment_no_alias(dst, src, internal::assign_op<typename Dst::Scalar>());
757 template<
typename Dst,
typename Src,
typename Func>
758 EIGEN_DEVICE_FUNC
void call_assignment_no_alias_no_transpose(Dst& dst,
const Src& src,
const Func& func)
760 Index dstRows = src.rows();
761 Index dstCols = src.cols();
762 if ((dst.rows() != dstRows) || (dst.cols() != dstCols))
763 dst.resize(dstRows, dstCols);
766 EIGEN_STATIC_ASSERT_LVALUE(Dst)
767 EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Dst, Src)
769 Assignment<Dst, Src, Func>::run(dst, src, func);
771 template<
typename Dst,
typename Src>
772 EIGEN_DEVICE_FUNC
void call_assignment_no_alias_no_transpose(Dst& dst,
const Src& src)
774 call_assignment_no_alias_no_transpose(dst, src, internal::assign_op<typename Dst::Scalar>());
778 template<
typename Dst,
typename Src>
void check_for_aliasing(
const Dst &dst,
const Src &src);
781 template<
typename DstXprType,
typename SrcXprType,
typename Functor,
typename Scalar>
786 eigen_assert(
dst.rows() ==
src.rows() &&
dst.cols() ==
src.cols());
788#ifndef EIGEN_NO_DEBUG
789 internal::check_for_aliasing(
dst,
src);
792 call_dense_assignment_loop(
dst,
src, func);
798 template<
typename DstXprType,
typename SrcXprType,
typename Functor,
typename Scalar>
803 eigen_assert(
dst.rows() ==
src.rows() &&
dst.cols() ==
src.cols());
Convenience specialization of Stride to specify only an outer stride See class Map for some examples.
Definition Stride.h:102
Pseudo expression representing a solving operation.
Definition Solve.h:63
Definition AssignEvaluator.h:539
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Index row, Index col)
Assign src(row,col) to dst(row,col) through the assignment functor.
Definition AssignEvaluator.h:571
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Index index)
Definition AssignEvaluator.h:577
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeffByOuterInner(Index outer, Index inner)
Definition AssignEvaluator.h:583
const unsigned int LinearAccessBit
Short version: means the expression can be seen as 1D vector.
Definition Constants.h:124
const unsigned int DirectAccessBit
Means that the underlying array of coefficients can be directly accessed as a plain strided array.
Definition Constants.h:149
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 AssignEvaluator.h:677
Definition AssignEvaluator.h:684
Definition AssignEvaluator.h:674
Definition AssignEvaluator.h:675
Definition AssignmentFunctors.h:21
Definition AssignEvaluator.h:165
Definition AssignEvaluator.h:190
Definition AssignEvaluator.h:210
Definition AssignEvaluator.h:230
Definition AssignEvaluator.h:258
Definition AssignEvaluator.h:29
Definition AssignEvaluator.h:283
Definition XprHelper.h:107
Definition DenseCoeffsBase.h:643
Definition GenericPacketMath.h:90
Definition AssignEvaluator.h:335
Definition XprHelper.h:119