ConjHelper.h
Go to the documentation of this file.
1 
2 // This file is part of Eigen, a lightweight C++ template library
3 // for linear algebra.
4 //
5 // Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_ARCH_CONJ_HELPER_H
12 #define EIGEN_ARCH_CONJ_HELPER_H
13 
14 #define EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(PACKET_CPLX, PACKET_REAL) \
15  template <> \
16  struct conj_helper<PACKET_REAL, PACKET_CPLX, false, false> { \
17  EIGEN_STRONG_INLINE PACKET_CPLX pmadd(const PACKET_REAL& x, const PACKET_CPLX& y, const PACKET_CPLX& c) const { \
18  return padd(c, this->pmul(x, y)); \
19  } \
20  EIGEN_STRONG_INLINE PACKET_CPLX pmul(const PACKET_REAL& x, const PACKET_CPLX& y) const { \
21  return PACKET_CPLX(Eigen::internal::pmul<PACKET_REAL>(x, y.v)); \
22  } \
23  }; \
24  \
25  template <> \
26  struct conj_helper<PACKET_CPLX, PACKET_REAL, false, false> { \
27  EIGEN_STRONG_INLINE PACKET_CPLX pmadd(const PACKET_CPLX& x, const PACKET_REAL& y, const PACKET_CPLX& c) const { \
28  return padd(c, this->pmul(x, y)); \
29  } \
30  EIGEN_STRONG_INLINE PACKET_CPLX pmul(const PACKET_CPLX& x, const PACKET_REAL& y) const { \
31  return PACKET_CPLX(Eigen::internal::pmul<PACKET_REAL>(x.v, y)); \
32  } \
33  };
34 
35 // IWYU pragma: private
36 #include "../../InternalHeaderCheck.h"
37 
38 namespace Eigen {
39 namespace internal {
40 
41 template <bool Conjugate>
42 struct conj_if;
43 
44 template <>
45 struct conj_if<true> {
46  template <typename T>
48  return numext::conj(x);
49  }
50  template <typename T>
52  return internal::pconj(x);
53  }
54 };
55 
56 template <>
57 struct conj_if<false> {
58  template <typename T>
60  return x;
61  }
62  template <typename T>
64  return x;
65  }
66 };
67 
68 // Generic Implementation, assume scalars since the packet-version is
69 // specialized below.
70 template <typename LhsType, typename RhsType, bool ConjLhs, bool ConjRhs>
71 struct conj_helper {
73 
74  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType pmadd(const LhsType& x, const RhsType& y,
75  const ResultType& c) const {
76  return this->pmul(x, y) + c;
77  }
78 
79  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType pmul(const LhsType& x, const RhsType& y) const {
80  return conj_if<ConjLhs>()(x) * conj_if<ConjRhs>()(y);
81  }
82 };
83 
84 template <typename LhsScalar, typename RhsScalar>
85 struct conj_helper<LhsScalar, RhsScalar, true, true> {
87 
88  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType pmadd(const LhsScalar& x, const RhsScalar& y,
89  const ResultType& c) const {
90  return this->pmul(x, y) + c;
91  }
92 
93  // We save a conjuation by using the identity conj(a)*conj(b) = conj(a*b).
94  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType pmul(const LhsScalar& x, const RhsScalar& y) const {
95  return numext::conj(x * y);
96  }
97 };
98 
99 // Implementation with equal type, use packet operations.
100 template <typename Packet, bool ConjLhs, bool ConjRhs>
101 struct conj_helper<Packet, Packet, ConjLhs, ConjRhs> {
105  }
106 
109  }
110 };
111 
112 template <typename Packet>
113 struct conj_helper<Packet, Packet, true, true> {
115 
117  return Eigen::internal::pmadd(pconj(x), pconj(y), c);
118  }
119  // We save a conjuation by using the identity conj(a)*conj(b) = conj(a*b).
121  return pconj(Eigen::internal::pmul(x, y));
122  }
123 };
124 
125 } // namespace internal
126 } // namespace Eigen
127 
128 #endif // EIGEN_ARCH_CONJ_HELPER_H
AnnoyingScalar conj(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:133
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define EIGEN_STRONG_INLINE
Definition: Macros.h:834
EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf &a)
Definition: AltiVec/Complex.h:268
const Scalar & y
Definition: RandomImpl.h:36
EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f &a, const Packet4f &b, const Packet4f &c)
Definition: AltiVec/PacketMath.h:1218
EIGEN_STRONG_INLINE Packet4cf pmul(const Packet4cf &a, const Packet4cf &b)
Definition: AVX/Complex.h:88
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
int c
Definition: calibrate.py:100
Definition: Eigen_Colamd.h:49
list x
Definition: plotDoE.py:28
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition: XprHelper.h:1043
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType pmul(const LhsScalar &x, const RhsScalar &y) const
Definition: ConjHelper.h:94
ScalarBinaryOpTraits< LhsScalar, RhsScalar >::ReturnType ResultType
Definition: ConjHelper.h:86
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType pmadd(const LhsScalar &x, const RhsScalar &y, const ResultType &c) const
Definition: ConjHelper.h:88
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmul(const Packet &x, const Packet &y) const
Definition: ConjHelper.h:107
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmadd(const Packet &x, const Packet &y, const Packet &c) const
Definition: ConjHelper.h:103
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmul(const Packet &x, const Packet &y) const
Definition: ConjHelper.h:120
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmadd(const Packet &x, const Packet &y, const Packet &c) const
Definition: ConjHelper.h:116
Definition: ConjHelper.h:71
ScalarBinaryOpTraits< LhsType, RhsType >::ReturnType ResultType
Definition: ConjHelper.h:72
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType pmadd(const LhsType &x, const RhsType &y, const ResultType &c) const
Definition: ConjHelper.h:74
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType pmul(const LhsType &x, const RhsType &y) const
Definition: ConjHelper.h:79
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T & pconj(const T &x) const
Definition: ConjHelper.h:63
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T & operator()(const T &x) const
Definition: ConjHelper.h:59
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T pconj(const T &x) const
Definition: ConjHelper.h:51
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T operator()(const T &x) const
Definition: ConjHelper.h:47
Definition: ConjHelper.h:42
Definition: ZVector/PacketMath.h:50