-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComplexSumRoundInnerProductClass.h
228 lines (216 loc) · 4.65 KB
/
ComplexSumRoundInnerProductClass.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#pragma once
#ifndef COMPLEXSRIPCLASS_H
#define COMPLEXSRIPCLASS_H
#include "ComplexCoreClass.h"
TemplateDefinition
class ComplexSumRoundInnerProductClass : ComplexCoreClass <TemplateParameter>
{
public:
ComplexSumRoundInnerProductClass()
{
// dont call base class default constructor directly, icc has problem with it.
// default constructor of base class automatically called befor constructor of derived class.
// but parametrized constructor of base class should be called explicitly.
}
ComplexSumRoundInnerProductClass(MemoryManagerClass *MemoryManager) : BaseConstructor
{
}
Ts_sum sum(Ts* A, int arrayLength)
{
Ts_sum sum = 0;
for (int i = 0; i < arrayLength; i++)
{
sum += A[i];
}
return sum;
}
Ts_sum sum(Ta Input)
{
return sum(Input.GetArray(), Input.Length);
}
Tc_sum sum(Tc* A, int arrayLength)
{
Tc_sum sum;
sum.real = 0;
sum.imag = 0;
for (int i = 0; i < arrayLength; i++)
{
sum = sum + A[i];
}
return sum;
}
Tc_sum sum(Tca Input)
{
return sum(Input.GetArray(), Input.Length);
}
Ts_sum sum(Ts* A, int StartIndex, int EndIndex)
{
Ts_sum sum = 0;
for (int i = StartIndex; i <= EndIndex; i++)
{
sum += A[i];
}
return sum;
}
Ts_sum sumReal(Tc* A, int arrayLength)
{
Ts_sum sum;
sum = 0;
for (int i = 0; i < arrayLength; i++)
{
sum = sum + A[i].real;
}
return sum;
}
Ts_sum sumReal(Tca Input)
{
return sumReal(Input.GetArray(), Input.Length);
}
Ts_sum sumImage(Tc* A, int arrayLength)
{
Ts_sum sum;
sum = 0;
for (int i = 0; i < arrayLength; i++)
{
sum = sum + A[i].imag;
}
return sum;
}
Ts_sum sumImage(Tca Input)
{
return sumImage(Input.GetArray(), Input.Length);
}
Ts Round(Ts A)
{
return round(A);
//return floor(A + 0.5);
}
Tc Round(Tc A)
{
Tc res;
res.real = Round(A.real);
res.imag = Round(A.imag);
return res;
}
Ts* Round(Ts* A, int ALength)
{
Ts* res = this->AllocMem_Single(ALength);
for (int i = 0; i < ALength; i++)
{
res[i] = Round(A[i]);
}
return res;
}
Ta Round(Ta Input)
{
Ta res(this->MemManager);
res.SetArray(Round(Input.GetArray(), Input.Length), Input.Length);
return res;
}
Tc* Round(Tc* A, int ALength)
{
Tc* res = this->AllocMem_Complex(ALength);
for (int i = 0; i < ALength; i++)
{
res[i].real = Round(A[i].real);
res[i].imag = Round(A[i].imag);
}
return res;
}
Tca Round(Tca Input)
{
Tca res(this->MemManager);
res.SetArray(Round(Input.GetArray(), Input.Length), Input.Length);
return res;
}
void Round_inplace(Tc* A, int ALength)
{
for (int i = 0; i < ALength; i++)
{
A[i].real = Round(A[i].real);//loop vectorized
A[i].imag = Round(A[i].imag);
}
}
void Round_inplace(Tca Input)
{
Round_inplace(Input.GetArray(), Input.Length);
}
void Round_inplace(Ts* A, int ALength)
{
for (int i = 0; i < ALength; i++)
{
A[i] = Round(A[i]); //loop vectorized
}
}
void Round_inplace(Ta Input)
{
Round_inplace(Input.GetArray(), Input.Length);
}
void RoundReal_inplace(Tc* A, int ALength)
{
for (int i = 0; i < ALength; i++)
{
A[i].real = Round(A[i].real);//loop vectorized
}
}
void RoundReal_inplace(Tca Input)
{
RoundReal_inplace(Input.GetArray(), Input.Length);
}
void RoundImage_inplace(Tc* A, int ALength)
{
for (int i = 0; i < ALength; i++)
{
A[i].imag = Round(A[i].image);//loop vectorized
}
}
void RoundImage_inplace(Tca Input)
{
RoundImage_inplace(Input.GetArray(), Input.Length);
}
Ts_sum InnerProduct(Ts *A, Ts *B, int arrayLength)
{
Ts_sum InPr = 0;
for (int i = 0; i < arrayLength; i++)
{
InPr = InPr + (A[i] * B[i]);
}
return InPr;
}
Ts_sum InnerProduct(Ta Input, Ta B)
{
return InnerProduct(Input.GetArray(), B.GetArray(), Input.Length);
}
Tc_sum InnerProduct(Tc *A, Tc *B, int arrayLength)
{
Tc_sum InPr;
InPr.real = 0;
InPr.imag = 0;
for (int i = 0; i < arrayLength; i++)
{
InPr = InPr + (A[i] * B[i]);
}
return InPr;
}
Tc_sum InnerProduct(Tca Input, Tca B)
{
return InnerProduct(Input.GetArray(), B.GetArray(), Input.Length);
}
Tc_sum InnerProductA_ConjB(Tc *A, Tc *B, int arrayLength)
{
Tc_sum InPr;
InPr.real = 0;
InPr.imag = 0;
for (int i = 0; i < arrayLength; i++)
{
InPr.real += (A[i].real * B[i].real) + (A[i].imag * B[i].imag);
InPr.imag += (A[i].imag * B[i].real)-(A[i].real * B[i].imag);
}
return InPr;
}
Tc_sum InnerProductA_ConjB(Tca Input, Tca B)
{
return InnerProductA_ConjB(Input.GetArray(), B.GetArray(), Input.Length);
}
};
#endif