12 #ifndef EIGEN_ASSIGN_H 13 #define EIGEN_ASSIGN_H 23 template <
typename Derived,
typename OtherDerived>
30 SrcIsAligned = OtherDerived::Flags &
AlignedBit,
31 JointAlignment = bool(DstIsAligned) && bool(SrcIsAligned) ?
Aligned :
Unaligned 36 InnerSize = int(Derived::IsVectorAtCompileTime) ? int(Derived::SizeAtCompileTime)
37 : int(Derived::Flags)&
RowMajorBit ? int(Derived::ColsAtCompileTime)
38 : int(Derived::RowsAtCompileTime),
39 InnerMaxSize = int(Derived::IsVectorAtCompileTime) ? int(Derived::MaxSizeAtCompileTime)
40 : int(Derived::Flags)&
RowMajorBit ? int(Derived::MaxColsAtCompileTime)
41 : int(Derived::MaxRowsAtCompileTime),
42 MaxSizeAtCompileTime = Derived::SizeAtCompileTime,
47 StorageOrdersAgree = (int(Derived::IsRowMajor) == int(OtherDerived::IsRowMajor)),
48 MightVectorize = StorageOrdersAgree
49 && (
int(Derived::Flags) & int(OtherDerived::Flags) & ActualPacketAccessBit),
50 MayInnerVectorize = MightVectorize &&
int(InnerSize)!=
Dynamic && int(InnerSize)%int(PacketSize)==0
51 && int(DstIsAligned) && int(SrcIsAligned),
52 MayLinearize = StorageOrdersAgree && (int(Derived::Flags) & int(OtherDerived::Flags) &
LinearAccessBit),
53 MayLinearVectorize = MightVectorize && MayLinearize && DstHasDirectAccess
54 && (DstIsAligned || MaxSizeAtCompileTime ==
Dynamic),
57 MaySliceVectorize = MightVectorize && DstHasDirectAccess
58 && (int(InnerMaxSize)==
Dynamic || int(InnerMaxSize)>=3*PacketSize)
66 Traversal = int(MayInnerVectorize) ? int(InnerVectorizedTraversal)
67 : int(MayLinearVectorize) ? int(LinearVectorizedTraversal)
68 : int(MaySliceVectorize) ? int(SliceVectorizedTraversal)
69 : int(MayLinearize) ? int(LinearTraversal)
70 : int(DefaultTraversal),
71 Vectorized = int(Traversal) == InnerVectorizedTraversal
72 || int(Traversal) == LinearVectorizedTraversal
73 || int(Traversal) == SliceVectorizedTraversal
78 UnrollingLimit = EIGEN_UNROLLING_LIMIT * (Vectorized ? int(PacketSize) : 1),
79 MayUnrollCompletely =
int(Derived::SizeAtCompileTime) !=
Dynamic 80 && int(OtherDerived::CoeffReadCost) !=
Dynamic 81 && int(Derived::SizeAtCompileTime) * int(OtherDerived::CoeffReadCost) <= int(UnrollingLimit),
82 MayUnrollInner = int(InnerSize) !=
Dynamic 83 && int(OtherDerived::CoeffReadCost) !=
Dynamic 84 && int(InnerSize) * int(OtherDerived::CoeffReadCost) <= int(UnrollingLimit)
89 Unrolling = (int(Traversal) == int(InnerVectorizedTraversal) || int(Traversal) == int(DefaultTraversal))
91 int(MayUnrollCompletely) ? int(CompleteUnrolling)
92 : int(MayUnrollInner) ? int(InnerUnrolling)
95 :
int(Traversal) == int(LinearVectorizedTraversal)
96 ? ( bool(MayUnrollCompletely) && bool(DstIsAligned) ? int(CompleteUnrolling) : int(NoUnrolling) )
97 :
int(Traversal) == int(LinearTraversal)
98 ? ( bool(MayUnrollCompletely) ? int(CompleteUnrolling) : int(NoUnrolling) )
102 #ifdef EIGEN_DEBUG_ASSIGN 105 EIGEN_DEBUG_VAR(DstIsAligned)
106 EIGEN_DEBUG_VAR(SrcIsAligned)
107 EIGEN_DEBUG_VAR(JointAlignment)
108 EIGEN_DEBUG_VAR(InnerSize)
109 EIGEN_DEBUG_VAR(InnerMaxSize)
110 EIGEN_DEBUG_VAR(PacketSize)
111 EIGEN_DEBUG_VAR(StorageOrdersAgree)
112 EIGEN_DEBUG_VAR(MightVectorize)
113 EIGEN_DEBUG_VAR(MayLinearize)
114 EIGEN_DEBUG_VAR(MayInnerVectorize)
115 EIGEN_DEBUG_VAR(MayLinearVectorize)
116 EIGEN_DEBUG_VAR(MaySliceVectorize)
117 EIGEN_DEBUG_VAR(Traversal)
118 EIGEN_DEBUG_VAR(UnrollingLimit)
119 EIGEN_DEBUG_VAR(MayUnrollCompletely)
120 EIGEN_DEBUG_VAR(MayUnrollInner)
121 EIGEN_DEBUG_VAR(Unrolling)
134 template<
typename Derived1,
typename Derived2,
int Index,
int Stop>
138 outer = Index / Derived1::InnerSizeAtCompileTime,
139 inner = Index % Derived1::InnerSizeAtCompileTime
142 static EIGEN_STRONG_INLINE
void run(Derived1 &dst,
const Derived2 &src)
144 dst.copyCoeffByOuterInner(outer, inner, src);
149 template<
typename Derived1,
typename Derived2,
int Stop>
152 static EIGEN_STRONG_INLINE
void run(Derived1 &,
const Derived2 &) {}
155 template<
typename Derived1,
typename Derived2,
int Index,
int Stop>
158 static EIGEN_STRONG_INLINE
void run(Derived1 &dst,
const Derived2 &src,
typename Derived1::Index outer)
160 dst.copyCoeffByOuterInner(outer, Index, src);
165 template<
typename Derived1,
typename Derived2,
int Stop>
168 static EIGEN_STRONG_INLINE
void run(Derived1 &,
const Derived2 &,
typename Derived1::Index) {}
175 template<
typename Derived1,
typename Derived2,
int Index,
int Stop>
178 static EIGEN_STRONG_INLINE
void run(Derived1 &dst,
const Derived2 &src)
180 dst.copyCoeff(Index, src);
185 template<
typename Derived1,
typename Derived2,
int Stop>
188 static EIGEN_STRONG_INLINE
void run(Derived1 &,
const Derived2 &) {}
195 template<
typename Derived1,
typename Derived2,
int Index,
int Stop>
199 outer = Index / Derived1::InnerSizeAtCompileTime,
200 inner = Index % Derived1::InnerSizeAtCompileTime,
204 static EIGEN_STRONG_INLINE
void run(Derived1 &dst,
const Derived2 &src)
206 dst.template copyPacketByOuterInner<Derived2, Aligned, JointAlignment>(outer, inner, src);
212 template<
typename Derived1,
typename Derived2,
int Stop>
215 static EIGEN_STRONG_INLINE
void run(Derived1 &,
const Derived2 &) {}
218 template<
typename Derived1,
typename Derived2,
int Index,
int Stop>
221 static EIGEN_STRONG_INLINE
void run(Derived1 &dst,
const Derived2 &src,
typename Derived1::Index outer)
223 dst.template copyPacketByOuterInner<Derived2, Aligned, Aligned>(outer, Index, src);
229 template<
typename Derived1,
typename Derived2,
int Stop>
232 static EIGEN_STRONG_INLINE
void run(Derived1 &,
const Derived2 &,
typename Derived1::Index) {}
239 template<
typename Derived1,
typename Derived2,
242 int Version = Specialized>
249 template<
typename Derived1,
typename Derived2,
int Unrolling,
int Version>
250 struct assign_impl<Derived1, Derived2, InvalidTraversal, Unrolling, Version>
252 static inline void run(Derived1 &,
const Derived2 &) { }
255 template<
typename Derived1,
typename Derived2,
int Version>
256 struct assign_impl<Derived1, Derived2, DefaultTraversal, NoUnrolling, Version>
258 typedef typename Derived1::Index Index;
259 static inline void run(Derived1 &dst,
const Derived2 &src)
261 const Index innerSize = dst.innerSize();
262 const Index outerSize = dst.outerSize();
263 for(Index outer = 0; outer < outerSize; ++outer)
264 for(Index inner = 0; inner < innerSize; ++inner)
265 dst.copyCoeffByOuterInner(outer, inner, src);
269 template<
typename Derived1,
typename Derived2,
int Version>
270 struct assign_impl<Derived1, Derived2, DefaultTraversal, CompleteUnrolling, Version>
272 static EIGEN_STRONG_INLINE
void run(Derived1 &dst,
const Derived2 &src)
279 template<
typename Derived1,
typename Derived2,
int Version>
280 struct assign_impl<Derived1, Derived2, DefaultTraversal, InnerUnrolling, Version>
282 typedef typename Derived1::Index Index;
283 static EIGEN_STRONG_INLINE
void run(Derived1 &dst,
const Derived2 &src)
285 const Index outerSize = dst.outerSize();
286 for(Index outer = 0; outer < outerSize; ++outer)
288 ::run(dst, src, outer);
296 template<
typename Derived1,
typename Derived2,
int Version>
297 struct assign_impl<Derived1, Derived2, LinearTraversal, NoUnrolling, Version>
299 typedef typename Derived1::Index Index;
300 static inline void run(Derived1 &dst,
const Derived2 &src)
302 const Index
size = dst.size();
303 for(Index i = 0; i <
size; ++i)
304 dst.copyCoeff(i, src);
308 template<
typename Derived1,
typename Derived2,
int Version>
309 struct assign_impl<Derived1, Derived2, LinearTraversal, CompleteUnrolling, Version>
311 static EIGEN_STRONG_INLINE
void run(Derived1 &dst,
const Derived2 &src)
322 template<
typename Derived1,
typename Derived2,
int Version>
323 struct assign_impl<Derived1, Derived2, InnerVectorizedTraversal, NoUnrolling, Version>
325 typedef typename Derived1::Index Index;
326 static inline void run(Derived1 &dst,
const Derived2 &src)
328 const Index innerSize = dst.innerSize();
329 const Index outerSize = dst.outerSize();
331 for(Index outer = 0; outer < outerSize; ++outer)
332 for(Index inner = 0; inner < innerSize; inner+=packetSize)
333 dst.template copyPacketByOuterInner<Derived2, Aligned, Aligned>(outer, inner, src);
337 template<
typename Derived1,
typename Derived2,
int Version>
338 struct assign_impl<Derived1, Derived2, InnerVectorizedTraversal, CompleteUnrolling, Version>
340 static EIGEN_STRONG_INLINE
void run(Derived1 &dst,
const Derived2 &src)
347 template<
typename Derived1,
typename Derived2,
int Version>
348 struct assign_impl<Derived1, Derived2, InnerVectorizedTraversal, InnerUnrolling, Version>
350 typedef typename Derived1::Index Index;
351 static EIGEN_STRONG_INLINE
void run(Derived1 &dst,
const Derived2 &src)
353 const Index outerSize = dst.outerSize();
354 for(Index outer = 0; outer < outerSize; ++outer)
356 ::run(dst, src, outer);
364 template <
bool IsAligned = false>
367 template <
typename Derived,
typename OtherDerived>
368 static EIGEN_STRONG_INLINE
void run(
const Derived&, OtherDerived&,
typename Derived::Index,
typename Derived::Index) {}
377 template <
typename Derived,
typename OtherDerived>
378 static EIGEN_DONT_INLINE
void run(
const Derived& src, OtherDerived& dst,
typename Derived::Index start,
typename Derived::Index end)
380 template <
typename Derived,
typename OtherDerived>
381 static EIGEN_STRONG_INLINE
void run(
const Derived& src, OtherDerived& dst,
typename Derived::Index start,
typename Derived::Index end)
384 for (
typename Derived::Index index = start; index < end; ++index)
385 dst.copyCoeff(index, src);
389 template<
typename Derived1,
typename Derived2,
int Version>
390 struct assign_impl<Derived1, Derived2, LinearVectorizedTraversal, NoUnrolling, Version>
392 typedef typename Derived1::Index Index;
393 static EIGEN_STRONG_INLINE
void run(Derived1 &dst,
const Derived2 &src)
395 const Index
size = dst.size();
403 : internal::first_aligned(&dst.coeffRef(0),
size);
404 const Index alignedEnd = alignedStart + ((size-alignedStart)/packetSize)*packetSize;
408 for(Index index = alignedStart; index < alignedEnd; index += packetSize)
410 dst.template copyPacket<Derived2, dstAlignment, srcAlignment>(index, src);
417 template<
typename Derived1,
typename Derived2,
int Version>
418 struct assign_impl<Derived1, Derived2, LinearVectorizedTraversal, CompleteUnrolling, Version>
420 typedef typename Derived1::Index Index;
421 static EIGEN_STRONG_INLINE
void run(Derived1 &dst,
const Derived2 &src)
423 enum {
size = Derived1::SizeAtCompileTime,
425 alignedSize = (
size/packetSize)*packetSize };
436 template<
typename Derived1,
typename Derived2,
int Version>
437 struct assign_impl<Derived1, Derived2, SliceVectorizedTraversal, NoUnrolling, Version>
439 typedef typename Derived1::Index Index;
440 static inline void run(Derived1 &dst,
const Derived2 &src)
446 alignable = PacketTraits::AlignedOnScalar,
448 dstAlignment = alignable ?
Aligned : int(dstIsAligned),
451 const Scalar *dst_ptr = &dst.coeffRef(0,0);
452 if((!
bool(dstIsAligned)) && (
size_t(dst_ptr) %
sizeof(Scalar))>0)
457 const Index packetAlignedMask = packetSize - 1;
458 const Index innerSize = dst.innerSize();
459 const Index outerSize = dst.outerSize();
460 const Index alignedStep = alignable ? (packetSize - dst.outerStride() % packetSize) & packetAlignedMask : 0;
461 Index alignedStart = ((!alignable) ||
bool(dstIsAligned)) ? 0 : internal::first_aligned(dst_ptr, innerSize);
463 for(Index outer = 0; outer < outerSize; ++outer)
465 const Index alignedEnd = alignedStart + ((innerSize-alignedStart) & ~packetAlignedMask);
467 for(Index inner = 0; inner<alignedStart ; ++inner)
468 dst.copyCoeffByOuterInner(outer, inner, src);
471 for(Index inner = alignedStart; inner<alignedEnd; inner+=packetSize)
472 dst.template copyPacketByOuterInner<Derived2, dstAlignment, Unaligned>(outer, inner, src);
475 for(Index inner = alignedEnd; inner<innerSize ; ++inner)
476 dst.copyCoeffByOuterInner(outer, inner, src);
478 alignedStart = std::min<Index>((alignedStart+alignedStep)%packetSize, innerSize);
489 template<
typename Derived>
490 template<
typename OtherDerived>
498 EIGEN_STATIC_ASSERT_LVALUE(Derived)
499 EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Derived,OtherDerived)
500 EIGEN_STATIC_ASSERT(SameType,YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
502 #ifdef EIGEN_DEBUG_ASSIGN 505 eigen_assert(rows() == other.rows() && cols() == other.cols());
507 :
int(InvalidTraversal)>::run(derived(),other.derived());
508 #ifndef EIGEN_NO_DEBUG 509 checkTransposeAliasing(other.derived());
516 template<
typename Derived,
typename OtherDerived,
518 bool NeedToTranspose = ((
int(Derived::RowsAtCompileTime) == 1 &&
int(OtherDerived::ColsAtCompileTime) == 1)
521 (int(Derived::ColsAtCompileTime) == 1 && int(OtherDerived::RowsAtCompileTime) == 1))
522 && int(Derived::SizeAtCompileTime) != 1>
525 template<
typename Derived,
typename OtherDerived>
527 static EIGEN_STRONG_INLINE Derived& run(Derived& dst,
const OtherDerived& other) {
return dst.lazyAssign(other.derived()); }
528 template<
typename ActualDerived,
typename ActualOtherDerived>
529 static EIGEN_STRONG_INLINE Derived& evalTo(ActualDerived& dst,
const ActualOtherDerived& other) { other.evalTo(dst);
return dst; }
531 template<
typename Derived,
typename OtherDerived>
533 static EIGEN_STRONG_INLINE Derived& run(Derived& dst,
const OtherDerived& other) {
return dst.lazyAssign(other.eval()); }
535 template<
typename Derived,
typename OtherDerived>
537 static EIGEN_STRONG_INLINE Derived& run(Derived& dst,
const OtherDerived& other) {
return dst.lazyAssign(other.transpose()); }
538 template<
typename ActualDerived,
typename ActualOtherDerived>
539 static EIGEN_STRONG_INLINE Derived& evalTo(ActualDerived& dst,
const ActualOtherDerived& other) {
Transpose<ActualDerived> dstTrans(dst); other.evalTo(dstTrans);
return dst; }
541 template<
typename Derived,
typename OtherDerived>
543 static EIGEN_STRONG_INLINE Derived& run(Derived& dst,
const OtherDerived& other) {
return dst.lazyAssign(other.transpose().eval()); }
548 template<
typename Derived>
549 template<
typename OtherDerived>
555 template<
typename Derived>
561 template<
typename Derived>
567 template<
typename Derived>
568 template <
typename OtherDerived>
574 template<
typename Derived>
575 template <
typename OtherDerived>
581 template<
typename Derived>
582 template<
typename OtherDerived>
590 #endif // EIGEN_ASSIGN_H Object is not correctly aligned for vectorization.
Definition: Constants.h:192
Expression of the transpose of a matrix.
Definition: Transpose.h:57
const unsigned int DirectAccessBit
Means that the underlying array of coefficients can be directly accessed as a plain strided array...
Definition: Constants.h:142
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Derived & derived()
Definition: EigenBase.h:34
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:53
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
Object is aligned for vectorization.
Definition: Constants.h:194
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:26
Definition: ReturnByValue.h:50
Definition: GenericPacketMath.h:71
const unsigned int AlignedBit
means the first coefficient packet is guaranteed to be aligned
Definition: Constants.h:147
detail::size< coerce_list< Ts... >> size
Get the size of a list (number of elements.)
Definition: Size.h:56
const unsigned int EvalBeforeAssigningBit
means the expression should be evaluated before any assignment
Definition: Constants.h:63
Definition: BandTriangularSolver.h:13
Derived & operator=(const DenseBase< OtherDerived > &other)
Copies other into *this.
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is stored in some runtime variable.
Definition: Constants.h:21
Derived & operator=(const MatrixBase &other)
Special case of the template operator=, in order to prevent the compiler from generating a default op...
Definition: Assign.h:562
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
const unsigned int LinearAccessBit
Short version: means the expression can be seen as 1D vector.
Definition: Constants.h:117
Definition: ForwardDeclarations.h:17
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48