Eigen  5.0.1-dev+7c7d8473
 
Loading...
Searching...
No Matches
ConjHelper.h
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 pmsub(const PACKET_REAL& x, const PACKET_CPLX& y, const PACKET_CPLX& c) const { \
21 return psub(this->pmul(x, y), c); \
22 } \
23 EIGEN_STRONG_INLINE PACKET_CPLX pmul(const PACKET_REAL& x, 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, const PACKET_REAL& y, const PACKET_CPLX& c) const { \
31 return padd(c, this->pmul(x, y)); \
32 } \
33 EIGEN_STRONG_INLINE PACKET_CPLX pmsub(const PACKET_CPLX& x, const PACKET_REAL& y, const PACKET_CPLX& c) const { \
34 return psub(this->pmul(x, y), c); \
35 } \
36 EIGEN_STRONG_INLINE PACKET_CPLX pmul(const PACKET_CPLX& x, const PACKET_REAL& y) const { \
37 return PACKET_CPLX(Eigen::internal::pmul<PACKET_REAL>(x.v, y)); \
38 } \
39 };
40
41// IWYU pragma: private
42#include "../../InternalHeaderCheck.h"
43
44namespace Eigen {
45namespace internal {
46
47template <bool Conjugate>
48struct conj_if;
49
50template <>
51struct conj_if<true> {
52 template <typename T>
53 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T operator()(const T& x) const {
54 return numext::conj(x);
55 }
56 template <typename T>
57 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T pconj(const T& x) const {
58 return internal::pconj(x);
59 }
60};
61
62template <>
63struct conj_if<false> {
64 template <typename T>
65 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T& operator()(const T& x) const {
66 return x;
67 }
68 template <typename T>
69 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T& pconj(const T& x) const {
70 return x;
71 }
72};
73
74// Generic Implementation, assume scalars since the packet-version is
75// specialized below.
76template <typename LhsType, typename RhsType, bool ConjLhs, bool ConjRhs>
77struct conj_helper {
78 typedef typename ScalarBinaryOpTraits<LhsType, RhsType>::ReturnType ResultType;
79
80 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType pmadd(const LhsType& x, const RhsType& y,
81 const ResultType& c) const {
82 return this->pmul(x, y) + c;
83 }
84
85 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType pmsub(const LhsType& x, const RhsType& y,
86 const ResultType& c) const {
87 return this->pmul(x, y) - c;
88 }
89
90 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType pmul(const LhsType& x, const RhsType& y) const {
91 return conj_if<ConjLhs>()(x) * conj_if<ConjRhs>()(y);
92 }
93};
94
95template <typename LhsScalar, typename RhsScalar>
96struct conj_helper<LhsScalar, RhsScalar, true, true> {
97 typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResultType;
98
99 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType pmadd(const LhsScalar& x, const RhsScalar& y,
100 const ResultType& c) const {
101 return this->pmul(x, y) + c;
102 }
103
104 // We save a conjuation by using the identity conj(a)*conj(b) = conj(a*b).
105 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType pmul(const LhsScalar& x, const RhsScalar& y) const {
106 return numext::conj(x * y);
107 }
108};
109
110// Implementation with equal type, use packet operations.
111template <typename Packet, bool ConjLhs, bool ConjRhs>
112struct conj_helper<Packet, Packet, ConjLhs, ConjRhs> {
113 typedef Packet ResultType;
114 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmadd(const Packet& x, const Packet& y, const Packet& c) const {
115 return Eigen::internal::pmadd(conj_if<ConjLhs>().pconj(x), conj_if<ConjRhs>().pconj(y), c);
116 }
117
118 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmsub(const Packet& x, const Packet& y, const Packet& c) const {
119 return Eigen::internal::pmsub(conj_if<ConjLhs>().pconj(x), conj_if<ConjRhs>().pconj(y), c);
120 }
121
122 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmul(const Packet& x, const Packet& y) const {
123 return Eigen::internal::pmul(conj_if<ConjLhs>().pconj(x), conj_if<ConjRhs>().pconj(y));
124 }
125};
126
127template <typename Packet>
128struct conj_helper<Packet, Packet, true, true> {
129 typedef Packet ResultType;
130
131 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmadd(const Packet& x, const Packet& y, const Packet& c) const {
132 return Eigen::internal::pmadd(pconj(x), pconj(y), c);
133 }
134 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmsub(const Packet& x, const Packet& y, const Packet& c) const {
135 return Eigen::internal::pmsub(pconj(x), pconj(y), c);
136 }
137 // We save a conjuation by using the identity conj(a)*conj(b) = conj(a*b).
138 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmul(const Packet& x, const Packet& y) const {
139 return pconj(Eigen::internal::pmul(x, y));
140 }
141};
142
143} // namespace internal
144} // namespace Eigen
145
146#endif // EIGEN_ARCH_CONJ_HELPER_H
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1