Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
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 <[email protected]>
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
38namespace Eigen {
39namespace internal {
40
41template <bool Conjugate>
42struct conj_if;
43
44template <>
45struct conj_if<true> {
46 template <typename T>
47 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T operator()(const T& x) const {
48 return numext::conj(x);
49 }
50 template <typename T>
51 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T pconj(const T& x) const {
52 return internal::pconj(x);
53 }
54};
55
56template <>
57struct conj_if<false> {
58 template <typename T>
59 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T& operator()(const T& x) const {
60 return x;
61 }
62 template <typename T>
63 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T& pconj(const T& x) const {
64 return x;
65 }
66};
67
68// Generic Implementation, assume scalars since the packet-version is
69// specialized below.
70template <typename LhsType, typename RhsType, bool ConjLhs, bool ConjRhs>
71struct conj_helper {
72 typedef typename ScalarBinaryOpTraits<LhsType, RhsType>::ReturnType ResultType;
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
84template <typename LhsScalar, typename RhsScalar>
85struct conj_helper<LhsScalar, RhsScalar, true, true> {
86 typedef typename ScalarBinaryOpTraits<LhsScalar, RhsScalar>::ReturnType ResultType;
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.
100template <typename Packet, bool ConjLhs, bool ConjRhs>
101struct conj_helper<Packet, Packet, ConjLhs, ConjRhs> {
102 typedef Packet ResultType;
103 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmadd(const Packet& x, const Packet& y, const Packet& c) const {
104 return Eigen::internal::pmadd(conj_if<ConjLhs>().pconj(x), conj_if<ConjRhs>().pconj(y), c);
105 }
106
107 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmul(const Packet& x, const Packet& y) const {
108 return Eigen::internal::pmul(conj_if<ConjLhs>().pconj(x), conj_if<ConjRhs>().pconj(y));
109 }
110};
111
112template <typename Packet>
113struct conj_helper<Packet, Packet, true, true> {
114 typedef Packet ResultType;
115
116 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmadd(const Packet& x, const Packet& y, const Packet& c) const {
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).
120 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmul(const Packet& x, const Packet& y) const {
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
Namespace containing all symbols from the Eigen library.
Definition Core:137