Swap.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_SWAP_H
11 #define EIGEN_SWAP_H
12 
13 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
17 namespace internal {
18 
19 // Overload default assignPacket behavior for swapping them
20 template<typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT>
21 class generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, swap_assign_op<typename DstEvaluatorTypeT::Scalar>, Specialized>
22  : public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, swap_assign_op<typename DstEvaluatorTypeT::Scalar>, BuiltIn>
23 {
24 protected:
25  typedef generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, swap_assign_op<typename DstEvaluatorTypeT::Scalar>, BuiltIn> Base;
26  using Base::m_dst;
27  using Base::m_src;
28  using Base::m_functor;
29 
30 public:
31  typedef typename Base::Scalar Scalar;
32  typedef typename Base::DstXprType DstXprType;
33  typedef swap_assign_op<Scalar> Functor;
34 
35  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
36  generic_dense_assignment_kernel(DstEvaluatorTypeT &dst, const SrcEvaluatorTypeT &src, const Functor &func, DstXprType& dstExpr)
37  : Base(dst, src, func, dstExpr)
38  {}
39 
40  template<int StoreMode, int LoadMode, typename PacketType>
41  EIGEN_STRONG_INLINE void assignPacket(Index row, Index col)
42  {
43  PacketType tmp = m_src.template packet<LoadMode,PacketType>(row,col);
44  const_cast<SrcEvaluatorTypeT&>(m_src).template writePacket<LoadMode>(row,col, m_dst.template packet<StoreMode,PacketType>(row,col));
45  m_dst.template writePacket<StoreMode>(row,col,tmp);
46  }
47 
48  template<int StoreMode, int LoadMode, typename PacketType>
49  EIGEN_STRONG_INLINE void assignPacket(Index index)
50  {
51  PacketType tmp = m_src.template packet<LoadMode,PacketType>(index);
52  const_cast<SrcEvaluatorTypeT&>(m_src).template writePacket<LoadMode>(index, m_dst.template packet<StoreMode,PacketType>(index));
53  m_dst.template writePacket<StoreMode>(index,tmp);
54  }
55 
56  // 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)
57  template<int StoreMode, int LoadMode, typename PacketType>
58  EIGEN_STRONG_INLINE void assignPacketByOuterInner(Index outer, Index inner)
59  {
60  Index row = Base::rowIndexByOuterInner(outer, inner);
61  Index col = Base::colIndexByOuterInner(outer, inner);
62  assignPacket<StoreMode,LoadMode,PacketType>(row, col);
63  }
64 };
65 
66 } // namespace internal
67 
68 } // end namespace Eigen
69 
70 #endif // EIGEN_SWAP_H
RowXpr row(Index i)
This is the const version of row(). *‍/.
ColXpr col(Index i)
This is the const version of col().
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
: InteropHeaders
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
@ Specialized
Definition: Constants.h:312
@ BuiltIn
Definition: Constants.h:313