Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:51:39

0001 
0002 // This file is part of Eigen, a lightweight C++ template library
0003 // for linear algebra.
0004 //
0005 // Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
0006 //
0007 // This Source Code Form is subject to the terms of the Mozilla
0008 // Public License v. 2.0. If a copy of the MPL was not distributed
0009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0010 
0011 #ifndef EIGEN_ARCH_CONJ_HELPER_H
0012 #define EIGEN_ARCH_CONJ_HELPER_H
0013 
0014 #define EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(PACKET_CPLX, PACKET_REAL)      \
0015   template <>                                                           \
0016   struct conj_helper<PACKET_REAL, PACKET_CPLX, false, false> {          \
0017     EIGEN_STRONG_INLINE PACKET_CPLX pmadd(const PACKET_REAL& x,         \
0018                                           const PACKET_CPLX& y,         \
0019                                           const PACKET_CPLX& c) const { \
0020       return padd(c, this->pmul(x, y));                                 \
0021     }                                                                   \
0022     EIGEN_STRONG_INLINE PACKET_CPLX pmul(const PACKET_REAL& x,          \
0023                                          const PACKET_CPLX& y) const {  \
0024       return PACKET_CPLX(Eigen::internal::pmul<PACKET_REAL>(x, y.v));   \
0025     }                                                                   \
0026   };                                                                    \
0027                                                                         \
0028   template <>                                                           \
0029   struct conj_helper<PACKET_CPLX, PACKET_REAL, false, false> {          \
0030     EIGEN_STRONG_INLINE PACKET_CPLX pmadd(const PACKET_CPLX& x,         \
0031                                           const PACKET_REAL& y,         \
0032                                           const PACKET_CPLX& c) const { \
0033       return padd(c, this->pmul(x, y));                                 \
0034     }                                                                   \
0035     EIGEN_STRONG_INLINE PACKET_CPLX pmul(const PACKET_CPLX& x,          \
0036                                          const PACKET_REAL& y) const {  \
0037       return PACKET_CPLX(Eigen::internal::pmul<PACKET_REAL>(x.v, y));   \
0038     }                                                                   \
0039   };
0040 
0041 namespace Eigen {
0042 namespace internal {
0043 
0044 template<bool Conjugate> struct conj_if;
0045 
0046 template<> struct conj_if<true> {
0047   template<typename T>
0048   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T operator()(const T& x) const { return numext::conj(x); }
0049   template<typename T>
0050   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T pconj(const T& x) const { return internal::pconj(x); }
0051 };
0052 
0053 template<> struct conj_if<false> {
0054   template<typename T>
0055   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T& operator()(const T& x) const { return x; }
0056   template<typename T>
0057   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T& pconj(const T& x) const { return x; }
0058 };
0059 
0060 // Generic Implementation, assume scalars since the packet-version is
0061 // specialized below.
0062 template<typename LhsType, typename RhsType, bool ConjLhs, bool ConjRhs>
0063 struct conj_helper {
0064   typedef typename ScalarBinaryOpTraits<LhsType, RhsType>::ReturnType ResultType;
0065 
0066   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType
0067   pmadd(const LhsType& x, const RhsType& y, const ResultType& c) const
0068   { return this->pmul(x, y) + c; }
0069 
0070   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType
0071   pmul(const LhsType& x, const RhsType& y) const
0072   { return conj_if<ConjLhs>()(x) * conj_if<ConjRhs>()(y); }
0073 };
0074 
0075 template<typename LhsScalar, typename RhsScalar>
0076 struct conj_helper<LhsScalar, RhsScalar, true, true> {
0077   typedef typename ScalarBinaryOpTraits<LhsScalar,RhsScalar>::ReturnType ResultType;
0078 
0079   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType
0080   pmadd(const LhsScalar& x, const RhsScalar& y, const ResultType& c) const
0081   { return this->pmul(x, y) + c; }
0082 
0083   // We save a conjuation by using the identity conj(a)*conj(b) = conj(a*b).
0084   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ResultType
0085   pmul(const LhsScalar& x, const RhsScalar& y) const
0086   { return numext::conj(x * y); }
0087 };
0088 
0089 // Implementation with equal type, use packet operations.
0090 template<typename Packet, bool ConjLhs, bool ConjRhs>
0091 struct conj_helper<Packet, Packet, ConjLhs, ConjRhs>
0092 {
0093   typedef Packet ResultType;
0094   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmadd(const Packet& x, const Packet& y, const Packet& c) const
0095   { return Eigen::internal::pmadd(conj_if<ConjLhs>().pconj(x), conj_if<ConjRhs>().pconj(y), c); }
0096 
0097 
0098   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmul(const Packet& x, const Packet& y) const
0099   { return Eigen::internal::pmul(conj_if<ConjLhs>().pconj(x), conj_if<ConjRhs>().pconj(y)); }
0100 };
0101 
0102 template<typename Packet>
0103 struct conj_helper<Packet, Packet, true, true>
0104 {
0105   typedef Packet ResultType;
0106 
0107   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmadd(const Packet& x, const Packet& y, const Packet& c) const
0108   { return Eigen::internal::pmadd(pconj(x), pconj(y), c); }
0109   // We save a conjuation by using the identity conj(a)*conj(b) = conj(a*b).
0110   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pmul(const Packet& x, const Packet& y) const
0111   { return pconj(Eigen::internal::pmul(x, y)); }
0112 };
0113 
0114 }  // namespace internal
0115 }  // namespace Eigen
0116 
0117 #endif  // EIGEN_ARCH_CONJ_HELPER_H