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 // 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,
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;
38 
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>
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>
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>
64  Index row = Base::rowIndexByOuterInner(outer, inner);
65  Index col = Base::colIndexByOuterInner(outer, inner);
66  assignPacket<StoreMode, LoadMode, PacketType>(row, col);
67  }
68 };
69 
70 } // namespace internal
71 
72 } // end namespace Eigen
73 
74 #endif // EIGEN_SWAP_H
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define EIGEN_STRONG_INLINE
Definition: Macros.h:834
m col(1)
m row(1)
generic_dense_assignment_kernel< DstEvaluatorTypeT, SrcEvaluatorTypeT, swap_assign_op< typename DstEvaluatorTypeT::Scalar >, BuiltIn > Base
Definition: Swap.h:29
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE generic_dense_assignment_kernel(DstEvaluatorTypeT &dst, const SrcEvaluatorTypeT &src, const Functor &func, DstXprType &dstExpr)
Definition: Swap.h:39
Definition: AssignEvaluator.h:585
const SrcEvaluatorType & m_src
Definition: AssignEvaluator.h:671
DstEvaluatorType & m_dst
Definition: AssignEvaluator.h:670
DstEvaluatorTypeT::XprType DstXprType
Definition: AssignEvaluator.h:587
DstEvaluatorType::Scalar Scalar
Definition: AssignEvaluator.h:593
@ Specialized
Definition: Constants.h:311
@ BuiltIn
Definition: Constants.h:311
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
Definition: Eigen_Colamd.h:49
Template functor for scalar/packet assignment with swapping.
Definition: AssignmentFunctors.h:147
Definition: benchGeometry.cpp:21