Eigen  5.0.1
 
Loading...
Searching...
No Matches
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// SPDX-License-Identifier: MPL-2.0
10
11#ifndef EIGEN_SWAP_H
12#define EIGEN_SWAP_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
19namespace internal {
20
21// Overload default assignPacket behavior for swapping them
22template <typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT>
23class generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT,
24 swap_assign_op<typename DstEvaluatorTypeT::Scalar>, Specialized>
25 : public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT,
26 swap_assign_op<typename DstEvaluatorTypeT::Scalar>, BuiltIn> {
27 protected:
28 using Base = generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT,
29 swap_assign_op<typename DstEvaluatorTypeT::Scalar>, BuiltIn>;
30 using Base::m_dst;
31 using Base::m_src;
32
33 public:
34 using Scalar = typename Base::Scalar;
35 using DstXprType = typename Base::DstXprType;
36 using Functor = swap_assign_op<Scalar>;
37
38 EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE generic_dense_assignment_kernel(DstEvaluatorTypeT &dst,
39 const SrcEvaluatorTypeT &src,
40 const Functor &func,
41 DstXprType &dstExpr)
42 : Base(dst, src, func, dstExpr) {}
43
44 template <int StoreMode, int LoadMode, typename PacketType>
45 EIGEN_DEVICE_FUNC 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_DEVICE_FUNC 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 template <int StoreMode, int LoadMode, typename PacketType>
61 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacketByOuterInner(Index outer, Index inner) {
62 Index row = Base::rowIndexByOuterInner(outer, inner);
63 Index col = Base::colIndexByOuterInner(outer, inner);
64 assignPacket<StoreMode, LoadMode, PacketType>(row, col);
65 }
66
67 template <int StoreMode, int LoadMode, typename PacketType>
68 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacketSegment(Index row, Index col, Index begin, Index count) {
69 PacketType tmp = m_src.template packetSegment<LoadMode, PacketType>(row, col, begin, count);
70 const_cast<SrcEvaluatorTypeT &>(m_src).template writePacketSegment<LoadMode>(
71 row, col, m_dst.template packetSegment<StoreMode, PacketType>(row, col, begin, count), begin, count);
72 m_dst.template writePacketSegment<StoreMode>(row, col, tmp, begin, count);
73 }
74
75 template <int StoreMode, int LoadMode, typename PacketType>
76 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacketSegment(Index index, Index begin, Index count) {
77 PacketType tmp = m_src.template packetSegment<LoadMode, PacketType>(index, begin, count);
78 const_cast<SrcEvaluatorTypeT &>(m_src).template writePacketSegment<LoadMode>(
79 index, m_dst.template packetSegment<StoreMode, PacketType>(index, begin, count), begin, count);
80 m_dst.template writePacketSegment<StoreMode>(index, tmp, begin, count);
81 }
82
83 template <int StoreMode, int LoadMode, typename PacketType>
84 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacketSegmentByOuterInner(Index outer, Index inner, Index begin,
85 Index count) {
86 Index row = Base::rowIndexByOuterInner(outer, inner);
87 Index col = Base::colIndexByOuterInner(outer, inner);
88 assignPacketSegment<StoreMode, LoadMode, PacketType>(row, col, begin, count);
89 }
90};
91
92} // namespace internal
93
94} // end namespace Eigen
95
96#endif // EIGEN_SWAP_H