-
Notifications
You must be signed in to change notification settings - Fork 1
/
mapping.jl
292 lines (254 loc) · 25.3 KB
/
mapping.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
using LinearAlgebra;
using FFTW;
# mapping between DFT and real vector beta
# mapping DFT to beta
# @param dim The dimension of the problem (dim = 1, 2, 3)
# @param size The size of each dimension of the problem
#(we only consider the cases when the sizes are even for all the dimenstions)
#(size is a tuple, e.g. size = (10, 20, 30))
# @param v DFT
# @details This fucnction maps DFT to beta
# @return A 1-dimensional real vector beta whose length is the product of size
# @example
# >dim = 2;
# >size1 = (6, 8);
# >x = randn(6, 8);
# >v = fft(x)/sqrt(prod(size1));
# >beta = DFT_to_beta(dim, size1, v);
function DFT_to_beta(dim, size, v)
if (dim == 1)
return DFT_to_beta_1d(v, size)
elseif (dim == 2)
return DFT_to_beta_2d(v, size)
else
return DFT_to_beta_3d(v, size)
end
end
# dim = 1
function DFT_to_beta_1d(v, size)
N = size[1];
beta = [real.(v[1]);
real.(v[Int(N/2)+1]);
sqrt(2).*(real.(v[2:Int(N/2)]));
sqrt(2).*(imag.(v[2:Int(N/2)]))];
return beta
end
# dim = 2
function DFT_to_beta_2d(v, size)
N1 = size[1];
N2 = size[2];
beta = [real.(v[1, 1]);
real.(v[1, Int(N2/2+1)]);
real.(v[Int(N1/2+1), 1]);
real.(v[Int(N1/2+1), Int(N2/2+1)]);
sqrt(2).*(real.(v[1, 2:Int(N2/2)]));
sqrt(2).*(imag.(v[1, 2:Int(N2/2)]));
sqrt(2).*(real.(v[Int(N1/2+1), 2:Int(N2/2)]));
sqrt(2).*(imag.(v[Int(N1/2+1), 2:Int(N2/2)]));
sqrt(2).*(real.(v[2:Int(N1/2), 1]));
sqrt(2).*(imag.(v[2:Int(N1/2), 1]));
sqrt(2).*(real.(v[2:Int(N1/2), Int(N2/2+1)]));
sqrt(2).*(imag.(v[2:Int(N1/2), Int(N2/2+1)]));
sqrt(2).*(reshape(real.(v[2:Int(N1/2), 2:Int(N2/2)]), Int((N1/2-1)*(N2/2-1))));
sqrt(2).*(reshape(imag.(v[2:Int(N1/2), 2:Int(N2/2)]), Int((N1/2-1)*(N2/2-1))));
sqrt(2).*(reshape(real.(v[2:Int(N1/2), Int(N2/2+2):N2]), Int((N1/2-1)*(N2/2-1))));
sqrt(2).*(reshape(imag.(v[2:Int(N1/2), Int(N2/2+2):N2]), Int((N1/2-1)*(N2/2-1))))]
return beta
end
# dim = 3
function DFT_to_beta_3d(v, size)
N1 = size[1];
N2 = size[2];
N3 = size[3];
beta = [real.(v[1,1,1]); real.(v[1,1,Int(N3/2+1)]); real.(v[1,Int(N2/2+1),1]); real.(v[1,Int(N2/2+1),Int(N3/2+1)]);
real.(v[Int(N1/2+1),1,1]); real.(v[Int(N1/2+1),1,Int(N3/2+1)]); real.(v[Int(N1/2+1),Int(N2/2+1),1]); real.(v[Int(N1/2+1),Int(N2/2+1),Int(N3/2+1)]);
sqrt(2).*(real.(v[1, 1, 2:Int(N3/2)]));
sqrt(2).*(imag.(v[1, 1, 2:Int(N3/2)]));
sqrt(2).*(real.(v[1, Int(N2/2+1), 2:Int(N3/2)]));
sqrt(2).*(imag.(v[1, Int(N2/2+1), 2:Int(N3/2)]));
sqrt(2).*(real.(v[Int(N1/2+1), 1, 2:Int(N3/2)]));
sqrt(2).*(imag.(v[Int(N1/2+1), 1, 2:Int(N3/2)]));
sqrt(2).*(real.(v[Int(N1/2+1), Int(N2/2+1), 2:Int(N3/2)]));
sqrt(2).*(imag.(v[Int(N1/2+1), Int(N2/2+1), 2:Int(N3/2)]));
sqrt(2).*(real.(v[1, 2:Int(N2/2), 1]));
sqrt(2).*(imag.(v[1, 2:Int(N2/2), 1]));
sqrt(2).*(real.(v[1, 2:Int(N2/2), Int(N3/2+1)]));
sqrt(2).*(imag.(v[1, 2:Int(N2/2), Int(N3/2+1)]));
sqrt(2).*(real.(v[Int(N1/2+1), 2:Int(N2/2), 1]));
sqrt(2).*(imag.(v[Int(N1/2+1), 2:Int(N2/2), 1]));
sqrt(2).*(real.(v[Int(N1/2+1), 2:Int(N2/2), Int(N3/2+1)]));
sqrt(2).*(imag.(v[Int(N1/2+1), 2:Int(N2/2), Int(N3/2+1)]));
sqrt(2).*(real.(v[2:Int(N1/2), 1, 1]));
sqrt(2).*(imag.(v[2:Int(N1/2), 1, 1]));
sqrt(2).*(real.(v[2:Int(N1/2), 1, Int(N3/2+1)]));
sqrt(2).*(imag.(v[2:Int(N1/2), 1, Int(N3/2+1)]));
sqrt(2).*(real.(v[2:Int(N1/2), Int(N2/2+1), 1]));
sqrt(2).*(imag.(v[2:Int(N1/2), Int(N2/2+1), 1]));
sqrt(2).*(real.(v[2:Int(N1/2), Int(N2/2+1), Int(N3/2+1)]));
sqrt(2).*(imag.(v[2:Int(N1/2), Int(N2/2+1), Int(N3/2+1)]));
reshape(sqrt(2).*(real.(v[1, 2:Int(N2/2), 2:Int(N3/2)])), Int((N2/2-1)*(N3/2-1)));
reshape(sqrt(2).*(imag.(v[1, 2:Int(N2/2), 2:Int(N3/2)])), Int((N2/2-1)*(N3/2-1)));
reshape(sqrt(2).*(real.(v[1, Int(N2/2+2):N2, 2:Int(N3/2)])), Int((N2/2-1)*(N3/2-1)));
reshape(sqrt(2).*(imag.(v[1, Int(N2/2+2):N2, 2:Int(N3/2)])), Int((N2/2-1)*(N3/2-1)));
reshape(sqrt(2).*(real.(v[Int(N1/2+1), 2:Int(N2/2), 2:Int(N3/2)])), Int((N2/2-1)*(N3/2-1)));
reshape(sqrt(2).*(imag.(v[Int(N1/2+1), 2:Int(N2/2), 2:Int(N3/2)])), Int((N2/2-1)*(N3/2-1)));
reshape(sqrt(2).*(real.(v[Int(N1/2+1), Int(N2/2+2):N2, 2:Int(N3/2)])), Int((N2/2-1)*(N3/2-1)));
reshape(sqrt(2).*(imag.(v[Int(N1/2+1), Int(N2/2+2):N2, 2:Int(N3/2)])), Int((N2/2-1)*(N3/2-1)));
reshape(sqrt(2).*(real.(v[2:Int(N1/2), 1, 2:Int(N3/2)])), Int((N1/2-1)*(N3/2-1)));
reshape(sqrt(2).*(imag.(v[2:Int(N1/2), 1, 2:Int(N3/2)])), Int((N1/2-1)*(N3/2-1)));
reshape(sqrt(2).*(real.(v[Int(N1/2+2):N1, 1, 2:Int(N3/2)])), Int((N1/2-1)*(N3/2-1)));
reshape(sqrt(2).*(imag.(v[Int(N1/2+2):N1, 1, 2:Int(N3/2)])), Int((N1/2-1)*(N3/2-1)));
reshape(sqrt(2).*(real.(v[2:Int(N1/2), Int(N2/2+1), 2:Int(N3/2)])), Int((N1/2-1)*(N3/2-1)));
reshape(sqrt(2).*(imag.(v[2:Int(N1/2), Int(N2/2+1), 2:Int(N3/2)])), Int((N1/2-1)*(N3/2-1)));
reshape(sqrt(2).*(real.(v[Int(N1/2+2):N1, Int(N2/2+1), 2:Int(N3/2)])), Int((N1/2-1)*(N3/2-1)));
reshape(sqrt(2).*(imag.(v[Int(N1/2+2):N1, Int(N2/2+1), 2:Int(N3/2)])), Int((N1/2-1)*(N3/2-1)));
reshape(sqrt(2).*(real.(v[2:Int(N1/2), 2:Int(N2/2), 1])), Int((N1/2-1)*(N2/2-1)));
reshape(sqrt(2).*(imag.(v[2:Int(N1/2), 2:Int(N2/2), 1])), Int((N1/2-1)*(N2/2-1)));
reshape(sqrt(2).*(real.(v[Int(N1/2+2):N1, 2:Int(N2/2), 1])), Int((N1/2-1)*(N2/2-1)));
reshape(sqrt(2).*(imag.(v[Int(N1/2+2):N1, 2:Int(N2/2), 1])), Int((N1/2-1)*(N2/2-1)));
reshape(sqrt(2).*(real.(v[2:Int(N1/2), 2:Int(N2/2), Int(N3/2+1)])), Int((N1/2-1)*(N2/2-1)));
reshape(sqrt(2).*(imag.(v[2:Int(N1/2), 2:Int(N2/2), Int(N3/2+1)])), Int((N1/2-1)*(N2/2-1)));
reshape(sqrt(2).*(real.(v[Int(N1/2+2):N1, 2:Int(N2/2), Int(N3/2+1)])), Int((N1/2-1)*(N2/2-1)));
reshape(sqrt(2).*(imag.(v[Int(N1/2+2):N1, 2:Int(N2/2), Int(N3/2+1)])), Int((N1/2-1)*(N2/2-1)));
reshape(sqrt(2).*(real.(v[2:Int(N1/2), 2:Int(N2/2), 2:Int(N3/2)])), Int((N1/2-1)*(N2/2-1)*(N3/2-1)));
reshape(sqrt(2).*(imag.(v[2:Int(N1/2), 2:Int(N2/2), 2:Int(N3/2)])), Int((N1/2-1)*(N2/2-1)*(N3/2-1)));
reshape(sqrt(2).*(real.(v[Int(N1/2+2):N1, 2:Int(N2/2), 2:Int(N3/2)])), Int((N1/2-1)*(N2/2-1)*(N3/2-1)));
reshape(sqrt(2).*(imag.(v[Int(N1/2+2):N1, 2:Int(N2/2), 2:Int(N3/2)])), Int((N1/2-1)*(N2/2-1)*(N3/2-1)));
reshape(sqrt(2).*(real.(v[2:Int(N1/2), Int(N2/2+2):N2, 2:Int(N3/2)])), Int((N1/2-1)*(N2/2-1)*(N3/2-1)));
reshape(sqrt(2).*(imag.(v[2:Int(N1/2), Int(N2/2+2):N2, 2:Int(N3/2)])), Int((N1/2-1)*(N2/2-1)*(N3/2-1)));
reshape(sqrt(2).*(real.(v[Int(N1/2+2):N1, Int(N2/2+2):N2, 2:Int(N3/2)])), Int((N1/2-1)*(N2/2-1)*(N3/2-1)));
reshape(sqrt(2).*(imag.(v[Int(N1/2+2):N1, Int(N2/2+2):N2, 2:Int(N3/2)])), Int((N1/2-1)*(N2/2-1)*(N3/2-1)))];
return beta
end
# mapping beta to DFT
# @param dim The dimension of the problem (dim = 1, 2, 3)
# @param size The size of each dimension of the problem
#(we only consider the cases when the sizes are even for all the dimenstions)
#(size is a tuple, e.g. size = (10, 20, 30))
# @param beta A 1-dimensional real vector with length equal to the product of size
# @details This fucnction maps beta to DFT
# @return DFT DFT shares the same size as param sizes
# @example
# >dim = 2;
# >size1 = (6, 8);
# >x = randn(6, 8);
# >v = fft(x)/sqrt(prod(size1));
# >beta = DFT_to_beta(dim, size1, v);
# >w = beta_to_DFT(dim, size1, beta); (w should be equal to v)
function beta_to_DFT(dim, size, beta)
if (dim == 1)
return beta_to_DFT_1d(beta, size)
elseif (dim == 2)
return beta_to_DFT_2d(beta, size)
else (dim == 3)
return beta_to_DFT_3d(beta, size)
end
end
# 1 dim
function beta_to_DFT_1d(beta, size)
N = size[1];
v = [beta[1];
(beta[3: Int(N/2+1)].+ (im.* beta[Int(N/2+2):N]))./sqrt(2);
beta[2];
reverse((beta[3: Int(N/2+1)].- (im.* beta[Int(N/2+2):N]))./sqrt(2))];
return v
end
# 2 dim
function beta_to_DFT_2d(beta, size)
N1 = size[1];
N2 = size[2];
v = Array{Complex{Float64}, 2}(undef, N1, N2);
v[:,1] = [beta[1];
((beta[Int(4+4*(N2/2-1)+1):Int(4+4*(N2/2-1)+(N1/2-1))]).+(im.*(beta[Int(4+4*(N2/2-1)+(N1/2-1)+1):Int(4+4*(N2/2-1)+2*(N1/2-1))])))./sqrt(2);
beta[3];
reverse(((beta[Int(4+4*(N2/2-1)+1):Int(4+4*(N2/2-1)+(N1/2-1))]).-(im.*(beta[Int(4+4*(N2/2-1)+(N1/2-1)+1):Int(4+4*(N2/2-1)+2*(N1/2-1))])))./sqrt(2))];
v[:,2:Int(N2/2)] = [transpose((beta[Int(4+1):Int(4+N2/2-1)]).+(im.*(beta[Int(4+(N2/2-1)+1):Int(4+2*(N2/2-1))])))./sqrt(2);
reshape(((beta[Int(4+4*(N2/2-1)+4*(N1/2-1)+1):Int(4+4*(N2/2-1)+4*(N1/2-1)+(N1/2-1)*(N2/2-1))]).+(im.*(beta[Int(4+4*(N2/2-1)+4*(N1/2-1)+(N1/2-1)*(N2/2-1)+1):Int(4+4*(N2/2-1)+4*(N1/2-1)+2*(N1/2-1)*(N2/2-1))])))./sqrt(2), Int(N1/2-1), Int(N2/2-1));
transpose((beta[Int(4+2*(N2/2-1)+1):Int(4+3*(N2/2-1))]).+(im.*(beta[Int(4+3*(N2/2-1)+1):Int(4+4*(N2/2-1))])))./sqrt(2);
reverse(reverse(reshape(((beta[Int(4+4*(N2/2-1)+4*(N1/2-1)+2*(N1/2-1)*(N2/2-1)+1):Int(4+4*(N2/2-1)+4*(N1/2-1)+3*(N1/2-1)*(N2/2-1))]).-(im.*(beta[Int(4+4*(N2/2-1)+4*(N1/2-1)+3*(N1/2-1)*(N2/2-1)+1):Int(N1*N2)])))./sqrt(2), Int(N1/2-1), Int(N2/2-1)), dims = 1), dims = 2)];
v[:,Int(N2/2+1)] = [beta[2];
((beta[Int(4+4*(N2/2-1)+2*(N1/2-1)+1):Int(4+4*(N2/2-1)+3*(N1/2-1))]).+(im.*(beta[Int(4+4*(N2/2-1)+3*(N1/2-1)+1):Int(4+4*(N2/2-1)+4*(N1/2-1))])))./sqrt(2);
beta[4];
reverse(((beta[Int(4+4*(N2/2-1)+2*(N1/2-1)+1):Int(4+4*(N2/2-1)+3*(N1/2-1))]).-(im.*(beta[Int(4+4*(N2/2-1)+3*(N1/2-1)+1):Int(4+4*(N2/2-1)+4*(N1/2-1))])))./sqrt(2), dims = 1)];
v[:, Int(N2/2+2):Int(N2)] = [transpose(reverse(conj.(v[1,2:Int(N2/2)])));
reverse(reverse(conj.(v[Int(N1/2+2):Int(N1),2:Int(N2/2)]), dims = 2), dims = 1);
transpose(reverse(conj.(v[Int(N1/2+1),2:Int(N2/2)])));
reverse(reverse(conj.(v[2:Int(N1/2),2:Int(N2/2)]), dims = 2), dims = 1)];
return v
end
# 3 dim
function beta_to_DFT_3d(beta, size)
N1 = size[1];
N2 = size[2];
N3 = size[3];
v = Array{Complex{Float64}, 3}(undef, N1, N2, N3);
v[:, 1, 1] = [beta[1];
((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+(N1/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+(N1/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+2*(N1/2-1))])))./sqrt(2);
beta[5];
reverse(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+(N1/2-1))]).-(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+(N1/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+2*(N1/2-1))])))./sqrt(2))];
v[:, 2:Int(N2/2), 1] = [transpose(((beta[Int(8+8*(N3/2-1)+1):Int(8+8*(N3/2-1)+(N2/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+(N2/2-1)+1):Int(8+8*(N3/2-1)+2*(N2/2-1))])))./sqrt(2));
reshape(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+8*(N1/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+8*(N1/2-1)*(N3/2-1)+(N1/2-1)*(N2/2-1))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2);
beta[7];
reverse(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+4*(N1/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+5*(N1/2-1))]).-(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+5*(N1/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+6*(N1/2-1))])))./sqrt(2))];
v[:, Int(N2/2+2):N2, 1] = [transpose(reverse(conj.(v[1, 2:Int(N2/2), 1])));
reverse(reverse(conj.(v[Int(N1/2+2):N1, 2:Int(N2/2), 1]), dims = 1), dims = 2);
transpose(reverse(conj.(v[Int(N1/2+1), 2:Int(N2/2), 1])));
reverse(reverse(conj.(v[2:Int(N1/2), 2:Int(N2/2), 1]), dims = 1), dims = 2)];
v[:, 1, Int(N3/2+1)] = [beta[2];
((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+2*(N1/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+3*(N1/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+3*(N1/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+4*(N1/2-1))])))./sqrt(2);
beta[6];
reverse(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+2*(N1/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+3*(N1/2-1))]).-(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+3*(N1/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+4*(N1/2-1))])))./sqrt(2))];
v[:, 2:Int(N2/2), Int(N3/2+1)] = [transpose(((beta[Int(8+8*(N3/2-1)+2*(N2/2-1)+1):Int(8+8*(N3/2-1)+3*(N2/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+3*(N2/2-1)+1):Int(8+8*(N3/2-1)+4*(N2/2-1))])))./sqrt(2));
reshape(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-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/2-1)+6*(N1/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+7*(N1/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+7*(N1/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1))])))./sqrt(2);
beta[8];
reverse(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+6*(N1/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+7*(N1/2-1))]).-(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+7*(N1/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1))])))./sqrt(2))];
v[:, Int(N2/2+2):N2, Int(N3/2+1)] = [transpose(reverse(conj.(v[1, 2:Int(N2/2), Int(N3/2+1)])));
reverse(reverse(conj.(v[Int(N1/2+2):N1, 2:Int(N2/2), Int(N3/2+1)]), dims = 1), dims = 2);
transpose(reverse(conj.(v[Int(N1/2+1), 2:Int(N2/2), Int(N3/2+1)])));
reverse(reverse(conj.(v[2:Int(N1/2), 2:Int(N2/2), Int(N3/2+1)]), dims = 1), dims = 2)];
v[:, 1, 2:Int(N3/2)] = [transpose(((beta[9:Int(8+(N3/2-1))]).+(im.*(beta[Int(8+(N3/2-1)+1):Int(8+2*(N3/2-1))])))./sqrt(2));
reshape(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+(N1/2-1)*(N3/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+(N1/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+2*(N1/2-1)*(N3/2-1))])))./sqrt(2), Int(N1/2-1), Int(N3/2-1));
transpose(((beta[Int(8+4*(N3/2-1)+1):Int(8+5*(N3/2-1))]).+(im.*(beta[Int(8+5*(N3/2-1)+1):Int(8+6*(N3/2-1))])))./sqrt(2));
reshape(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+2*(N1/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+3*(N1/2-1)*(N3/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+3*(N1/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+4*(N1/2-1)*(N3/2-1))])))./sqrt(2), Int(N1/2-1), Int(N3/2-1))];
v[:, 1, Int(N3/2+2):N3] = [transpose(reverse(conj.(v[1, 1, 2:Int(N3/2)])));
reverse(reverse(conj.(v[Int(N1/2+2):N1, 1, 2:Int(N3/2)]), dims = 1), dims = 2);
transpose(reverse(conj.(v[Int(N1/2+1), 1, 2:Int(N3/2)])));
reverse(reverse(conj.(v[2:Int(N1/2), 1, 2:Int(N3/2)]), dims = 1), dims = 2)];
# v[:, Int(N2/2+1), 2:Int(N3/2)] = [transpose(((beta[9:Int(8+(N3/2-1))]).+(im.*(beta[Int(8+(N3/2-1)+1):Int(8+2*(N3/2-1))])))./sqrt(2));
v[:, Int(N2/2+1), 2:Int(N3/2)] = [transpose(((beta[Int(8+2*(N3/2-1)+1):Int(8+3*(N3/2-1))]).+(im.*(beta[Int(8+3*(N3/2-1)+1):Int(8+4*(N3/2-1))])))./sqrt(2));
#reshape(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+(N1/2-1)*(N3/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+(N1/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+2*(N1/2-1)*(N3/2-1))])))./sqrt(2), Int(N1/2-1), Int(N3/2-1));
reshape(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+4*(N1/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+5*(N1/2-1)*(N3/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+5*(N1/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+6*(N1/2-1)*(N3/2-1))])))./sqrt(2), Int(N1/2-1), Int(N3/2-1));
#transpose(((beta[Int(8+4*(N3/2-1)+1):Int(8+5*(N3/2-1))]).+(im.*(beta[Int(8+5*(N3/2-1)+1):Int(8+6*(N3/2-1))])))./sqrt(2));
transpose(((beta[Int(8+6*(N3/2-1)+1):Int(8+7*(N3/2-1))]).+(im.*(beta[Int(8+7*(N3/2-1)+1):Int(8+8*(N3/2-1))])))./sqrt(2));
reshape(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+6*(N1/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+7*(N1/2-1)*(N3/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+7*(N1/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+8*(N1/2-1)*(N3/2-1))])))./sqrt(2), Int(N1/2-1), Int(N3/2-1))];
# reshape(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+2*(N1/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+3*(N1/2-1)*(N3/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+3*(N1/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+4*(N1/2-1)*(N3/2-1))])))./sqrt(2), Int(N1/2-1), Int(N3/2-1))];
v[:, Int(N2/2+1), Int(N3/2+2):N3] = [transpose(reverse(conj.(v[1, Int(N2/2+1), 2:Int(N3/2)])));
reverse(reverse(conj.(v[Int(N1/2+2):N1, Int(N2/2+1), 2:Int(N3/2)]), dims = 1), dims = 2);
transpose(reverse(conj.(v[Int(N1/2+1), Int(N2/2+1), 2:Int(N3/2)])));
reverse(reverse(conj.(v[2:Int(N1/2), Int(N2/2+1), 2:Int(N3/2)]), dims = 1), dims = 2)];
v[1, 2:Int(N2/2), 2:Int(N3/2)] = reshape(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+(N2/2-1)*(N3/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+(N2/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+2*(N2/2-1)*(N3/2-1))])))./sqrt(2), Int(N2/2-1), Int(N3/2-1));
v[1, Int(N2/2+2):N2, 2:Int(N3/2)] = reshape(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+2*(N2/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+3*(N2/2-1)*(N3/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+3*(N2/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+4*(N2/2-1)*(N3/2-1))])))./sqrt(2), Int(N2/2-1), Int(N3/2-1));
v[1, 2:Int(N2/2), Int(N3/2+2):N3] = reverse(reverse(conj.(v[1, Int(N2/2+2):N2, 2:Int(N3/2)]), dims = 1), dims = 2);
v[1, Int(N2/2+2):N2, Int(N3/2+2):N3] = reverse(reverse(conj.(v[1, 2:Int(N2/2), 2:Int(N3/2)]), dims = 1), dims = 2);
v[Int(N1/2+1), 2:Int(N2/2), 2:Int(N3/2)] = reshape(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+4*(N2/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+5*(N2/2-1)*(N3/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+5*(N2/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+6*(N2/2-1)*(N3/2-1))])))./sqrt(2), Int(N2/2-1), Int(N3/2-1));
v[Int(N1/2+1), Int(N2/2+2):N2, 2:Int(N3/2)] = reshape(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+6*(N2/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+7*(N2/2-1)*(N3/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+7*(N2/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1))])))./sqrt(2), Int(N2/2-1), Int(N3/2-1));
v[Int(N1/2+1), 2:Int(N2/2), Int(N3/2+2):N3] = reverse(reverse(conj.(v[Int(N1/2+1), Int(N2/2+2):N2, 2:Int(N3/2)]), dims = 1), dims = 2);
v[Int(N1/2+1), Int(N2/2+2):N2, Int(N3/2+2):N3] = reverse(reverse(conj.(v[Int(N1/2+1), 2:Int(N2/2), 2:Int(N3/2)]), dims = 1), dims = 2);
v[2:Int(N1/2), 2:Int(N2/2), 2:Int(N3/2)] = reshape(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+8*(N1/2-1)*(N3/2-1)+8*(N1/2-1)*(N2/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+8*(N1/2-1)*(N3/2-1)+8*(N1/2-1)*(N2/2-1)+(N1/2-1)*(N2/2-1)*(N3/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+8*(N1/2-1)*(N3/2-1)+8*(N1/2-1)*(N2/2-1)+(N1/2-1)*(N2/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+8*(N1/2-1)*(N3/2-1)+8*(N1/2-1)*(N2/2-1)+2*(N1/2-1)*(N2/2-1)*(N3/2-1))])))./sqrt(2), Int(N1/2-1), Int(N2/2-1), Int(N3/2-1));
v[Int(N1/2+2):N1, Int(N2/2+2):N2, Int(N3/2+2):N3] = reverse(reverse(reverse(conj.(v[2:Int(N1/2), 2:Int(N2/2), 2:Int(N3/2)]), dims = 1), dims = 2), dims = 3);
v[Int(N1/2+2):N1, 2:Int(N2/2), 2:Int(N3/2)] = reshape(((beta[Int(8+8*(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-1)*(N3/2-1)+8*(N1/2-1)*(N3/2-1)+8*(N1/2-1)*(N2/2-1)+5*(N1/2-1)*(N2/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+8*(N1/2-1)*(N3/2-1)+8*(N1/2-1)*(N2/2-1)+6*(N1/2-1)*(N2/2-1)*(N3/2-1))])))./sqrt(2), Int(N1/2-1), Int(N2/2-1), Int(N3/2-1));
v[Int(N1/2+2):N1, 2:Int(N2/2), Int(N3/2+2):N3] = reverse(reverse(reverse(conj.(v[2:Int(N1/2), Int(N2/2+2):N2, 2:Int(N3/2)]), dims = 1), dims = 2), dims = 3);
v[Int(N1/2+2):N1, Int(N2/2+2):N2, 2:Int(N3/2)] = reshape(((beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+8*(N1/2-1)*(N3/2-1)+8*(N1/2-1)*(N2/2-1)+6*(N1/2-1)*(N2/2-1)*(N3/2-1)+1):Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+8*(N1/2-1)*(N3/2-1)+8*(N1/2-1)*(N2/2-1)+7*(N1/2-1)*(N2/2-1)*(N3/2-1))]).+(im.*(beta[Int(8+8*(N3/2-1)+8*(N2/2-1)+8*(N1/2-1)+8*(N2/2-1)*(N3/2-1)+8*(N1/2-1)*(N3/2-1)+8*(N1/2-1)*(N2/2-1)+7*(N1/2-1)*(N2/2-1)*(N3/2-1)+1):Int(N1*N2*N3)])))./sqrt(2), Int(N1/2-1), Int(N2/2-1), Int(N3/2-1));
v[2:Int(N1/2), 2:Int(N2/2), Int(N3/2+2):N3] = reverse(reverse(reverse(conj.(v[Int(N1/2+2):N1, Int(N2/2+2):N2, 2:Int(N3/2)]), dims = 1), dims= 2), dims = 3);
return v
end