Assign.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2007 Michael Olbrich <michael.olbrich@gmx.net>
00005 // Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
00006 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
00007 //
00008 // Eigen is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Lesser General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 3 of the License, or (at your option) any later version.
00012 //
00013 // Alternatively, you can redistribute it and/or
00014 // modify it under the terms of the GNU General Public License as
00015 // published by the Free Software Foundation; either version 2 of
00016 // the License, or (at your option) any later version.
00017 //
00018 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00019 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00020 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00021 // GNU General Public License for more details.
00022 //
00023 // You should have received a copy of the GNU Lesser General Public
00024 // License and a copy of the GNU General Public License along with
00025 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 #ifndef EIGEN_ASSIGN_H
00028 #define EIGEN_ASSIGN_H
00029 
00030 namespace internal {
00031 
00032 /***************************************************************************
00033 * Part 1 : the logic deciding a strategy for traversal and unrolling       *
00034 ***************************************************************************/
00035 
00036 template <typename Derived, typename OtherDerived>
00037 struct assign_traits
00038 {
00039 public:
00040   enum {
00041     DstIsAligned = Derived::Flags & AlignedBit,
00042     DstHasDirectAccess = Derived::Flags & DirectAccessBit,
00043     SrcIsAligned = OtherDerived::Flags & AlignedBit,
00044     JointAlignment = bool(DstIsAligned) && bool(SrcIsAligned) ? Aligned : Unaligned
00045   };
00046 
00047 private:
00048   enum {
00049     InnerSize = int(Derived::IsVectorAtCompileTime) ? int(Derived::SizeAtCompileTime)
00050               : int(Derived::Flags)&RowMajorBit ? int(Derived::ColsAtCompileTime)
00051               : int(Derived::RowsAtCompileTime),
00052     InnerMaxSize = int(Derived::IsVectorAtCompileTime) ? int(Derived::MaxSizeAtCompileTime)
00053               : int(Derived::Flags)&RowMajorBit ? int(Derived::MaxColsAtCompileTime)
00054               : int(Derived::MaxRowsAtCompileTime),
00055     MaxSizeAtCompileTime = Derived::SizeAtCompileTime,
00056     PacketSize = packet_traits<typename Derived::Scalar>::size
00057   };
00058 
00059   enum {
00060     StorageOrdersAgree = (int(Derived::IsRowMajor) == int(OtherDerived::IsRowMajor)),
00061     MightVectorize = StorageOrdersAgree
00062                   && (int(Derived::Flags) & int(OtherDerived::Flags) & ActualPacketAccessBit),
00063     MayInnerVectorize  = MightVectorize && int(InnerSize)!=Dynamic && int(InnerSize)%int(PacketSize)==0
00064                        && int(DstIsAligned) && int(SrcIsAligned),
00065     MayLinearize = StorageOrdersAgree && (int(Derived::Flags) & int(OtherDerived::Flags) & LinearAccessBit),
00066     MayLinearVectorize = MightVectorize && MayLinearize && DstHasDirectAccess
00067                        && (DstIsAligned || MaxSizeAtCompileTime == Dynamic),
00068       /* If the destination isn't aligned, we have to do runtime checks and we don't unroll,
00069          so it's only good for large enough sizes. */
00070     MaySliceVectorize  = MightVectorize && DstHasDirectAccess
00071                        && (int(InnerMaxSize)==Dynamic || int(InnerMaxSize)>=3*PacketSize)
00072       /* slice vectorization can be slow, so we only want it if the slices are big, which is
00073          indicated by InnerMaxSize rather than InnerSize, think of the case of a dynamic block
00074          in a fixed-size matrix */
00075   };
00076 
00077 public:
00078   enum {
00079     Traversal = int(MayInnerVectorize)  ? int(InnerVectorizedTraversal)
00080               : int(MayLinearVectorize) ? int(LinearVectorizedTraversal)
00081               : int(MaySliceVectorize)  ? int(SliceVectorizedTraversal)
00082               : int(MayLinearize)       ? int(LinearTraversal)
00083                                         : int(DefaultTraversal),
00084     Vectorized = int(Traversal) == InnerVectorizedTraversal
00085               || int(Traversal) == LinearVectorizedTraversal
00086               || int(Traversal) == SliceVectorizedTraversal
00087   };
00088 
00089 private:
00090   enum {
00091     UnrollingLimit      = EIGEN_UNROLLING_LIMIT * (Vectorized ? int(PacketSize) : 1),
00092     MayUnrollCompletely = int(Derived::SizeAtCompileTime) != Dynamic
00093                        && int(OtherDerived::CoeffReadCost) != Dynamic
00094                        && int(Derived::SizeAtCompileTime) * int(OtherDerived::CoeffReadCost) <= int(UnrollingLimit),
00095     MayUnrollInner      = int(InnerSize) != Dynamic
00096                        && int(OtherDerived::CoeffReadCost) != Dynamic
00097                        && int(InnerSize) * int(OtherDerived::CoeffReadCost) <= int(UnrollingLimit)
00098   };
00099 
00100 public:
00101   enum {
00102     Unrolling = (int(Traversal) == int(InnerVectorizedTraversal) || int(Traversal) == int(DefaultTraversal))
00103                 ? (
00104                     int(MayUnrollCompletely) ? int(CompleteUnrolling)
00105                   : int(MayUnrollInner)      ? int(InnerUnrolling)
00106                                              : int(NoUnrolling)
00107                   )
00108               : int(Traversal) == int(LinearVectorizedTraversal)
00109                 ? ( bool(MayUnrollCompletely) && bool(DstIsAligned) ? int(CompleteUnrolling) : int(NoUnrolling) )
00110               : int(Traversal) == int(LinearTraversal)
00111                 ? ( bool(MayUnrollCompletely) ? int(CompleteUnrolling) : int(NoUnrolling) )
00112               : int(NoUnrolling)
00113   };
00114 
00115 #ifdef EIGEN_DEBUG_ASSIGN
00116   static void debug()
00117   {
00118     EIGEN_DEBUG_VAR(DstIsAligned)
00119     EIGEN_DEBUG_VAR(SrcIsAligned)
00120     EIGEN_DEBUG_VAR(JointAlignment)
00121     EIGEN_DEBUG_VAR(InnerSize)
00122     EIGEN_DEBUG_VAR(InnerMaxSize)
00123     EIGEN_DEBUG_VAR(PacketSize)
00124     EIGEN_DEBUG_VAR(StorageOrdersAgree)
00125     EIGEN_DEBUG_VAR(MightVectorize)
00126     EIGEN_DEBUG_VAR(MayLinearize)
00127     EIGEN_DEBUG_VAR(MayInnerVectorize)
00128     EIGEN_DEBUG_VAR(MayLinearVectorize)
00129     EIGEN_DEBUG_VAR(MaySliceVectorize)
00130     EIGEN_DEBUG_VAR(Traversal)
00131     EIGEN_DEBUG_VAR(UnrollingLimit)
00132     EIGEN_DEBUG_VAR(MayUnrollCompletely)
00133     EIGEN_DEBUG_VAR(MayUnrollInner)
00134     EIGEN_DEBUG_VAR(Unrolling)
00135   }
00136 #endif
00137 };
00138 
00139 /***************************************************************************
00140 * Part 2 : meta-unrollers
00141 ***************************************************************************/
00142 
00143 /************************
00144 *** Default traversal ***
00145 ************************/
00146 
00147 template<typename Derived1, typename Derived2, int Index, int Stop>
00148 struct assign_DefaultTraversal_CompleteUnrolling
00149 {
00150   enum {
00151     outer = Index / Derived1::InnerSizeAtCompileTime,
00152     inner = Index % Derived1::InnerSizeAtCompileTime
00153   };
00154 
00155   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
00156   {
00157     dst.copyCoeffByOuterInner(outer, inner, src);
00158     assign_DefaultTraversal_CompleteUnrolling<Derived1, Derived2, Index+1, Stop>::run(dst, src);
00159   }
00160 };
00161 
00162 template<typename Derived1, typename Derived2, int Stop>
00163 struct assign_DefaultTraversal_CompleteUnrolling<Derived1, Derived2, Stop, Stop>
00164 {
00165   EIGEN_STRONG_INLINE static void run(Derived1 &, const Derived2 &) {}
00166 };
00167 
00168 template<typename Derived1, typename Derived2, int Index, int Stop>
00169 struct assign_DefaultTraversal_InnerUnrolling
00170 {
00171   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src, int outer)
00172   {
00173     dst.copyCoeffByOuterInner(outer, Index, src);
00174     assign_DefaultTraversal_InnerUnrolling<Derived1, Derived2, Index+1, Stop>::run(dst, src, outer);
00175   }
00176 };
00177 
00178 template<typename Derived1, typename Derived2, int Stop>
00179 struct assign_DefaultTraversal_InnerUnrolling<Derived1, Derived2, Stop, Stop>
00180 {
00181   EIGEN_STRONG_INLINE static void run(Derived1 &, const Derived2 &, int) {}
00182 };
00183 
00184 /***********************
00185 *** Linear traversal ***
00186 ***********************/
00187 
00188 template<typename Derived1, typename Derived2, int Index, int Stop>
00189 struct assign_LinearTraversal_CompleteUnrolling
00190 {
00191   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
00192   {
00193     dst.copyCoeff(Index, src);
00194     assign_LinearTraversal_CompleteUnrolling<Derived1, Derived2, Index+1, Stop>::run(dst, src);
00195   }
00196 };
00197 
00198 template<typename Derived1, typename Derived2, int Stop>
00199 struct assign_LinearTraversal_CompleteUnrolling<Derived1, Derived2, Stop, Stop>
00200 {
00201   EIGEN_STRONG_INLINE static void run(Derived1 &, const Derived2 &) {}
00202 };
00203 
00204 /**************************
00205 *** Inner vectorization ***
00206 **************************/
00207 
00208 template<typename Derived1, typename Derived2, int Index, int Stop>
00209 struct assign_innervec_CompleteUnrolling
00210 {
00211   enum {
00212     outer = Index / Derived1::InnerSizeAtCompileTime,
00213     inner = Index % Derived1::InnerSizeAtCompileTime,
00214     JointAlignment = assign_traits<Derived1,Derived2>::JointAlignment
00215   };
00216 
00217   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
00218   {
00219     dst.template copyPacketByOuterInner<Derived2, Aligned, JointAlignment>(outer, inner, src);
00220     assign_innervec_CompleteUnrolling<Derived1, Derived2,
00221       Index+packet_traits<typename Derived1::Scalar>::size, Stop>::run(dst, src);
00222   }
00223 };
00224 
00225 template<typename Derived1, typename Derived2, int Stop>
00226 struct assign_innervec_CompleteUnrolling<Derived1, Derived2, Stop, Stop>
00227 {
00228   EIGEN_STRONG_INLINE static void run(Derived1 &, const Derived2 &) {}
00229 };
00230 
00231 template<typename Derived1, typename Derived2, int Index, int Stop>
00232 struct assign_innervec_InnerUnrolling
00233 {
00234   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src, int outer)
00235   {
00236     dst.template copyPacketByOuterInner<Derived2, Aligned, Aligned>(outer, Index, src);
00237     assign_innervec_InnerUnrolling<Derived1, Derived2,
00238       Index+packet_traits<typename Derived1::Scalar>::size, Stop>::run(dst, src, outer);
00239   }
00240 };
00241 
00242 template<typename Derived1, typename Derived2, int Stop>
00243 struct assign_innervec_InnerUnrolling<Derived1, Derived2, Stop, Stop>
00244 {
00245   EIGEN_STRONG_INLINE static void run(Derived1 &, const Derived2 &, int) {}
00246 };
00247 
00248 /***************************************************************************
00249 * Part 3 : implementation of all cases
00250 ***************************************************************************/
00251 
00252 template<typename Derived1, typename Derived2,
00253          int Traversal = assign_traits<Derived1, Derived2>::Traversal,
00254          int Unrolling = assign_traits<Derived1, Derived2>::Unrolling>
00255 struct assign_impl;
00256 
00257 /************************
00258 *** Default traversal ***
00259 ************************/
00260 
00261 template<typename Derived1, typename Derived2, int Unrolling>
00262 struct assign_impl<Derived1, Derived2, InvalidTraversal, Unrolling>
00263 {
00264   inline static void run(Derived1 &, const Derived2 &) { }
00265 };
00266 
00267 template<typename Derived1, typename Derived2>
00268 struct assign_impl<Derived1, Derived2, DefaultTraversal, NoUnrolling>
00269 {
00270   typedef typename Derived1::Index Index;
00271   inline static void run(Derived1 &dst, const Derived2 &src)
00272   {
00273     const Index innerSize = dst.innerSize();
00274     const Index outerSize = dst.outerSize();
00275     for(Index outer = 0; outer < outerSize; ++outer)
00276       for(Index inner = 0; inner < innerSize; ++inner)
00277         dst.copyCoeffByOuterInner(outer, inner, src);
00278   }
00279 };
00280 
00281 template<typename Derived1, typename Derived2>
00282 struct assign_impl<Derived1, Derived2, DefaultTraversal, CompleteUnrolling>
00283 {
00284   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
00285   {
00286     assign_DefaultTraversal_CompleteUnrolling<Derived1, Derived2, 0, Derived1::SizeAtCompileTime>
00287       ::run(dst, src);
00288   }
00289 };
00290 
00291 template<typename Derived1, typename Derived2>
00292 struct assign_impl<Derived1, Derived2, DefaultTraversal, InnerUnrolling>
00293 {
00294   typedef typename Derived1::Index Index;
00295   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
00296   {
00297     const Index outerSize = dst.outerSize();
00298     for(Index outer = 0; outer < outerSize; ++outer)
00299       assign_DefaultTraversal_InnerUnrolling<Derived1, Derived2, 0, Derived1::InnerSizeAtCompileTime>
00300         ::run(dst, src, outer);
00301   }
00302 };
00303 
00304 /***********************
00305 *** Linear traversal ***
00306 ***********************/
00307 
00308 template<typename Derived1, typename Derived2>
00309 struct assign_impl<Derived1, Derived2, LinearTraversal, NoUnrolling>
00310 {
00311   typedef typename Derived1::Index Index;
00312   inline static void run(Derived1 &dst, const Derived2 &src)
00313   {
00314     const Index size = dst.size();
00315     for(Index i = 0; i < size; ++i)
00316       dst.copyCoeff(i, src);
00317   }
00318 };
00319 
00320 template<typename Derived1, typename Derived2>
00321 struct assign_impl<Derived1, Derived2, LinearTraversal, CompleteUnrolling>
00322 {
00323   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
00324   {
00325     assign_LinearTraversal_CompleteUnrolling<Derived1, Derived2, 0, Derived1::SizeAtCompileTime>
00326       ::run(dst, src);
00327   }
00328 };
00329 
00330 /**************************
00331 *** Inner vectorization ***
00332 **************************/
00333 
00334 template<typename Derived1, typename Derived2>
00335 struct assign_impl<Derived1, Derived2, InnerVectorizedTraversal, NoUnrolling>
00336 {
00337   typedef typename Derived1::Index Index;
00338   inline static void run(Derived1 &dst, const Derived2 &src)
00339   {
00340     const Index innerSize = dst.innerSize();
00341     const Index outerSize = dst.outerSize();
00342     const Index packetSize = packet_traits<typename Derived1::Scalar>::size;
00343     for(Index outer = 0; outer < outerSize; ++outer)
00344       for(Index inner = 0; inner < innerSize; inner+=packetSize)
00345         dst.template copyPacketByOuterInner<Derived2, Aligned, Aligned>(outer, inner, src);
00346   }
00347 };
00348 
00349 template<typename Derived1, typename Derived2>
00350 struct assign_impl<Derived1, Derived2, InnerVectorizedTraversal, CompleteUnrolling>
00351 {
00352   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
00353   {
00354     assign_innervec_CompleteUnrolling<Derived1, Derived2, 0, Derived1::SizeAtCompileTime>
00355       ::run(dst, src);
00356   }
00357 };
00358 
00359 template<typename Derived1, typename Derived2>
00360 struct assign_impl<Derived1, Derived2, InnerVectorizedTraversal, InnerUnrolling>
00361 {
00362   typedef typename Derived1::Index Index;
00363   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
00364   {
00365     const Index outerSize = dst.outerSize();
00366     for(Index outer = 0; outer < outerSize; ++outer)
00367       assign_innervec_InnerUnrolling<Derived1, Derived2, 0, Derived1::InnerSizeAtCompileTime>
00368         ::run(dst, src, outer);
00369   }
00370 };
00371 
00372 /***************************
00373 *** Linear vectorization ***
00374 ***************************/
00375 
00376 template <bool IsAligned = false>
00377 struct unaligned_assign_impl
00378 {
00379   template <typename Derived, typename OtherDerived>
00380   static EIGEN_STRONG_INLINE void run(const Derived&, OtherDerived&, typename Derived::Index, typename Derived::Index) {}
00381 };
00382 
00383 template <>
00384 struct unaligned_assign_impl<false>
00385 {
00386   // MSVC must not inline this functions. If it does, it fails to optimize the
00387   // packet access path.
00388 #ifdef _MSC_VER
00389   template <typename Derived, typename OtherDerived>
00390   static EIGEN_DONT_INLINE void run(const Derived& src, OtherDerived& dst, typename Derived::Index start, typename Derived::Index end)
00391 #else
00392   template <typename Derived, typename OtherDerived>
00393   static EIGEN_STRONG_INLINE void run(const Derived& src, OtherDerived& dst, typename Derived::Index start, typename Derived::Index end)
00394 #endif
00395   {
00396     for (typename Derived::Index index = start; index < end; ++index)
00397       dst.copyCoeff(index, src);
00398   }
00399 };
00400 
00401 template<typename Derived1, typename Derived2>
00402 struct assign_impl<Derived1, Derived2, LinearVectorizedTraversal, NoUnrolling>
00403 {
00404   typedef typename Derived1::Index Index;
00405   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
00406   {
00407     const Index size = dst.size();
00408     typedef packet_traits<typename Derived1::Scalar> PacketTraits;
00409     enum {
00410       packetSize = PacketTraits::size,
00411       dstAlignment = PacketTraits::AlignedOnScalar ? Aligned : int(assign_traits<Derived1,Derived2>::DstIsAligned) ,
00412       srcAlignment = assign_traits<Derived1,Derived2>::JointAlignment
00413     };
00414     const Index alignedStart = assign_traits<Derived1,Derived2>::DstIsAligned ? 0
00415                              : first_aligned(&dst.coeffRef(0), size);
00416     const Index alignedEnd = alignedStart + ((size-alignedStart)/packetSize)*packetSize;
00417 
00418     unaligned_assign_impl<assign_traits<Derived1,Derived2>::DstIsAligned!=0>::run(src,dst,0,alignedStart);
00419 
00420     for(Index index = alignedStart; index < alignedEnd; index += packetSize)
00421     {
00422       dst.template copyPacket<Derived2, dstAlignment, srcAlignment>(index, src);
00423     }
00424 
00425     unaligned_assign_impl<>::run(src,dst,alignedEnd,size);
00426   }
00427 };
00428 
00429 template<typename Derived1, typename Derived2>
00430 struct assign_impl<Derived1, Derived2, LinearVectorizedTraversal, CompleteUnrolling>
00431 {
00432   typedef typename Derived1::Index Index;
00433   EIGEN_STRONG_INLINE static void run(Derived1 &dst, const Derived2 &src)
00434   {
00435     enum { size = Derived1::SizeAtCompileTime,
00436            packetSize = packet_traits<typename Derived1::Scalar>::size,
00437            alignedSize = (size/packetSize)*packetSize };
00438 
00439     assign_innervec_CompleteUnrolling<Derived1, Derived2, 0, alignedSize>::run(dst, src);
00440     assign_DefaultTraversal_CompleteUnrolling<Derived1, Derived2, alignedSize, size>::run(dst, src);
00441   }
00442 };
00443 
00444 /**************************
00445 *** Slice vectorization ***
00446 ***************************/
00447 
00448 template<typename Derived1, typename Derived2>
00449 struct assign_impl<Derived1, Derived2, SliceVectorizedTraversal, NoUnrolling>
00450 {
00451   typedef typename Derived1::Index Index;
00452   inline static void run(Derived1 &dst, const Derived2 &src)
00453   {
00454     typedef packet_traits<typename Derived1::Scalar> PacketTraits;
00455     enum {
00456       packetSize = PacketTraits::size,
00457       alignable = PacketTraits::AlignedOnScalar,
00458       dstAlignment = alignable ? Aligned : int(assign_traits<Derived1,Derived2>::DstIsAligned) ,
00459       srcAlignment = assign_traits<Derived1,Derived2>::JointAlignment
00460     };
00461     const Index packetAlignedMask = packetSize - 1;
00462     const Index innerSize = dst.innerSize();
00463     const Index outerSize = dst.outerSize();
00464     const Index alignedStep = alignable ? (packetSize - dst.outerStride() % packetSize) & packetAlignedMask : 0;
00465     Index alignedStart = ((!alignable) || assign_traits<Derived1,Derived2>::DstIsAligned) ? 0
00466                        : first_aligned(&dst.coeffRef(0,0), innerSize);
00467 
00468     for(Index outer = 0; outer < outerSize; ++outer)
00469     {
00470       const Index alignedEnd = alignedStart + ((innerSize-alignedStart) & ~packetAlignedMask);
00471       // do the non-vectorizable part of the assignment
00472       for(Index inner = 0; inner<alignedStart ; ++inner)
00473         dst.copyCoeffByOuterInner(outer, inner, src);
00474 
00475       // do the vectorizable part of the assignment
00476       for(Index inner = alignedStart; inner<alignedEnd; inner+=packetSize)
00477         dst.template copyPacketByOuterInner<Derived2, dstAlignment, Unaligned>(outer, inner, src);
00478 
00479       // do the non-vectorizable part of the assignment
00480       for(Index inner = alignedEnd; inner<innerSize ; ++inner)
00481         dst.copyCoeffByOuterInner(outer, inner, src);
00482 
00483       alignedStart = std::min<Index>((alignedStart+alignedStep)%packetSize, innerSize);
00484     }
00485   }
00486 };
00487 
00488 } // end namespace internal
00489 
00490 /***************************************************************************
00491 * Part 4 : implementation of DenseBase methods
00492 ***************************************************************************/
00493 
00494 template<typename Derived>
00495 template<typename OtherDerived>
00496 EIGEN_STRONG_INLINE Derived& DenseBase<Derived>
00497   ::lazyAssign(const DenseBase<OtherDerived>& other)
00498 {
00499   enum{
00500     SameType = internal::is_same<typename Derived::Scalar,typename OtherDerived::Scalar>::value
00501   };
00502 
00503   EIGEN_STATIC_ASSERT_LVALUE(Derived)
00504   EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Derived,OtherDerived)
00505   EIGEN_STATIC_ASSERT(SameType,YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
00506 
00507 #ifdef EIGEN_DEBUG_ASSIGN
00508   internal::assign_traits<Derived, OtherDerived>::debug();
00509 #endif
00510   eigen_assert(rows() == other.rows() && cols() == other.cols());
00511   internal::assign_impl<Derived, OtherDerived, int(SameType) ? int(internal::assign_traits<Derived, OtherDerived>::Traversal)
00512                                                        : int(InvalidTraversal)>::run(derived(),other.derived());
00513 #ifndef EIGEN_NO_DEBUG
00514   checkTransposeAliasing(other.derived());
00515 #endif
00516   return derived();
00517 }
00518 
00519 namespace internal {
00520 
00521 template<typename Derived, typename OtherDerived,
00522          bool EvalBeforeAssigning = (int(OtherDerived::Flags) & EvalBeforeAssigningBit) != 0,
00523          bool NeedToTranspose = Derived::IsVectorAtCompileTime
00524                 && OtherDerived::IsVectorAtCompileTime
00525                 && ((int(Derived::RowsAtCompileTime) == 1 && int(OtherDerived::ColsAtCompileTime) == 1)
00526                       |  // FIXME | instead of || to please GCC 4.4.0 stupid warning "suggest parentheses around &&".
00527                          // revert to || as soon as not needed anymore.
00528                     (int(Derived::ColsAtCompileTime) == 1 && int(OtherDerived::RowsAtCompileTime) == 1))
00529                 && int(Derived::SizeAtCompileTime) != 1>
00530 struct assign_selector;
00531 
00532 template<typename Derived, typename OtherDerived>
00533 struct assign_selector<Derived,OtherDerived,false,false> {
00534   EIGEN_STRONG_INLINE static Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.derived()); }
00535 };
00536 template<typename Derived, typename OtherDerived>
00537 struct assign_selector<Derived,OtherDerived,true,false> {
00538   EIGEN_STRONG_INLINE static Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.eval()); }
00539 };
00540 template<typename Derived, typename OtherDerived>
00541 struct assign_selector<Derived,OtherDerived,false,true> {
00542   EIGEN_STRONG_INLINE static Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.transpose()); }
00543 };
00544 template<typename Derived, typename OtherDerived>
00545 struct assign_selector<Derived,OtherDerived,true,true> {
00546   EIGEN_STRONG_INLINE static Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.transpose().eval()); }
00547 };
00548 
00549 } // end namespace internal
00550 
00551 template<typename Derived>
00552 template<typename OtherDerived>
00553 EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::operator=(const DenseBase<OtherDerived>& other)
00554 {
00555   return internal::assign_selector<Derived,OtherDerived>::run(derived(), other.derived());
00556 }
00557 
00558 template<typename Derived>
00559 EIGEN_STRONG_INLINE Derived& DenseBase<Derived>::operator=(const DenseBase& other)
00560 {
00561   return internal::assign_selector<Derived,Derived>::run(derived(), other.derived());
00562 }
00563 
00564 template<typename Derived>
00565 EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const MatrixBase& other)
00566 {
00567   return internal::assign_selector<Derived,Derived>::run(derived(), other.derived());
00568 }
00569 
00570 template<typename Derived>
00571 template <typename OtherDerived>
00572 EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const DenseBase<OtherDerived>& other)
00573 {
00574   return internal::assign_selector<Derived,OtherDerived>::run(derived(), other.derived());
00575 }
00576 
00577 template<typename Derived>
00578 template <typename OtherDerived>
00579 EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const EigenBase<OtherDerived>& other)
00580 {
00581   other.derived().evalTo(derived());
00582   return derived();
00583 }
00584 
00585 template<typename Derived>
00586 template<typename OtherDerived>
00587 EIGEN_STRONG_INLINE Derived& MatrixBase<Derived>::operator=(const ReturnByValue<OtherDerived>& other)
00588 {
00589   other.evalTo(derived());
00590   return derived();
00591 }
00592 
00593 #endif // EIGEN_ASSIGN_H


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:29