23#ifndef HIP_INCLUDE_HIP_AMD_DETAIL_HIP_COMPLEX_H
24#define HIP_INCLUDE_HIP_AMD_DETAIL_HIP_COMPLEX_H
26#include "hip/amd_detail/amd_hip_vector_types.h"
28#if defined(__HIPCC_RTC__)
29#define __HOST_DEVICE__ __device__
31#define __HOST_DEVICE__ __host__ __device__
43#define COMPLEX_NEG_OP_OVERLOAD(type) \
44 __HOST_DEVICE__ static inline type operator-(const type& op) { \
51#define COMPLEX_EQ_OP_OVERLOAD(type) \
52 __HOST_DEVICE__ static inline bool operator==(const type& lhs, const type& rhs) { \
53 return lhs.x == rhs.x && lhs.y == rhs.y; \
56#define COMPLEX_NE_OP_OVERLOAD(type) \
57 __HOST_DEVICE__ static inline bool operator!=(const type& lhs, const type& rhs) { \
58 return !(lhs == rhs); \
61#define COMPLEX_ADD_OP_OVERLOAD(type) \
62 __HOST_DEVICE__ static inline type operator+(const type& lhs, const type& rhs) { \
64 ret.x = lhs.x + rhs.x; \
65 ret.y = lhs.y + rhs.y; \
69#define COMPLEX_SUB_OP_OVERLOAD(type) \
70 __HOST_DEVICE__ static inline type operator-(const type& lhs, const type& rhs) { \
72 ret.x = lhs.x - rhs.x; \
73 ret.y = lhs.y - rhs.y; \
77#define COMPLEX_MUL_OP_OVERLOAD(type) \
78 __HOST_DEVICE__ static inline type operator*(const type& lhs, const type& rhs) { \
80 ret.x = lhs.x * rhs.x - lhs.y * rhs.y; \
81 ret.y = lhs.x * rhs.y + lhs.y * rhs.x; \
85#define COMPLEX_DIV_OP_OVERLOAD(type) \
86 __HOST_DEVICE__ static inline type operator/(const type& lhs, const type& rhs) { \
88 ret.x = (lhs.x * rhs.x + lhs.y * rhs.y); \
89 ret.y = (rhs.x * lhs.y - lhs.x * rhs.y); \
90 ret.x = ret.x / (rhs.x * rhs.x + rhs.y * rhs.y); \
91 ret.y = ret.y / (rhs.x * rhs.x + rhs.y * rhs.y); \
95#define COMPLEX_ADD_PREOP_OVERLOAD(type) \
96 __HOST_DEVICE__ static inline type& operator+=(type& lhs, const type& rhs) { \
102#define COMPLEX_SUB_PREOP_OVERLOAD(type) \
103 __HOST_DEVICE__ static inline type& operator-=(type& lhs, const type& rhs) { \
109#define COMPLEX_MUL_PREOP_OVERLOAD(type) \
110 __HOST_DEVICE__ static inline type& operator*=(type& lhs, const type& rhs) { \
112 lhs.x = rhs.x * temp.x - rhs.y * temp.y; \
113 lhs.y = rhs.y * temp.x + rhs.x * temp.y; \
117#define COMPLEX_DIV_PREOP_OVERLOAD(type) \
118 __HOST_DEVICE__ static inline type& operator/=(type& lhs, const type& rhs) { \
120 temp.x = (lhs.x*rhs.x + lhs.y * rhs.y) / (rhs.x*rhs.x + rhs.y*rhs.y); \
121 temp.y = (lhs.y * rhs.x - lhs.x * rhs.y) / (rhs.x*rhs.x + rhs.y*rhs.y); \
126#define COMPLEX_SCALAR_PRODUCT(type, type1) \
127 __HOST_DEVICE__ static inline type operator*(const type& lhs, type1 rhs) { \
129 ret.x = lhs.x * rhs; \
130 ret.y = lhs.y * rhs; \
138__HOST_DEVICE__
static inline float hipCrealf(
hipFloatComplex z) {
return z.x; }
140__HOST_DEVICE__
static inline float hipCimagf(
hipFloatComplex z) {
return z.y; }
142__HOST_DEVICE__
static inline hipFloatComplex make_hipFloatComplex(
float a,
float b) {
157 return z.x * z.x + z.y * z.y;
161 return make_hipFloatComplex(p.x + q.x, p.y + q.y);
165 return make_hipFloatComplex(p.x - q.x, p.y - q.y);
169 return make_hipFloatComplex(p.x * q.x - p.y * q.y, p.y * q.x + p.x * q.y);
173 float sqabs = hipCsqabsf(q);
175 ret.x = (p.x * q.x + p.y * q.y) / sqabs;
176 ret.y = (p.y * q.x - p.x * q.y) / sqabs;
180__HOST_DEVICE__
static inline float hipCabsf(
hipFloatComplex z) {
return sqrtf(hipCsqabsf(z)); }
185__HOST_DEVICE__
static inline double hipCreal(
hipDoubleComplex z) {
return z.x; }
187__HOST_DEVICE__
static inline double hipCimag(
hipDoubleComplex z) {
return z.y; }
189__HOST_DEVICE__
static inline hipDoubleComplex make_hipDoubleComplex(
double a,
double b) {
204 return z.x * z.x + z.y * z.y;
208 return make_hipDoubleComplex(p.x + q.x, p.y + q.y);
212 return make_hipDoubleComplex(p.x - q.x, p.y - q.y);
216 return make_hipDoubleComplex(p.x * q.x - p.y * q.y, p.y * q.x + p.x * q.y);
220 double sqabs = hipCsqabs(q);
222 ret.x = (p.x * q.x + p.y * q.y) / sqabs;
223 ret.y = (p.y * q.x - p.x * q.y) / sqabs;
227__HOST_DEVICE__
static inline double hipCabs(
hipDoubleComplex z) {
return sqrt(hipCsqabs(z)); }
281__HOST_DEVICE__
static inline hipComplex make_hipComplex(
float x,
float y) {
282 return make_hipFloatComplex(x, y);
286 return make_hipFloatComplex((
float)z.x, (
float)z.y);
290 return make_hipDoubleComplex((
double)z.x, (
double)z.y);
294 float real = (p.x * q.x) + r.x;
295 float imag = (q.x * p.y) + r.y;
297 real = -(p.y * q.y) + real;
298 imag = (p.x * q.y) + imag;
300 return make_hipComplex(real, imag);
305 double real = (p.x * q.x) + r.x;
306 double imag = (q.x * p.y) + r.y;
308 real = -(p.y * q.y) + real;
309 imag = (p.x * q.y) + imag;
311 return make_hipDoubleComplex(real, imag);
Definition amd_hip_vector_types.h:1986
Definition amd_hip_vector_types.h:2023