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, \
18  const PACKET_CPLX& y, \
19  const PACKET_CPLX& c) const { \
20  return padd(c, this->pmul(x, y)); \
21  } \
22  EIGEN_STRONG_INLINE PACKET_CPLX pmul(const PACKET_REAL& x, \
23  const PACKET_CPLX& y) const { \
24  return PACKET_CPLX(Eigen::internal::pmul<PACKET_REAL>(x, y.v)); \
25  } \
26  }; \
27  \
28  template <> \
29  struct conj_helper<PACKET_CPLX, PACKET_REAL, false, false> { \
30  EIGEN_STRONG_INLINE PACKET_CPLX pmadd(const PACKET_CPLX& x, \
31  const PACKET_REAL& y, \
32  const PACKET_CPLX& c) const { \
33  return padd(c, this->pmul(x, y)); \
34  } \
35  EIGEN_STRONG_INLINE PACKET_CPLX pmul(const PACKET_CPLX& x, \
36  const PACKET_REAL& y) const { \
37  return PACKET_CPLX(Eigen::internal::pmul<PACKET_REAL>(x.v, y)); \
38  } \
39  };
40 
41 #include "../../InternalHeaderCheck.h"
42 
43 namespace Eigen {
44 namespace internal {
45 
46 template<bool Conjugate> struct conj_if;
47 
48 template<> struct conj_if<true> {
49  template<typename T>
50  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T operator()(const T& x) const { return numext::conj(x); }
51  template<typename T>
52  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T pconj(const T& x) const { return internal::pconj(x); }
53 };
54 
55 template<> struct conj_if<false> {
56  template<typename T>
57  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T& operator()(const T& x) const { return x; }
58  template<typename T>
59  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T& pconj(const T& x) const { return x; }
60 };
61 
62 // Generic Implementation, assume scalars since the packet-version is
63 // specialized below.
64 template<typename LhsType, typename RhsType, bool ConjLhs, bool ConjRhs>
65 struct conj_helper {
66  typedef typename ScalarBinaryOpTraits<LhsType, RhsType>::ReturnType ResultType;
67 
68  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType
69  pmadd(const LhsType& x, const RhsType& y, const ResultType& c) const
70  { return this->pmul(x, y) + c; }
71 
72  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType
73  pmul(const LhsType& x, const RhsType& y) const
74  { return conj_if<ConjLhs>()(x) * conj_if<ConjRhs>()(y); }
75 };
76 
77 template<typename LhsScalar, typename RhsScalar>
78 struct conj_helper<LhsScalar, RhsScalar, true, true> {
79  typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar>::ReturnType ResultType;
80 
81  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType
82  pmadd(const LhsScalar& x, const RhsScalar& y, const ResultType& c) const
83  { return this->pmul(x, y) + c; }
84 
85  // We save a conjuation by using the identity conj(a)*conj(b) = conj(a*b).
86  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType
87  pmul(const LhsScalar& x, const RhsScalar& y) const
88  { return numext::conj(x * y); }
89 };
90 
91 // Implementation with equal type, use packet operations.
92 template<typename Packet, bool ConjLhs, bool ConjRhs>
93 struct conj_helper<Packet, Packet, ConjLhs, ConjRhs>
94 {
95  typedef Packet ResultType;
96  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmadd(const Packet& x, const Packet& y, const Packet& c) const
97  { return Eigen::internal::pmadd(conj_if<ConjLhs>().pconj(x), conj_if<ConjRhs>().pconj(y), c); }
98 
99 
100  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmul(const Packet& x, const Packet& y) const
101  { return Eigen::internal::pmul(conj_if<ConjLhs>().pconj(x), conj_if<ConjRhs>().pconj(y)); }
102 };
103 
104 template<typename Packet>
105 struct conj_helper<Packet, Packet, true, true>
106 {
107  typedef Packet ResultType;
108 
109  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmadd(const Packet& x, const Packet& y, const Packet& c) const
110  { return Eigen::internal::pmadd(pconj(x), pconj(y), c); }
111  // We save a conjuation by using the identity conj(a)*conj(b) = conj(a*b).
112  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmul(const Packet& x, const Packet& y) const
113  { return pconj(Eigen::internal::pmul(x, y)); }
114 };
115 
116 } // namespace internal
117 } // namespace Eigen
118 
119 #endif // EIGEN_ARCH_CONJ_HELPER_H
Array33i c
IndexedView_or_Block operator()(const RowIndices &rowIndices, const ColIndices &colIndices)
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
const Scalar & y
Packet4f pmadd(const Packet4f &a, const Packet4f &b, const Packet4f &c)
Packet pmul(const Packet &a, const Packet &b)
Packet2cf pconj(const Packet2cf &a)
: InteropHeaders
Definition: Core:139
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_conjugate_op< typename Derived::Scalar >, const Derived > conj(const Eigen::ArrayBase< Derived > &x)