Another set of UI messages fixes and tweaks! No functional changes.
[blender.git] / extern / Eigen3 / Eigen / src / Core / Assign.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2007 Michael Olbrich <michael.olbrich@gmx.net>
5 // Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
6 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
7 //
8 // Eigen is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 3 of the License, or (at your option) any later version.
12 //
13 // Alternatively, you can redistribute it and/or
14 // modify it under the terms of the GNU General Public License as
15 // published by the Free Software Foundation; either version 2 of
16 // the License, or (at your option) any later version.
17 //
18 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public
24 // License and a copy of the GNU General Public License along with
25 // Eigen. If not, see <http://www.gnu.org/licenses/>.
26
27 #ifndef EIGEN_ASSIGN_H
28 #define EIGEN_ASSIGN_H
29
30 namespace internal {
31
32 /***************************************************************************
33 * Part 1 : the logic deciding a strategy for traversal and unrolling       *
34 ***************************************************************************/
35
36 template <typename Derived, typename OtherDerived>
37 struct assign_traits
38 {
39 public:
40   enum {
41     DstIsAligned = Derived::Flags & AlignedBit,
42     DstHasDirectAccess = Derived::Flags & DirectAccessBit,
43     SrcIsAligned = OtherDerived::Flags & AlignedBit,
44     JointAlignment = bool(DstIsAligned) && bool(SrcIsAligned) ? Aligned : Unaligned
45   };
46
47 private:
48   enum {
49     InnerSize = int(Derived::IsVectorAtCompileTime) ? int(Derived::SizeAtCompileTime)
50               : int(Derived::Flags)&RowMajorBit ? int(Derived::ColsAtCompileTime)
51               : int(Derived::RowsAtCompileTime),
52     InnerMaxSize = int(Derived::IsVectorAtCompileTime) ? int(Derived::MaxSizeAtCompileTime)
53               : int(Derived::Flags)&RowMajorBit ? int(Derived::MaxColsAtCompileTime)
54               : int(Derived::MaxRowsAtCompileTime),
55     MaxSizeAtCompileTime = Derived::SizeAtCompileTime,
56     PacketSize = packet_traits<typename Derived::Scalar>::size
57   };
58
59   enum {
60     StorageOrdersAgree = (int(Derived::IsRowMajor) == int(OtherDerived::IsRowMajor)),
61     MightVectorize = StorageOrdersAgree
62                   && (int(Derived::Flags) & int(OtherDerived::Flags) & ActualPacketAccessBit),
63     MayInnerVectorize  = MightVectorize && int(InnerSize)!=Dynamic && int(InnerSize)%int(PacketSize)==0
64                        && int(DstIsAligned) && int(SrcIsAligned),
65     MayLinearize = StorageOrdersAgree && (int(Derived::Flags) & int(OtherDerived::Flags) & LinearAccessBit),
66     MayLinearVectorize = MightVectorize && MayLinearize && DstHasDirectAccess
67                        && (DstIsAligned || MaxSizeAtCompileTime == Dynamic),
68       /* If the destination isn't aligned, we have to do runtime checks and we don't unroll,
69          so it's only good for large enough sizes. */
70     MaySliceVectorize  = MightVectorize && DstHasDirectAccess
71                        && (int(InnerMaxSize)==Dynamic || int(InnerMaxSize)>=3*PacketSize)
72       /* slice vectorization can be slow, so we only want it if the slices are big, which is
73          indicated by InnerMaxSize rather than InnerSize, think of the case of a dynamic block
74          in a fixed-size matrix */
75   };
76
77 public:
78   enum {
79     Traversal = int(MayInnerVectorize)  ? int(InnerVectorizedTraversal)
80               : int(MayLinearVectorize) ? int(LinearVectorizedTraversal)
81               : int(MaySliceVectorize)  ? int(SliceVectorizedTraversal)
82               : int(MayLinearize)       ? int(LinearTraversal)
83                                         : int(DefaultTraversal),
84     Vectorized = int(Traversal) == InnerVectorizedTraversal
85               || int(Traversal) == LinearVectorizedTraversal
86               || int(Traversal) == SliceVectorizedTraversal
87   };
88
89 private:
90   enum {
91     UnrollingLimit      = EIGEN_UNROLLING_LIMIT * (Vectorized ? int(PacketSize) : 1),
92     MayUnrollCompletely = int(Derived::SizeAtCompileTime) != Dynamic
93                        && int(OtherDerived::CoeffReadCost) != Dynamic
94                        && int(Derived::SizeAtCompileTime) * int(OtherDerived::CoeffReadCost) <= int(UnrollingLimit),
95     MayUnrollInner      = int(InnerSize) != Dynamic
96                        && int(OtherDerived::CoeffReadCost) != Dynamic
97                        && int(InnerSize) * int(OtherDerived::CoeffReadCost) <= int(UnrollingLimit)
98   };
99
100 public:
101   enum {
102     Unrolling = (int(Traversal) == int(InnerVectorizedTraversal) || int(Traversal) == int(DefaultTraversal))
103                 ? (
104                     int(MayUnrollCompletely) ? int(CompleteUnrolling)
105                   : int(MayUnrollInner)      ? int(InnerUnrolling)
106                                              : int(NoUnrolling)
107                   )
108               : int(Traversal) == int(LinearVectorizedTraversal)
109                 ? ( bool(MayUnrollCompletely) && bool(DstIsAligned) ? int(CompleteUnrolling) : int(NoUnrolling) )
110               : int(Traversal) == int(LinearTraversal)
111                 ? ( bool(MayUnrollCompletely) ? int(CompleteUnrolling) : int(NoUnrolling) )
112               : int(NoUnrolling)
113   };
114
115 #ifdef EIGEN_DEBUG_ASSIGN
116   static void debug()
117   {
118     EIGEN_DEBUG_VAR(DstIsAligned)
119     EIGEN_DEBUG_VAR(SrcIsAligned)
120     EIGEN_DEBUG_VAR(JointAlignment)
121     EIGEN_DEBUG_VAR(InnerSize)
122     EIGEN_DEBUG_VAR(InnerMaxSize)
123     EIGEN_DEBUG_VAR(PacketSize)
124     EIGEN_DEBUG_VAR(StorageOrdersAgree)
125     EIGEN_DEBUG_VAR(MightVectorize)
126     EIGEN_DEBUG_VAR(MayLinearize)
127     EIGEN_DEBUG_VAR(MayInnerVectorize)
128     EIGEN_DEBUG_VAR(MayLinearVectorize)
129     EIGEN_DEBUG_VAR(MaySliceVectorize)
130     EIGEN_DEBUG_VAR(Traversal)
131     EIGEN_DEBUG_VAR(UnrollingLimit)
132     EIGEN_DEBUG_VAR(MayUnrollCompletely)
133     EIGEN_DEBUG_VAR(MayUnrollInner)
134     EIGEN_DEBUG_VAR(Unrolling)
135   }
136 #endif
137 };
138
139 /***************************************************************************
140 * Part 2 : meta-unrollers
141 ***************************************************************************/
142
143 /************************
144 *** Default traversal ***
145 ************************/
146
147 template<typename Derived1, typename Derived2, int Index, int Stop>
148 struct assign_DefaultTraversal_CompleteUnrolling
149 {
150   enum {
151     outer = Index / Derived1::InnerSizeAtCompileTime,
152     inner = Index % Derived1::InnerSizeAtCompileTime
153   };
154
155   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
156   {
157     dst.copyCoeffByOuterInner(outer, inner, src);
158     assign_DefaultTraversal_CompleteUnrolling<Derived1, Derived2, Index+1, Stop>::run(dst, src);
159   }
160 };
161
162 template<typename Derived1, typename Derived2, int Stop>
163 struct assign_DefaultTraversal_CompleteUnrolling<Derived1, Derived2, Stop, Stop>
164 {
165   EIGEN_STRONG_INLINE static void run(Derived1 &, const Derived2 &) {}
166 };
167
168 template<typename Derived1, typename Derived2, int Index, int Stop>
169 struct assign_DefaultTraversal_InnerUnrolling
170 {
171   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src, int outer)
172   {
173     dst.copyCoeffByOuterInner(outer, Index, src);
174     assign_DefaultTraversal_InnerUnrolling<Derived1, Derived2, Index+1, Stop>::run(dst, src, outer);
175   }
176 };
177
178 template<typename Derived1, typename Derived2, int Stop>
179 struct assign_DefaultTraversal_InnerUnrolling<Derived1, Derived2, Stop, Stop>
180 {
181   EIGEN_STRONG_INLINE static void run(Derived1 &, const Derived2 &, int) {}
182 };
183
184 /***********************
185 *** Linear traversal ***
186 ***********************/
187
188 template<typename Derived1, typename Derived2, int Index, int Stop>
189 struct assign_LinearTraversal_CompleteUnrolling
190 {
191   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
192   {
193     dst.copyCoeff(Index, src);
194     assign_LinearTraversal_CompleteUnrolling<Derived1, Derived2, Index+1, Stop>::run(dst, src);
195   }
196 };
197
198 template<typename Derived1, typename Derived2, int Stop>
199 struct assign_LinearTraversal_CompleteUnrolling<Derived1, Derived2, Stop, Stop>
200 {
201   EIGEN_STRONG_INLINE static void run(Derived1 &, const Derived2 &) {}
202 };
203
204 /**************************
205 *** Inner vectorization ***
206 **************************/
207
208 template<typename Derived1, typename Derived2, int Index, int Stop>
209 struct assign_innervec_CompleteUnrolling
210 {
211   enum {
212     outer = Index / Derived1::InnerSizeAtCompileTime,
213     inner = Index % Derived1::InnerSizeAtCompileTime,
214     JointAlignment = assign_traits<Derived1,Derived2>::JointAlignment
215   };
216
217   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
218   {
219     dst.template copyPacketByOuterInner<Derived2, Aligned, JointAlignment>(outer, inner, src);
220     assign_innervec_CompleteUnrolling<Derived1, Derived2,
221       Index+packet_traits<typename Derived1::Scalar>::size, Stop>::run(dst, src);
222   }
223 };
224
225 template<typename Derived1, typename Derived2, int Stop>
226 struct assign_innervec_CompleteUnrolling<Derived1, Derived2, Stop, Stop>
227 {
228   EIGEN_STRONG_INLINE static void run(Derived1 &, const Derived2 &) {}
229 };
230
231 template<typename Derived1, typename Derived2, int Index, int Stop>
232 struct assign_innervec_InnerUnrolling
233 {
234   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src, int outer)
235   {
236     dst.template copyPacketByOuterInner<Derived2, Aligned, Aligned>(outer, Index, src);
237     assign_innervec_InnerUnrolling<Derived1, Derived2,
238       Index+packet_traits<typename Derived1::Scalar>::size, Stop>::run(dst, src, outer);
239   }
240 };
241
242 template<typename Derived1, typename Derived2, int Stop>
243 struct assign_innervec_InnerUnrolling<Derived1, Derived2, Stop, Stop>
244 {
245   EIGEN_STRONG_INLINE static void run(Derived1 &, const Derived2 &, int) {}
246 };
247
248 /***************************************************************************
249 * Part 3 : implementation of all cases
250 ***************************************************************************/
251
252 template<typename Derived1, typename Derived2,
253          int Traversal = assign_traits<Derived1, Derived2>::Traversal,
254          int Unrolling = assign_traits<Derived1, Derived2>::Unrolling>
255 struct assign_impl;
256
257 /************************
258 *** Default traversal ***
259 ************************/
260
261 template<typename Derived1, typename Derived2, int Unrolling>
262 struct assign_impl<Derived1, Derived2, InvalidTraversal, Unrolling>
263 {
264   inline static void run(Derived1 &, const Derived2 &) { }
265 };
266
267 template<typename Derived1, typename Derived2>
268 struct assign_impl<Derived1, Derived2, DefaultTraversal, NoUnrolling>
269 {
270   typedef typename Derived1::Index Index;
271   inline static void run(Derived1 &dst, const Derived2 &src)
272   {
273     const Index innerSize = dst.innerSize();
274     const Index outerSize = dst.outerSize();
275     for(Index outer = 0; outer < outerSize; ++outer)
276       for(Index inner = 0; inner < innerSize; ++inner)
277         dst.copyCoeffByOuterInner(outer, inner, src);
278   }
279 };
280
281 template<typename Derived1, typename Derived2>
282 struct assign_impl<Derived1, Derived2, DefaultTraversal, CompleteUnrolling>
283 {
284   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
285   {
286     assign_DefaultTraversal_CompleteUnrolling<Derived1, Derived2, 0, Derived1::SizeAtCompileTime>
287       ::run(dst, src);
288   }
289 };
290
291 template<typename Derived1, typename Derived2>
292 struct assign_impl<Derived1, Derived2, DefaultTraversal, InnerUnrolling>
293 {
294   typedef typename Derived1::Index Index;
295   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
296   {
297     const Index outerSize = dst.outerSize();
298     for(Index outer = 0; outer < outerSize; ++outer)
299       assign_DefaultTraversal_InnerUnrolling<Derived1, Derived2, 0, Derived1::InnerSizeAtCompileTime>
300         ::run(dst, src, outer);
301   }
302 };
303
304 /***********************
305 *** Linear traversal ***
306 ***********************/
307
308 template<typename Derived1, typename Derived2>
309 struct assign_impl<Derived1, Derived2, LinearTraversal, NoUnrolling>
310 {
311   typedef typename Derived1::Index Index;
312   inline static void run(Derived1 &dst, const Derived2 &src)
313   {
314     const Index size = dst.size();
315     for(Index i = 0; i < size; ++i)
316       dst.copyCoeff(i, src);
317   }
318 };
319
320 template<typename Derived1, typename Derived2>
321 struct assign_impl<Derived1, Derived2, LinearTraversal, CompleteUnrolling>
322 {
323   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
324   {
325     assign_LinearTraversal_CompleteUnrolling<Derived1, Derived2, 0, Derived1::SizeAtCompileTime>
326       ::run(dst, src);
327   }
328 };
329
330 /**************************
331 *** Inner vectorization ***
332 **************************/
333
334 template<typename Derived1, typename Derived2>
335 struct assign_impl<Derived1, Derived2, InnerVectorizedTraversal, NoUnrolling>
336 {
337   typedef typename Derived1::Index Index;
338   inline static void run(Derived1 &dst, const Derived2 &src)
339   {
340     const Index innerSize = dst.innerSize();
341     const Index outerSize = dst.outerSize();
342     const Index packetSize = packet_traits<typename Derived1::Scalar>::size;
343     for(Index outer = 0; outer < outerSize; ++outer)
344       for(Index inner = 0; inner < innerSize; inner+=packetSize)
345         dst.template copyPacketByOuterInner<Derived2, Aligned, Aligned>(outer, inner, src);
346   }
347 };
348
349 template<typename Derived1, typename Derived2>
350 struct assign_impl<Derived1, Derived2, InnerVectorizedTraversal, CompleteUnrolling>
351 {
352   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
353   {
354     assign_innervec_CompleteUnrolling<Derived1, Derived2, 0, Derived1::SizeAtCompileTime>
355       ::run(dst, src);
356   }
357 };
358
359 template<typename Derived1, typename Derived2>
360 struct assign_impl<Derived1, Derived2, InnerVectorizedTraversal, InnerUnrolling>
361 {
362   typedef typename Derived1::Index Index;
363   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
364   {
365     const Index outerSize = dst.outerSize();
366     for(Index outer = 0; outer < outerSize; ++outer)
367       assign_innervec_InnerUnrolling<Derived1, Derived2, 0, Derived1::InnerSizeAtCompileTime>
368         ::run(dst, src, outer);
369   }
370 };
371
372 /***************************
373 *** Linear vectorization ***
374 ***************************/
375
376 template <bool IsAligned = false>
377 struct unaligned_assign_impl
378 {
379   template <typename Derived, typename OtherDerived>
380   static EIGEN_STRONG_INLINE void run(const Derived&, OtherDerived&, typename Derived::Index, typename Derived::Index) {}
381 };
382
383 template <>
384 struct unaligned_assign_impl<false>
385 {
386   // MSVC must not inline this functions. If it does, it fails to optimize the
387   // packet access path.
388 #ifdef _MSC_VER
389   template <typename Derived, typename OtherDerived>
390   static EIGEN_DONT_INLINE void run(const Derived& src, OtherDerived& dst, typename Derived::Index start, typename Derived::Index end)
391 #else
392   template <typename Derived, typename OtherDerived>
393   static EIGEN_STRONG_INLINE void run(const Derived& src, OtherDerived& dst, typename Derived::Index start, typename Derived::Index end)
394 #endif
395   {
396     for (typename Derived::Index index = start; index < end; ++index)
397       dst.copyCoeff(index, src);
398   }
399 };
400
401 template<typename Derived1, typename Derived2>
402 struct assign_impl<Derived1, Derived2, LinearVectorizedTraversal, NoUnrolling>
403 {
404   typedef typename Derived1::Index Index;
405   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
406   {
407     const Index size = dst.size();
408     typedef packet_traits<typename Derived1::Scalar> PacketTraits;
409     enum {
410       packetSize = PacketTraits::size,
411       dstAlignment = PacketTraits::AlignedOnScalar ? Aligned : int(assign_traits<Derived1,Derived2>::DstIsAligned) ,
412       srcAlignment = assign_traits<Derived1,Derived2>::JointAlignment
413     };
414     const Index alignedStart = assign_traits<Derived1,Derived2>::DstIsAligned ? 0
415                              : first_aligned(&dst.coeffRef(0), size);
416     const Index alignedEnd = alignedStart + ((size-alignedStart)/packetSize)*packetSize;
417
418     unaligned_assign_impl<assign_traits<Derived1,Derived2>::DstIsAligned!=0>::run(src,dst,0,alignedStart);
419
420     for(Index index = alignedStart; index < alignedEnd; index += packetSize)
421     {
422       dst.template copyPacket<Derived2, dstAlignment, srcAlignment>(index, src);
423     }
424
425     unaligned_assign_impl<>::run(src,dst,alignedEnd,size);
426   }
427 };
428
429 template<typename Derived1, typename Derived2>
430 struct assign_impl<Derived1, Derived2, LinearVectorizedTraversal, CompleteUnrolling>
431 {
432   typedef typename Derived1::Index Index;
433   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
434   {
435     enum { size = Derived1::SizeAtCompileTime,
436            packetSize = packet_traits<typename Derived1::Scalar>::size,
437            alignedSize = (size/packetSize)*packetSize };
438
439     assign_innervec_CompleteUnrolling<Derived1, Derived2, 0, alignedSize>::run(dst, src);
440     assign_DefaultTraversal_CompleteUnrolling<Derived1, Derived2, alignedSize, size>::run(dst, src);
441   }
442 };
443
444 /**************************
445 *** Slice vectorization ***
446 ***************************/
447
448 template<typename Derived1, typename Derived2>
449 struct assign_impl<Derived1, Derived2, SliceVectorizedTraversal, NoUnrolling>
450 {
451   typedef typename Derived1::Index Index;
452   inline static void run(Derived1 &dst, const Derived2 &src)
453   {
454     typedef packet_traits<typename Derived1::Scalar> PacketTraits;
455     enum {
456       packetSize = PacketTraits::size,
457       alignable = PacketTraits::AlignedOnScalar,
458       dstAlignment = alignable ? Aligned : int(assign_traits<Derived1,Derived2>::DstIsAligned) ,
459       srcAlignment = assign_traits<Derived1,Derived2>::JointAlignment
460     };
461     const Index packetAlignedMask = packetSize - 1;
462     const Index innerSize = dst.innerSize();
463     const Index outerSize = dst.outerSize();
464     const Index alignedStep = alignable ? (packetSize - dst.outerStride() % packetSize) & packetAlignedMask : 0;
465     Index alignedStart = ((!alignable) || assign_traits<Derived1,Derived2>::DstIsAligned) ? 0
466                        : first_aligned(&dst.coeffRef(0,0), innerSize);
467
468     for(Index outer = 0; outer < outerSize; ++outer)
469     {
470       const Index alignedEnd = alignedStart + ((innerSize-alignedStart) & ~packetAlignedMask);
471       // do the non-vectorizable part of the assignment
472       for(Index inner = 0; inner<alignedStart ; ++inner)
473         dst.copyCoeffByOuterInner(outer, inner, src);
474
475       // do the vectorizable part of the assignment
476       for(Index inner = alignedStart; inner<alignedEnd; inner+=packetSize)
477         dst.template copyPacketByOuterInner<Derived2, dstAlignment, Unaligned>(outer, inner, src);
478
479       // do the non-vectorizable part of the assignment
480       for(Index inner = alignedEnd; inner<innerSize ; ++inner)
481         dst.copyCoeffByOuterInner(outer, inner, src);
482
483       alignedStart = std::min<Index>((alignedStart+alignedStep)%packetSize, innerSize);
484     }
485   }
486 };
487
488 } // end namespace internal
489
490 /***************************************************************************
491 * Part 4 : implementation of DenseBase methods
492 ***************************************************************************/
493
494 template<typename Derived>
495 template<typename OtherDerived>
496 EIGEN_STRONG_INLINE Derived& DenseBase<Derived>
497   ::lazyAssign(const DenseBase<OtherDerived>& other)
498 {
499   enum{
500     SameType = internal::is_same<typename Derived::Scalar,typename OtherDerived::Scalar>::value
501   };
502
503   EIGEN_STATIC_ASSERT_LVALUE(Derived)
504   EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Derived,OtherDerived)
505   EIGEN_STATIC_ASSERT(SameType,YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
506
507 #ifdef EIGEN_DEBUG_ASSIGN
508   internal::assign_traits<Derived, OtherDerived>::debug();
509 #endif
510   eigen_assert(rows() == other.rows() && cols() == other.cols());
511   internal::assign_impl<Derived, OtherDerived, int(SameType) ? int(internal::assign_traits<Derived, OtherDerived>::Traversal)
512                                                        : int(InvalidTraversal)>::run(derived(),other.derived());
513 #ifndef EIGEN_NO_DEBUG
514   checkTransposeAliasing(other.derived());
515 #endif
516   return derived();
517 }
518
519 namespace internal {
520
521 template<typename Derived, typename OtherDerived,
522          bool EvalBeforeAssigning = (int(OtherDerived::Flags) & EvalBeforeAssigningBit) != 0,
523          bool NeedToTranspose = Derived::IsVectorAtCompileTime
524                 && OtherDerived::IsVectorAtCompileTime
525                 && ((int(Derived::RowsAtCompileTime) == 1 && int(OtherDerived::ColsAtCompileTime) == 1)
526                       |  // FIXME | instead of || to please GCC 4.4.0 stupid warning "suggest parentheses around &&".
527                          // revert to || as soon as not needed anymore.
528                     (int(Derived::ColsAtCompileTime) == 1 && int(OtherDerived::RowsAtCompileTime) == 1))
529                 && int(Derived::SizeAtCompileTime) != 1>
530 struct assign_selector;
531
532 template<typename Derived, typename OtherDerived>
533 struct assign_selector<Derived,OtherDerived,false,false> {
534   EIGEN_STRONG_INLINE static Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.derived()); }
535 };
536 template<typename Derived, typename OtherDerived>
537 struct assign_selector<Derived,OtherDerived,true,false> {
538   EIGEN_STRONG_INLINE static Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.eval()); }
539 };
540 template<typename Derived, typename OtherDerived>
541 struct assign_selector<Derived,OtherDerived,false,true> {
542   EIGEN_STRONG_INLINE static Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.transpose()); }
543 };
544 template<typename Derived, typename OtherDerived>
545 struct assign_selector<Derived,OtherDerived,true,true> {
546   EIGEN_STRONG_INLINE static Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.transpose().eval()); }
547 };
548
549 } // end namespace internal
550
551 template<typename Derived>
552 template<typename OtherDerived>
553 EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::operator=(const DenseBase<OtherDerived>& other)
554 {
555   return internal::assign_selector<Derived,OtherDerived>::run(derived(), other.derived());
556 }
557
558 template<typename Derived>
559 EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::operator=(const DenseBase& other)
560 {
561   return internal::assign_selector<Derived,Derived>::run(derived(), other.derived());
562 }
563
564 template<typename Derived>
565 EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const MatrixBase& other)
566 {
567   return internal::assign_selector<Derived,Derived>::run(derived(), other.derived());
568 }
569
570 template<typename Derived>
571 template <typename OtherDerived>
572 EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const DenseBase<OtherDerived>& other)
573 {
574   return internal::assign_selector<Derived,OtherDerived>::run(derived(), other.derived());
575 }
576
577 template<typename Derived>
578 template <typename OtherDerived>
579 EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const EigenBase<OtherDerived>& other)
580 {
581   other.derived().evalTo(derived());
582   return derived();
583 }
584
585 template<typename Derived>
586 template<typename OtherDerived>
587 EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const ReturnByValue<OtherDerived>& other)
588 {
589   other.evalTo(derived());
590   return derived();
591 }
592
593 #endif // EIGEN_ASSIGN_H