WPILibC++ 2023.4.3
AssignmentFunctors.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) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
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_ASSIGNMENT_FUNCTORS_H
11#define EIGEN_ASSIGNMENT_FUNCTORS_H
12
13namespace Eigen {
14
15namespace internal {
16
17/** \internal
18 * \brief Template functor for scalar/packet assignment
19 *
20 */
21template<typename DstScalar,typename SrcScalar> struct assign_op {
22
24 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a = b; }
25
26 template<int Alignment, typename Packet>
27 EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const
28 { internal::pstoret<DstScalar,Packet,Alignment>(a,b); }
29};
30
31// Empty overload for void type (used by PermutationMatrix)
32template<typename DstScalar> struct assign_op<DstScalar,void> {};
33
34template<typename DstScalar,typename SrcScalar>
35struct functor_traits<assign_op<DstScalar,SrcScalar> > {
36 enum {
39 };
40};
41
42/** \internal
43 * \brief Template functor for scalar/packet assignment with addition
44 *
45 */
46template<typename DstScalar,typename SrcScalar> struct add_assign_op {
47
49 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a += b; }
50
51 template<int Alignment, typename Packet>
52 EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const
53 { internal::pstoret<DstScalar,Packet,Alignment>(a,internal::padd(internal::ploadt<Packet,Alignment>(a),b)); }
54};
55template<typename DstScalar,typename SrcScalar>
56struct functor_traits<add_assign_op<DstScalar,SrcScalar> > {
57 enum {
60 };
61};
62
63/** \internal
64 * \brief Template functor for scalar/packet assignment with subtraction
65 *
66 */
67template<typename DstScalar,typename SrcScalar> struct sub_assign_op {
68
70 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a -= b; }
71
72 template<int Alignment, typename Packet>
73 EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const
74 { internal::pstoret<DstScalar,Packet,Alignment>(a,internal::psub(internal::ploadt<Packet,Alignment>(a),b)); }
75};
76template<typename DstScalar,typename SrcScalar>
77struct functor_traits<sub_assign_op<DstScalar,SrcScalar> > {
78 enum {
81 };
82};
83
84/** \internal
85 * \brief Template functor for scalar/packet assignment with multiplication
86 *
87 */
88template<typename DstScalar, typename SrcScalar=DstScalar>
90
92 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a *= b; }
93
94 template<int Alignment, typename Packet>
95 EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const
96 { internal::pstoret<DstScalar,Packet,Alignment>(a,internal::pmul(internal::ploadt<Packet,Alignment>(a),b)); }
97};
98template<typename DstScalar, typename SrcScalar>
99struct functor_traits<mul_assign_op<DstScalar,SrcScalar> > {
100 enum {
103 };
104};
105
106/** \internal
107 * \brief Template functor for scalar/packet assignment with diviving
108 *
109 */
110template<typename DstScalar, typename SrcScalar=DstScalar> struct div_assign_op {
111
113 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar& a, const SrcScalar& b) const { a /= b; }
114
115 template<int Alignment, typename Packet>
116 EIGEN_STRONG_INLINE void assignPacket(DstScalar* a, const Packet& b) const
117 { internal::pstoret<DstScalar,Packet,Alignment>(a,internal::pdiv(internal::ploadt<Packet,Alignment>(a),b)); }
118};
119template<typename DstScalar, typename SrcScalar>
120struct functor_traits<div_assign_op<DstScalar,SrcScalar> > {
121 enum {
124 };
125};
126
127/** \internal
128 * \brief Template functor for scalar/packet assignment with swapping
129 *
130 * It works as follow. For a non-vectorized evaluation loop, we have:
131 * for(i) func(A.coeffRef(i), B.coeff(i));
132 * where B is a SwapWrapper expression. The trick is to make SwapWrapper::coeff behaves like a non-const coeffRef.
133 * Actually, SwapWrapper might not even be needed since even if B is a plain expression, since it has to be writable
134 * B.coeff already returns a const reference to the underlying scalar value.
135 *
136 * The case of a vectorized loop is more tricky:
137 * for(i,j) func.assignPacket<A_Align>(&A.coeffRef(i,j), B.packet<B_Align>(i,j));
138 * Here, B must be a SwapWrapper whose packet function actually returns a proxy object holding a Scalar*,
139 * the actual alignment and Packet type.
140 *
141 */
142template<typename Scalar> struct swap_assign_op {
143
145 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Scalar& a, const Scalar& b) const
146 {
147#ifdef EIGEN_GPUCC
148 // FIXME is there some kind of cuda::swap?
149 Scalar t=b; const_cast<Scalar&>(b)=a; a=t;
150#else
151 using std::swap;
152 swap(a,const_cast<Scalar&>(b));
153#endif
154 }
155};
156template<typename Scalar>
158 enum {
160 PacketAccess =
161 #if defined(EIGEN_VECTORIZE_AVX) && EIGEN_COMP_CLANG && (EIGEN_COMP_CLANG<800 || defined(__apple_build_version__))
162 // This is a partial workaround for a bug in clang generating bad code
163 // when mixing 256/512 bits loads and 128 bits moves.
164 // See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1684
165 // https://bugs.llvm.org/show_bug.cgi?id=40815
166 0
167 #else
169 #endif
170 };
171};
172
173} // namespace internal
174
175} // namespace Eigen
176
177#endif // EIGEN_ASSIGNMENT_FUNCTORS_H
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:986
#define EIGEN_STRONG_INLINE
Definition: Macros.h:927
#define EIGEN_EMPTY_STRUCT_CTOR(X)
Definition: XprHelper.h:22
EIGEN_DEVICE_FUNC Packet pdiv(const Packet &a, const Packet &b)
Definition: GenericPacketMath.h:244
EIGEN_DEVICE_FUNC Packet pmul(const Packet &a, const Packet &b)
Definition: GenericPacketMath.h:237
EIGEN_DEVICE_FUNC Packet psub(const Packet &a, const Packet &b)
Definition: GenericPacketMath.h:222
DoublePacket< Packet > padd(const DoublePacket< Packet > &a, const DoublePacket< Packet > &b)
Definition: GeneralBlockPanelKernel.h:689
void swap(scoped_array< T > &a, scoped_array< T > &b)
Definition: Memory.h:709
Namespace containing all symbols from the Eigen library.
Definition: MatrixExponential.h:16
Definition: Eigen_Colamd.h:50
void swap(wpi::SmallVectorImpl< T > &LHS, wpi::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.
Definition: SmallVector.h:1299
b
Definition: data.h:44
Holds information about the various numeric (i.e.
Definition: NumTraits.h:233
Definition: AssignmentFunctors.h:46
EIGEN_STRONG_INLINE void assignPacket(DstScalar *a, const Packet &b) const
Definition: AssignmentFunctors.h:52
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar &a, const SrcScalar &b) const
Definition: AssignmentFunctors.h:49
Definition: AssignmentFunctors.h:21
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar &a, const SrcScalar &b) const
Definition: AssignmentFunctors.h:24
EIGEN_STRONG_INLINE void assignPacket(DstScalar *a, const Packet &b) const
Definition: AssignmentFunctors.h:27
Definition: AssignmentFunctors.h:110
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar &a, const SrcScalar &b) const
Definition: AssignmentFunctors.h:113
EIGEN_STRONG_INLINE void assignPacket(DstScalar *a, const Packet &b) const
Definition: AssignmentFunctors.h:116
Definition: XprHelper.h:176
@ PacketAccess
Definition: XprHelper.h:180
@ Cost
Definition: XprHelper.h:179
Definition: Meta.h:148
Definition: AssignmentFunctors.h:89
EIGEN_STRONG_INLINE void assignPacket(DstScalar *a, const Packet &b) const
Definition: AssignmentFunctors.h:95
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar &a, const SrcScalar &b) const
Definition: AssignmentFunctors.h:92
Definition: GenericPacketMath.h:107
Definition: AssignmentFunctors.h:67
EIGEN_STRONG_INLINE void assignPacket(DstScalar *a, const Packet &b) const
Definition: AssignmentFunctors.h:73
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(DstScalar &a, const SrcScalar &b) const
Definition: AssignmentFunctors.h:70
Definition: AssignmentFunctors.h:142
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Scalar &a, const Scalar &b) const
Definition: AssignmentFunctors.h:145