isce3 0.25.0
Loading...
Searching...
No Matches
float2.h
1/*
2 * @file float2.h
3 * @brief Define operators and functions on float2 (cuComplex) datatype
4 *
5 */
6
7#ifndef __FLOAT2_H
8#define __FLOAT2_H
9
10#include <math.h>
11
12#ifndef __CUDACC__
13#define __host__
14#define __device__
15#endif
16
17namespace isce3::matchtemplate::pycuampcor {
18
19struct float2 {
20 float x, y;
21};
22
23struct float3 {
24 float x, y, z;
25};
26
27struct double2 {
28 double x, y;
29};
30
31struct int2 {
32 int x, y;
33};
34
35inline int2 make_int2(int x, int y) {
36 return {x, y};
37}
38
39inline float2 make_float2(float x, float y) {
40 return {x, y};
41}
42
43inline double2 make_double2(double x, double y) {
44 return {x, y};
45}
46
47inline float3 make_float3(float x, float y, float z) {
48 return {x, y, z};
49}
50
51inline __host__ __device__ void zero(float2 &a) { a.x = 0.0f; a.y = 0.0f; }
52
53// negative
54inline __host__ __device__ float2 operator-(float2 &a)
55{
56 return make_float2(-a.x, -a.y);
57}
58
59// complex conjugate
60inline __host__ __device__ float2 conjugate(float2 a)
61{
62 return make_float2(a.x, -a.y);
63}
64
65// addition
66inline __host__ __device__ float2 operator+(float2 a, float2 b)
67{
68 return make_float2(a.x + b.x, a.y + b.y);
69}
70inline __host__ __device__ void operator+=(float2 &a, float2 b)
71{
72 a.x += b.x;
73 a.y += b.y;
74}
75
76inline __host__ __device__ float2 operator+(float2 a, float b)
77{
78 return make_float2(a.x + b, a.y);
79}
80inline __host__ __device__ void operator+=(float2 &a, float b)
81{
82 a.x += b;
83}
84
85inline double2& operator+=(double2& lhs, const float2& rhs)
86{
87 lhs.x += rhs.x;
88 lhs.y += rhs.y;
89 return lhs;
90}
91
92// subtraction
93inline __host__ __device__ float2 operator-(float2 a, float2 b)
94{
95 return make_float2(a.x - b.x, a.y - b.y);
96}
97inline __host__ __device__ void operator-=(float2 &a, float2 b)
98{
99 a.x -= b.x;
100 a.y -= b.y;
101}
102inline __host__ __device__ float2 operator-(float2 a, float b)
103{
104 return make_float2(a.x - b, a.y);
105}
106inline __host__ __device__ void operator-=(float2 &a, float b)
107{
108 a.x -= b;
109}
110
111// multiplication
112inline __host__ __device__ float2 operator*(float2 a, float2 b)
113{
114 return make_float2(a.x*b.x - a.y*b.y, a.y*b.x + a.x*b.y);
115}
116inline __host__ __device__ void operator*=(float2 &a, float2 b)
117{
118 a.x = a.x*b.x - a.y*b.y;
119 a.y = a.y*b.x + a.x*b.y;
120}
121inline __host__ __device__ float2 operator*(float2 a, float b)
122{
123 return make_float2(a.x * b, a.y * b);
124}
125inline __host__ __device__ void operator*=(float2 &a, float b)
126{
127 a.x *= b;
128 a.y *= b;
129}
130inline __host__ __device__ float2 operator*(float2 a, int b)
131{
132 return make_float2(a.x * b, a.y * b);
133}
134inline __host__ __device__ void operator*=(float2 &a, int b)
135{
136 a.x *= b;
137 a.y *= b;
138}
139inline __host__ __device__ float2 complexMul(float2 a, float2 b)
140{
141 return a*b;
142}
143inline __host__ __device__ float2 complexMulConj(float2 a, float2 b)
144{
145 return make_float2(a.x*b.x + a.y*b.y, a.y*b.x - a.x*b.y);
146}
147
148inline __host__ __device__ float2 operator/(float2 a, float b)
149{
150 return make_float2(a.x / b, a.y / b);
151}
152inline __host__ __device__ void operator/=(float2 &a, float b)
153{
154 a.x /= b;
155 a.y /= b;
156}
157
158// abs, arg
159inline __host__ __device__ float complexAbs(float2 a)
160{
161 return sqrtf(a.x*a.x+a.y*a.y);
162}
163inline __host__ __device__ float complexArg(float2 a)
164{
165 return atan2f(a.y, a.x);
166}
167
168// make a complex number from phase
169inline __host__ __device__ float2 complexExp(float arg)
170{
171 return make_float2(cosf(arg), sinf(arg));
172}
173
174} // namespace
175
176#endif //__FLOAT2_H
177// end of file

Generated for ISCE3.0 by doxygen 1.13.2.