![]() |
Eigen
3.3.3
|
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> 00005 // 00006 // This Source Code Form is subject to the terms of the Mozilla 00007 // Public License v. 2.0. If a copy of the MPL was not distributed 00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00009 00010 #ifndef EIGEN_SWAP_H 00011 #define EIGEN_SWAP_H 00012 00013 namespace Eigen { 00014 00015 namespace internal { 00016 00017 // Overload default assignPacket behavior for swapping them 00018 template<typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT> 00019 class generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, swap_assign_op<typename DstEvaluatorTypeT::Scalar>, Specialized> 00020 : public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, swap_assign_op<typename DstEvaluatorTypeT::Scalar>, BuiltIn> 00021 { 00022 protected: 00023 typedef generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, swap_assign_op<typename DstEvaluatorTypeT::Scalar>, BuiltIn> Base; 00024 using Base::m_dst; 00025 using Base::m_src; 00026 using Base::m_functor; 00027 00028 public: 00029 typedef typename Base::Scalar Scalar; 00030 typedef typename Base::DstXprType DstXprType; 00031 typedef swap_assign_op<Scalar> Functor; 00032 00033 EIGEN_DEVICE_FUNC generic_dense_assignment_kernel(DstEvaluatorTypeT &dst, const SrcEvaluatorTypeT &src, const Functor &func, DstXprType& dstExpr) 00034 : Base(dst, src, func, dstExpr) 00035 {} 00036 00037 template<int StoreMode, int LoadMode, typename PacketType> 00038 void assignPacket(Index row, Index col) 00039 { 00040 PacketType tmp = m_src.template packet<LoadMode,PacketType>(row,col); 00041 const_cast<SrcEvaluatorTypeT&>(m_src).template writePacket<LoadMode>(row,col, m_dst.template packet<StoreMode,PacketType>(row,col)); 00042 m_dst.template writePacket<StoreMode>(row,col,tmp); 00043 } 00044 00045 template<int StoreMode, int LoadMode, typename PacketType> 00046 void assignPacket(Index index) 00047 { 00048 PacketType tmp = m_src.template packet<LoadMode,PacketType>(index); 00049 const_cast<SrcEvaluatorTypeT&>(m_src).template writePacket<LoadMode>(index, m_dst.template packet<StoreMode,PacketType>(index)); 00050 m_dst.template writePacket<StoreMode>(index,tmp); 00051 } 00052 00053 // TODO find a simple way not to have to copy/paste this function from generic_dense_assignment_kernel, by simple I mean no CRTP (Gael) 00054 template<int StoreMode, int LoadMode, typename PacketType> 00055 void assignPacketByOuterInner(Index outer, Index inner) 00056 { 00057 Index row = Base::rowIndexByOuterInner(outer, inner); 00058 Index col = Base::colIndexByOuterInner(outer, inner); 00059 assignPacket<StoreMode,LoadMode,PacketType>(row, col); 00060 } 00061 }; 00062 00063 } // namespace internal 00064 00065 } // end namespace Eigen 00066 00067 #endif // EIGEN_SWAP_H