$darkmode
Eigen  5.0.1-dev
Swap.h
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 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 
20 // Overload default assignPacket behavior for swapping them
21 template <typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT>
22 class generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT,
23  swap_assign_op<typename DstEvaluatorTypeT::Scalar>, Specialized>
24  : public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT,
25  swap_assign_op<typename DstEvaluatorTypeT::Scalar>, BuiltIn> {
26  protected:
27  typedef generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT,
28  swap_assign_op<typename DstEvaluatorTypeT::Scalar>, BuiltIn>
29  Base;
30  using Base::m_dst;
31  using Base::m_functor;
32  using Base::m_src;
33 
34  public:
35  typedef typename Base::Scalar Scalar;
36  typedef typename Base::DstXprType DstXprType;
37  typedef swap_assign_op<Scalar> Functor;
38 
39  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE generic_dense_assignment_kernel(DstEvaluatorTypeT &dst,
40  const SrcEvaluatorTypeT &src,
41  const Functor &func, DstXprType &dstExpr)
42  : Base(dst, src, func, dstExpr) {}
43 
44  template <int StoreMode, int LoadMode, typename PacketType>
45  EIGEN_STRONG_INLINE void assignPacket(Index row, Index col) {
46  PacketType tmp = m_src.template packet<LoadMode, PacketType>(row, col);
47  const_cast<SrcEvaluatorTypeT &>(m_src).template writePacket<LoadMode>(
48  row, col, m_dst.template packet<StoreMode, PacketType>(row, col));
49  m_dst.template writePacket<StoreMode>(row, col, tmp);
50  }
51 
52  template <int StoreMode, int LoadMode, typename PacketType>
53  EIGEN_STRONG_INLINE void assignPacket(Index index) {
54  PacketType tmp = m_src.template packet<LoadMode, PacketType>(index);
55  const_cast<SrcEvaluatorTypeT &>(m_src).template writePacket<LoadMode>(
56  index, m_dst.template packet<StoreMode, PacketType>(index));
57  m_dst.template writePacket<StoreMode>(index, tmp);
58  }
59 
60  // TODO find a simple way not to have to copy/paste this function from generic_dense_assignment_kernel, by simple I
61  // mean no CRTP (Gael)
62  template <int StoreMode, int LoadMode, typename PacketType>
63  EIGEN_STRONG_INLINE void assignPacketByOuterInner(Index outer, Index inner) {
64  Index row = Base::rowIndexByOuterInner(outer, inner);
65  Index col = Base::colIndexByOuterInner(outer, inner);
66  assignPacket<StoreMode, LoadMode, PacketType>(row, col);
67  }
68 
69  template <int StoreMode, int LoadMode, typename PacketType>
70  EIGEN_STRONG_INLINE void assignPacketSegment(Index row, Index col, Index begin, Index count) {
71  PacketType tmp = m_src.template packetSegment<LoadMode, PacketType>(row, col, begin, count);
72  const_cast<SrcEvaluatorTypeT &>(m_src).template writePacketSegment<LoadMode>(
73  row, col, m_dst.template packetSegment<StoreMode, PacketType>(row, col, begin, count), begin, count);
74  m_dst.template writePacketSegment<StoreMode>(row, col, tmp, begin, count);
75  }
76 
77  template <int StoreMode, int LoadMode, typename PacketType>
78  EIGEN_STRONG_INLINE void assignPacketSegment(Index index, Index begin, Index count) {
79  PacketType tmp = m_src.template packetSegment<LoadMode, PacketType>(index, begin, count);
80  const_cast<SrcEvaluatorTypeT &>(m_src).template writePacketSegment<LoadMode>(
81  index, m_dst.template packetSegment<StoreMode, PacketType>(index, begin, count), begin, count);
82  m_dst.template writePacketSegment<StoreMode>(index, tmp, begin, count);
83  }
84 
85  // TODO find a simple way not to have to copy/paste this function from generic_dense_assignment_kernel, by simple I
86  // mean no CRTP (Gael)
87  template <int StoreMode, int LoadMode, typename PacketType>
88  EIGEN_STRONG_INLINE void assignPacketSegmentByOuterInner(Index outer, Index inner, Index begin, Index count) {
89  Index row = Base::rowIndexByOuterInner(outer, inner);
90  Index col = Base::colIndexByOuterInner(outer, inner);
91  assignPacketSegment<StoreMode, LoadMode, PacketType>(row, col, begin, count);
92  }
93 };
94 
95 } // namespace internal
96 
97 } // end namespace Eigen
98 
99 #endif // EIGEN_SWAP_H
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82