-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapping_gpu.jl
367 lines (306 loc) · 22.7 KB
/
mapping_gpu.jl
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
using CUDA
# DFT_to_beta
function DFT_to_beta_1d!(beta::CuVector{Float64}, v::CuVector{ComplexF64}, size; rdft::Bool=false)
N = size[1]
M = N ÷ 2
view(beta, 1:2) .= real.(view(v, 1:M:M+1))
view(beta, 3:M+1) .= sqrt(2) .* real.(view(v, 2:M))
view(beta, M+2:N) .= sqrt(2) .* imag.(view(v, 2:M))
return beta
end
function DFT_to_beta_2d!(beta::CuVector{Float64}, v::CuMatrix{ComplexF64}, size; rdft::Bool=false)
N1 = size[1]
N2 = size[2]
M1 = N1 ÷ 2
M2 = N2 ÷ 2
P1 = M1 - 1
P2 = M2 - 1
PP = P1 * P2
view(beta, 1:2) .= real.(view(v, 1 , 1:M2:M2+1))
view(beta, 3:4) .= real.(view(v, M1+1, 1:M2:M2+1))
view(beta, 5 :4+ P2 ) .= sqrt(2) .* real.(view(v, 1, 2:M2))
view(beta, 5+ P2 :4+2*P2 ) .= sqrt(2) .* imag.(view(v, 1, 2:M2))
view(beta, 5+2*P2 :4+3*P2 ) .= sqrt(2) .* real.(view(v, M1+1, 2:M2))
view(beta, 5+3*P2 :4+4*P2 ) .= sqrt(2) .* imag.(view(v, M1+1, 2:M2))
view(beta, 5+4*P2 :4+4*P2+P1 ) .= sqrt(2) .* real.(view(v, 2:M1, 1))
view(beta, 5+4*P2+ P1 :4+4*P2+2*P1 ) .= sqrt(2) .* imag.(view(v, 2:M1, 1))
view(beta, 5+4*P2+2*P1 :4+4*P2+3*P1 ) .= sqrt(2) .* real.(view(v, 2:M1, M2+1))
view(beta, 5+4*P2+3*P1 :4+4*P2+4*P1 ) .= sqrt(2) .* imag.(view(v, 2:M1, M2+1))
view(beta, 5+4*P2+4*P1 :4+4*P2+4*P1+ PP) .= sqrt(2) .* real.(view(v, 2:M1, 2:M2) |> vec)
view(beta, 5+4*P2+4*P1+ PP:4+4*P2+4*P1+2*PP) .= sqrt(2) .* imag.(view(v, 2:M1, 2:M2) |> vec)
view(beta, 5+4*P2+4*P1+2*PP:4+4*P2+4*P1+3*PP) .= sqrt(2) .* real.(view(v, 2:M1, M2+2:N2) |> vec)
view(beta, 5+4*P2+4*P1+3*PP:4+4*P2+4*P1+4*PP) .= sqrt(2) .* imag.(view(v, 2:M1, M2+2:N2) |> vec)
return beta
end
function DFT_to_beta_3d!(beta::CuVector{Float64}, v::CuArray{ComplexF64,3}, size; rdft::Bool=false)
N1 = size[1]
N2 = size[2]
N3 = size[3]
M1 = N1 ÷ 2
M2 = N2 ÷ 2
M3 = N3 ÷ 2
P1 = M1 - 1
P2 = M2 - 1
P3 = M3 - 1
P23 = P2 * P3
P13 = P1 * P3
P12 = P1 * P2
P123 = P1 * P2 * P3
view(beta, 1:2) .= real.(view(v, 1 , 1 , 1:M3:M3+1))
view(beta, 3:4) .= real.(view(v, 1 , M2+1, 1:M3:M3+1))
view(beta, 5:6) .= real.(view(v, M1+1, 1 , 1:M3:M3+1))
view(beta, 7:8) .= real.(view(v, M1+1, M2+1, 1:M3:M3+1))
view(beta,9 :8+ P3 ) .= sqrt(2) .* real.(view(v,1, 1, 2:M3))
view(beta,9+ P3 :8+2*P3 ) .= sqrt(2) .* imag.(view(v,1, 1, 2:M3))
view(beta,9+2*P3 :8+3*P3 ) .= sqrt(2) .* real.(view(v,1, M2+1, 2:M3))
view(beta,9+3*P3 :8+4*P3 ) .= sqrt(2) .* imag.(view(v,1, M2+1, 2:M3))
view(beta,9+4*P3 :8+5*P3 ) .= sqrt(2) .* real.(view(v,M1+1, 1, 2:M3))
view(beta,9+5*P3 :8+6*P3 ) .= sqrt(2) .* imag.(view(v,M1+1, 1, 2:M3))
view(beta,9+6*P3 :8+7*P3 ) .= sqrt(2) .* real.(view(v,M1+1, M2+1, 2:M3))
view(beta,9+7*P3 :8+8*P3 ) .= sqrt(2) .* imag.(view(v,M1+1, M2+1, 2:M3))
view(beta,9+8*P3 :8+8*P3+ P2 ) .= sqrt(2) .* real.(view(v,1, 2:M2, 1))
view(beta,9+8*P3+ P2 :8+8*P3+2*P2 ) .= sqrt(2) .* imag.(view(v,1, 2:M2, 1))
view(beta,9+8*P3+2*P2 :8+8*P3+3*P2 ) .= sqrt(2) .* real.(view(v,1, 2:M2, M3+1))
view(beta,9+8*P3+3*P2 :8+8*P3+4*P2 ) .= sqrt(2) .* imag.(view(v,1, 2:M2, M3+1))
view(beta,9+8*P3+4*P2 :8+8*P3+5*P2 ) .= sqrt(2) .* real.(view(v,M1+1, 2:M2, 1))
view(beta,9+8*P3+5*P2 :8+8*P3+6*P2 ) .= sqrt(2) .* imag.(view(v,M1+1, 2:M2, 1))
view(beta,9+8*P3+6*P2 :8+8*P3+7*P2 ) .= sqrt(2) .* real.(view(v,M1+1, 2:M2, M3+1))
view(beta,9+8*P3+7*P2 :8+8*P3+8*P2 ) .= sqrt(2) .* imag.(view(v,M1+1, 2:M2, M3+1))
view(beta,9+8*P3+8*P2 :8+8*P3+8*P2+ P1 ) .= sqrt(2) .* real.(view(v,2:M1, 1, 1))
view(beta,9+8*P3+8*P2+ P1 :8+8*P3+8*P2+2*P1 ) .= sqrt(2) .* imag.(view(v,2:M1, 1, 1))
view(beta,9+8*P3+8*P2+2*P1 :8+8*P3+8*P2+3*P1 ) .= sqrt(2) .* real.(view(v,2:M1, 1, M3+1))
view(beta,9+8*P3+8*P2+3*P1 :8+8*P3+8*P2+4*P1 ) .= sqrt(2) .* imag.(view(v,2:M1, 1, M3+1))
view(beta,9+8*P3+8*P2+4*P1 :8+8*P3+8*P2+5*P1 ) .= sqrt(2) .* real.(view(v,2:M1, M2+1, 1))
view(beta,9+8*P3+8*P2+5*P1 :8+8*P3+8*P2+6*P1 ) .= sqrt(2) .* imag.(view(v,2:M1, M2+1, 1))
view(beta,9+8*P3+8*P2+6*P1 :8+8*P3+8*P2+7*P1 ) .= sqrt(2) .* real.(view(v,2:M1, M2+1, M3+1))
view(beta,9+8*P3+8*P2+7*P1 :8+8*P3+8*P2+8*P1 ) .= sqrt(2) .* imag.(view(v,2:M1, M2+1, M3+1))
view(beta,9+8*P3+8*P2+8*P1 :8+8*P3+8*P2+8*P1+ P23 ) .= sqrt(2) .* real.(view(v,1, 2:M2, 2:M3) |> vec)
view(beta,9+8*P3+8*P2+8*P1+ P23 :8+8*P3+8*P2+8*P1+2*P23 ) .= sqrt(2) .* imag.(view(v,1, 2:M2, 2:M3) |> vec)
view(beta,9+8*P3+8*P2+8*P1+2*P23 :8+8*P3+8*P2+8*P1+3*P23 ) .= sqrt(2) .* real.(view(v,1, M2+2:N2, 2:M3) |> vec)
view(beta,9+8*P3+8*P2+8*P1+3*P23 :8+8*P3+8*P2+8*P1+4*P23 ) .= sqrt(2) .* imag.(view(v,1, M2+2:N2, 2:M3) |> vec)
view(beta,9+8*P3+8*P2+8*P1+4*P23 :8+8*P3+8*P2+8*P1+5*P23 ) .= sqrt(2) .* real.(view(v,M1+1, 2:M2, 2:M3) |> vec)
view(beta,9+8*P3+8*P2+8*P1+5*P23 :8+8*P3+8*P2+8*P1+6*P23 ) .= sqrt(2) .* imag.(view(v,M1+1, 2:M2, 2:M3) |> vec)
view(beta,9+8*P3+8*P2+8*P1+6*P23 :8+8*P3+8*P2+8*P1+7*P23 ) .= sqrt(2) .* real.(view(v,M1+1, M2+2:N2, 2:M3) |> vec)
view(beta,9+8*P3+8*P2+8*P1+7*P23 :8+8*P3+8*P2+8*P1+8*P23 ) .= sqrt(2) .* imag.(view(v,M1+1, M2+2:N2, 2:M3) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23 :8+8*P3+8*P2+8*P1+8*P23+ P13 ) .= sqrt(2) .* real.(view(v,2:M1, 1, 2:M3) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+ P13 :8+8*P3+8*P2+8*P1+8*P23+2*P13 ) .= sqrt(2) .* imag.(view(v,2:M1, 1, 2:M3) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+2*P13 :8+8*P3+8*P2+8*P1+8*P23+3*P13 ) .= sqrt(2) .* real.(view(v,M1:-1:2, 1, N3:-1:M3+2) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+3*P13 :8+8*P3+8*P2+8*P1+8*P23+4*P13 ) .= -sqrt(2) .* imag.(view(v,M1:-1:2, 1, N3:-1:M3+2) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+4*P13 :8+8*P3+8*P2+8*P1+8*P23+5*P13 ) .= sqrt(2) .* real.(view(v,2:M1, M2+1, 2:M3) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+5*P13 :8+8*P3+8*P2+8*P1+8*P23+6*P13 ) .= sqrt(2) .* imag.(view(v,2:M1, M2+1, 2:M3) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+6*P13 :8+8*P3+8*P2+8*P1+8*P23+7*P13 ) .= sqrt(2) .* real.(view(v,M1:-1:2, M2+1, N3:-1:M3+2) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+7*P13 :8+8*P3+8*P2+8*P1+8*P23+8*P13 ) .= -sqrt(2) .* imag.(view(v,M1:-1:2, M2+1, N3:-1:M3+2) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+8*P13 :8+8*P3+8*P2+8*P1+8*P23+8*P13+ P12 ) .= sqrt(2) .* real.(view(v,2:M1, 2:M2, 1) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+8*P13+ P12 :8+8*P3+8*P2+8*P1+8*P23+8*P13+2*P12 ) .= sqrt(2) .* imag.(view(v,2:M1, 2:M2, 1) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+8*P13+2*P12 :8+8*P3+8*P2+8*P1+8*P23+8*P13+3*P12 ) .= sqrt(2) .* real.(view(v,M1:-1:2, N2:-1:M2+2, 1) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+8*P13+3*P12 :8+8*P3+8*P2+8*P1+8*P23+8*P13+4*P12 ) .= -sqrt(2) .* imag.(view(v,M1:-1:2, N2:-1:M2+2, 1) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+8*P13+4*P12 :8+8*P3+8*P2+8*P1+8*P23+8*P13+5*P12 ) .= sqrt(2) .* real.(view(v,2:M1, 2:M2, M3+1) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+8*P13+5*P12 :8+8*P3+8*P2+8*P1+8*P23+8*P13+6*P12 ) .= sqrt(2) .* imag.(view(v,2:M1, 2:M2, M3+1) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+8*P13+6*P12 :8+8*P3+8*P2+8*P1+8*P23+8*P13+7*P12 ) .= sqrt(2) .* real.(view(v,M1:-1:2, N2:-1:M2+2, M3+1) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+8*P13+7*P12 :8+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12 ) .= -sqrt(2) .* imag.(view(v,M1:-1:2, N2:-1:M2+2, M3+1) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12 :8+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12+ P123) .= sqrt(2) .* real.(view(v,2:M1, 2:M2, 2:M3) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12+ P123:8+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12+2*P123) .= sqrt(2) .* imag.(view(v,2:M1, 2:M2, 2:M3) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12+2*P123:8+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12+3*P123) .= sqrt(2) .* real.(view(v,M1:-1:2, N2:-1:M2+2, N3:-1:M3+2) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12+3*P123:8+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12+4*P123) .= -sqrt(2) .* imag.(view(v,M1:-1:2, N2:-1:M2+2, N3:-1:M3+2) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12+4*P123:8+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12+5*P123) .= sqrt(2) .* real.(view(v,2:M1, M2+2:N2, 2:M3) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12+5*P123:8+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12+6*P123) .= sqrt(2) .* imag.(view(v,2:M1, M2+2:N2, 2:M3) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12+6*P123:8+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12+7*P123) .= sqrt(2) .* real.(view(v,M1:-1:2, M2:-1:2, N3:-1:M3+2) |> vec)
view(beta,9+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12+7*P123:8+8*P3+8*P2+8*P1+8*P23+8*P13+8*P12+8*P123) .= -sqrt(2) .* imag.(view(v,M1:-1:2, M2:-1:2, N3:-1:M3+2) |> vec)
return beta
end
# beta_to_DFT
function beta_to_DFT_1d!(v::CuVector{ComplexF64}, beta::StridedCuVector{Float64}, size; rdft::Bool=false)
N = size[1]
M = N ÷ 2
view(v, 1:M:M+1) .= view(beta, 1:2)
beta_r = view(beta, 3:M+1)
beta_c = view(beta, M+2:N)
view(v, 2:M) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
if !rdft
view(v, N:-1:M+2) .= (beta_r .- im .* beta_c) ./ sqrt(2)
end
return v
end
function beta_to_DFT_2d!(v::CuMatrix{ComplexF64}, beta::StridedCuVector{Float64}, size; rdft::Bool=false)
N1 = size[1]
N2 = size[2]
M1 = N1 ÷ 2
M2 = N2 ÷ 2
P1 = M1 - 1
P2 = M2 - 1
view(v,1:M1:M1+1,M2+1) .= view(beta, 2:2:4)
view(v,1:M1:M1+1) .= view(beta, 1:2:3)
beta_r = view(beta,4+1:4+M2-1)
beta_c = view(beta,4+P2+1:4+2*P2)
view(v, 1, 2:M2) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = view(beta,4+2*P2+1:4+3*P2)
beta_c = view(beta,4+3*P2+1:4+4*P2)
view(v,M1+1, 2:M2) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = view(beta,4+4*P2+1:4+4*P2+P1)
beta_c = view(beta,4+4*P2+P1+1:4+4*P2+2*P1)
view(v,2:M1,1) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = view(beta,4+4*P2+2*P1+1:4+4*P2+3*P1)
beta_c = view(beta,4+4*P2+3*P1+1:4+4*P2+4*P1)
view(v,2:M1,M2+1) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,4+4*P2+4*P1+1:4+4*P2+4*P1+P1*P2), P1, P2)
beta_c = reshape(view(beta,4+4*P2+4*P1+P1*P2+1:4+4*P2+4*P1+2*P1*P2), P1, P2)
view(v,2:M1, 2:M2) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,4+4*P2+4*P1+3*P1*P2:-1:4+4*P2+4*P1+2*P1*P2+1), P1, P2)
beta_c = reshape(view(beta,N1*N2:-1:4+4*P2+4*P1+3*P1*P2+1), P1, P2)
view(v,M1:-1:2,N2:-1:M2+2) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
view(v,1,M2+2:N2) .= conj.(view(v,1,M2:-1:2))
view(v,M1+1,M2+2:N2) .= conj.(view(v,M1+1,M2:-1:2))
if !rdft
beta_r = view(beta,4+4*P2+1:4+4*P2+P1)
beta_c = view(beta,4+4*P2+P1+1:4+4*P2+2*P1)
view(v,N1:-1:M1+2,1) .= (beta_r .- im .* beta_c) ./ sqrt(2)
beta_r = view(beta,4+4*P2+2*P1+1:4+4*P2+3*P1)
beta_c = view(beta,4+4*P2+3*P1+1:4+4*P2+4*P1)
view(v,N1:-1:M1+2,M2+1) .= (beta_r .- im .* beta_c) ./ sqrt(2)
view(v,N1:-1:M1+2,M2:-1:2) .= conj.(view(v,2:M1,M2+2:N2))
view(v,M1+2:N1,M2+2:N2) .= conj.(view(v,M1:-1:2,M2:-1:2))
end
return v
end
function beta_to_DFT_3d!(v::CuArray{ComplexF64, 3}, beta::StridedCuVector{Float64}, size; rdft::Bool=false)
N1 = size[1]
N2 = size[2]
N3 = size[3]
M1 = N1 ÷ 2
M2 = N2 ÷ 2
M3 = N3 ÷ 2
P1 = M1 - 1
P2 = M2 - 1
P3 = M3 - 1
P23 = P2 * P3
P13 = P1 * P3
P12 = P1 * P2
P123 = P1 * P2 * P3
view(v,1 , 1 , 1:M3:M3+1) .= view(beta,1:2)
view(v,1 , M2+1, 1:M3:M3+1) .= view(beta,3:4)
view(v,M1+1, 1 , 1:M3:M3+1) .= view(beta,5:6)
view(v,M1+1, M2+1, 1:M3:M3+1) .= view(beta,7:8)
beta_r = view(beta,9:8+P3)
beta_c = view(beta,9+P3:8+2*P3)
view(v, 1, 1, 2:M3) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = view(beta,9+2*P3:8+3*P3)
beta_c = view(beta,9+3*P3:8+4*P3)
view(v,1, M2+1, 2:M3) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = view(beta,9+4*P3:8+5*P3)
beta_c = view(beta,9+5*P3:8+6*P3)
view(v,M1+1, 1, 2:M3) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = view(beta,9+6*P3:8+7*P3)
beta_c = view(beta,9+7*P3:8+8*P3)
view(v,M1+1, M2+1, 2:M3) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = view(beta,8+8*P3+1:8+8*P3+P2)
beta_c = view(beta,8+8*P3+P2+1:8+8*P3+2*P2)
view(v,1, 2:M2, 1) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = view(beta,8+8*P3+2*P2+1:8+8*P3+3*P2)
beta_c = view(beta,8+8*P3+3*P2+1:8+8*P3+4*P2)
view(v,1, 2:M2, M3+1) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = view(beta,8+8*P3+4*P2+1:8+8*P3+5*P2)
beta_c = view(beta,8+8*P3+5*P2+1:8+8*P3+6*P2)
view(v,M1+1, 2:M2, 1) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = view(beta,8+8*P3+6*P2+1:8+8*P3+7*P2)
beta_c = view(beta,8+8*P3+7*P2+1:8+8*P3+8*P2)
view(v,M1+1, 2:M2, M3+1) .= (beta_r .+ im .* beta_c) ./sqrt(2)
beta_r = view(beta,8+8*P3+8*P2+1:8+8*P3+8*P2+P1)
beta_c = view(beta,8+8*P3+8*P2+P1+1:8+8*P3+8*P2+2*P1)
view(v,2:M1, 1, 1) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = view(beta,8+8*P3+8*P2+2*P1+1:8+8*P3+8*P2+3*P1)
beta_c = view(beta,8+8*P3+8*P2+3*P1+1:8+8*P3+8*P2+4*P1)
view(v,2:M1, 1, M3+1) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = view(beta,8+8*P3+8*P2+4*P1+1:8+8*P3+8*P2+5*P1)
beta_c = view(beta,8+8*P3+8*P2+5*P1+1:8+8*P3+8*P2+6*P1)
view(v,2:M1, M2+1, 1) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = view(beta,8+8*P3+8*P2+6*P1+1:8+8*P3+8*P2+7*P1)
beta_c = view(beta,8+8*P3+8*P2+7*P1+1:8+8*P3+8*P2+8*P1)
view(v, 2:M1, M2+1, M3+1) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,8+8*P3+8*P2+8*P1+1:8+8*P3+8*P2+8*P1+P2*P3), P2, P3)
beta_c = reshape(view(beta,8+8*P3+8*P2+8*P1+P2*P3+1:8+8*P3+8*P2+8*P1+2*P2*P3), P2, P3)
view(v,1, 2:M2, 2:M3) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,8+8*P3+8*P2+8*P1+2*P2*P3+1:8+8*P3+8*P2+8*P1+3*P2*P3), P2, P3)
beta_c = reshape(view(beta,8+8*P3+8*P2+8*P1+3*P2*P3+1:8+8*P3+8*P2+8*P1+4*P2*P3), P2, P3)
view(v,1, M2+2:N2, 2:M3) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,8+8*P3+8*P2+8*P1+4*P2*P3+1:8+8*P3+8*P2+8*P1+5*P2*P3), P2, P3)
beta_c = reshape(view(beta,8+8*P3+8*P2+8*P1+5*P2*P3+1:8+8*P3+8*P2+8*P1+6*P2*P3), P2, P3)
view(v,M1+1, 2:M2, 2:M3) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,8+8*P3+8*P2+8*P1+6*P2*P3+1:8+8*P3+8*P2+8*P1+7*P2*P3), P2, P3)
beta_c = reshape(view(beta,8+8*P3+8*P2+8*P1+7*P2*P3+1:8+8*P3+8*P2+8*P1+8*P2*P3), P2, P3)
view(v,M1+1, M2+2:N2, 2:M3) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+1:8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+P1*P2), P1, P2)
beta_c = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+P1*P2+1:8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+2*P1*P2), P1, P2)
view(v,2:M1, 2:M2, 1) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+2*P1*P2+1:8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+3*P1*P2), P1, P2)
beta_c = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+3*P1*P2+1:8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+4*P1*P2), P1, P2)
view(v,M1:-1:2, N2:-1:M2+2, 1) .= (beta_r .- im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+4*P1*P2+1:8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+5*P1*P2), P1, P2)
beta_c = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+5*P1*P2+1:8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+6*P1*P2), P1, P2)
view(v,2:M1, 2:M2, M3+1) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+6*P1*P2+1:8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+7*P1*P2), P1, P2)
beta_c = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+7*P1*P2+1:8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+8*P1*P2), P1, P2)
view(v,M1:-1:2, N2:-1:M2+2, M3+1) .= (beta_r .- im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+1:8+8*P3+8*P2+8*P1+8*P2*P3+P1*P3), P1, P3)
beta_c = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+P1*P3+1:8+8*P3+8*P2+8*P1+8*P2*P3+2*P1*P3), P1, P3)
view(v,2:M1, 1, 2:M3) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+2*P1*P3+1:8+8*P3+8*P2+8*P1+8*P2*P3+3*P1*P3), P1, P3)
beta_c = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+3*P1*P3+1:8+8*P3+8*P2+8*P1+8*P2*P3+4*P1*P3), P1, P3)
view(v,M1:-1:2, 1, N3:-1:M3+2) .= (beta_r .- im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+4*P1*P3+1:8+8*P3+8*P2+8*P1+8*P2*P3+5*P1*P3), P1, P3)
beta_c = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+5*P1*P3+1:8+8*P3+8*P2+8*P1+8*P2*P3+6*P1*P3), P1, P3)
view(v,2:M1, M2+1, 2:M3) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+6*P1*P3+1:8+8*P3+8*P2+8*P1+8*P2*P3+7*P1*P3), P1, P3)
beta_c = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+7*P1*P3+1:8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3), P1, P3)
view(v,M1:-1:2, M2+1, N3:-1:M3+2) .= (beta_r .- im .* beta_c) ./ sqrt(2)
view(v,1 , M2+2:N2, 1) .= conj.(view(v,1, M2:-1:2, 1))
view(v,M1+1, M2+2:N2, 1) .= conj.(view(v,M1+1, M2:-1:2, 1))
view(v, 1 , M2+2:N2, M3+1) .= conj.(view(v,1, M2:-1:2, M3+1))
view(v, M1+1, M2+2:N2, M3+1) .= conj.(view(v,M1+1, M2:-1:2, M3+1))
view(v,1 , 1, M3+2:N3) .= conj.(view(v,1, 1, M3:-1:2))
view(v,M1+1, 1, M3+2:N3) .= conj.(view(v,M1+1, 1, M3:-1:2))
view(v,1 , M2+1, M3+2:N3) .= conj.(view(v,1, M2+1, M3:-1:2))
view(v,M1+1, M2+1, M3+2:N3) .= conj.(view(v,M1+1, M2+1, M3:-1:2))
view(v,1, 2:M2 , M3+2:N3) .= conj.(view(v,1, N2:-1:M2+2, M3:-1:2))
view(v,1, M2+2:N2, M3+2:N3) .= conj.(view(v,1, M2:-1:2, M3:-1:2))
view(v,M1+1, 2:M2 , M3+2:N3) .= conj.(view(v,M1+1, N2:-1:M2+2, M3:-1:2))
view(v,M1+1, M2+2:N2, M3+2:N3) .= conj.(view(v,M1+1, M2:-1:2, M3:-1:2))
beta_r = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+8*P1*P2+1:8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+8*P1*P2+P1*P2*P3), P1, P2, P3)
beta_c = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+8*P1*P2+P1*P2*P3+1:8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+8*P1*P2+2*P1*P2*P3), P1, P2, P3)
view(v,2:M1, 2:M2, 2:M3) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+8*P1*P2+2*P1*P2*P3+1:8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+8*P1*P2+3*P1*P2*P3), P1, P2, P3)
beta_c = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+8*P1*P2+3*P1*P2*P3+1:8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+8*P1*P2+4*P1*P2*P3), P1, P2, P3)
view(v,M1:-1:2, N2:-1:M2+2, N3:-1:M3+2) .= (beta_r .- im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+8*P1*P2+4*P1*P2*P3+1:8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+8*P1*P2+5*P1*P2*P3), P1, P2, P3)
beta_c = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+8*P1*P2+5*P1*P2*P3+1:8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+8*P1*P2+6*P1*P2*P3), P1, P2, P3)
view(v,2:M1, M2+2:N2, 2:M3) .= (beta_r .+ im .* beta_c) ./ sqrt(2)
beta_r = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+8*P1*P2+6*P1*P2*P3+1:8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+8*P1*P2+7*P1*P2*P3), P1, P2, P3)
beta_c = reshape(view(beta,8+8*P3+8*P2+8*P1+8*P2*P3+8*P1*P3+8*P1*P2+7*P1*P2*P3+1:N1*N2*N3), P1, P2, P3)
view(v,M1:-1:2, M2:-1:2, N3:-1:M3+2) .= (beta_r .- im .* beta_c) ./ sqrt(2)
if !rdft
beta_r = view(beta,8+8*P3+8*P2+P1:-1:8+8*P3+8*P2+1)
beta_c = view(beta,8+8*P3+8*P2+2*P1:-1:8+8*P3+8*P2+P1+1)
view(v,M1+2:N1, 1, 1) .= (beta_r .- im .* beta_c) ./ sqrt(2)
beta_r = view(beta,8+8*P3+8*P2+3*P1:-1:8+8*P3+8*P2+2*P1+1)
beta_c = view(beta,8+8*P3+8*P2+4*P1:-1:8+8*P3+8*P2+3*P1+1)
view(v,M1+2:N1, 1, M3+1) .= (beta_r .- im .* beta_c) ./ sqrt(2)
beta_r = view(beta,8+8*P3+8*P2+5*P1:-1:8+8*P3+8*P2+4*P1+1)
beta_c = view(beta,8+8*P3+8*P2+6*P1:-1:8+8*P3+8*P2+5*P1+1)
view(v, M1+2:N1, M2+1, 1) .= (beta_r .- im .* beta_c) ./ sqrt(2)
beta_r = view(beta,8+8*P3+8*P2+7*P1:-1:8+8*P3+8*P2+6*P1+1)
beta_c = view(beta,8+8*P3+8*P2+8*P1:-1:8+8*P3+8*P2+7*P1+1)
view(v,M1+2:N1, M2+1, M3+1) .= (beta_r .- im .* beta_c) ./ sqrt(2)
view(v, N1:-1:M1+2, M2:-1:2, 1) .= conj.(view(v, 2:M1, M2+2:N2, 1))
view(v, M1+2:N1, M2+2:N2, 1) .= conj.(view(v,M1:-1:2, M2:-1:2, 1))
view(v, N1:-1:M1+2, M2:-1:2, M3+1) .= conj.(view(v, 2:M1, M2+2:N2, M3+1))
view(v, M1+2:N1, M2+2:N2, M3+1) .= conj.(view(v, M1:-1:2, M2:-1:2, M3+1))
view(v, N1:-1:M1+2, 1, M3:-1:2) .= conj.(view(v,2:M1, 1, M3+2:N3))
view(v, M1+2:N1, 1, M3+2:N3) .= conj.(view(v,M1:-1:2, 1, M3:-1:2))
view(v, N1:-1:M1+2, M2+1, M3:-1:2) .= conj.(view(v,2:M1, M2+1, M3+2:N3))
view(v, M1+2:N1, M2+1, M3+2:N3) .= conj.(view(v,M1:-1:2, M2+1, M3:-1:2))
view(v, M1+2:N1, M2+2:N2, M3+2:N3) .= conj.(view(v,M1:-1:2, M2:-1:2, M3:-1:2))
view(v, N1:-1:M1+2, M2:-1:2, M3:-1:2) .= conj.(view(v,2:M1, M2+2:N2, M3+2:N3))
view(v, M1+2:N1, 2:M2, M3+2:N3) .= conj.(view(v,M1:-1:2, N2:-1:M2+2, M3:-1:2))
view(v, N1:-1:M1+2, N2:-1:M2+2, M3:-1:2) .= conj.(view(v,2:M1, 2:M2, M3+2:N3))
end
return v
end