xlang v4.0 Release
程序设计语言基础库文档
载入中...
搜索中...
未找到
fftw.xcs
浏览该文件的文档.
1//xlang Source, Name:fftw.xcsm
2//Date: Thu Apr 20:31:57 2019
3
4class fftw : Library{
5
6 /*static bool bloaded = false;//load();
7
8 static bool load(){
9 try{
10 if (_system_.getPlatformId() == 0){
11 loadLibrary("xfftw.dll");
12 }else
13 if (_system_.getPlatformId() == 1){
14 loadLibrary("xfftw.so");
15 }else
16 if (_system_.getPlatformId() == 2){
17 loadLibrary("xfftw.dylib");
18 }
19 bloaded = true;
20 }catch(Exception e){
21 _system_.output("load fftw fatal:" + e.getMessage());
22 }
23 return bloaded;
24 }*/
25
26 public static class fftwComplex{
27 public long native = 0;
28 public int s = 0, w = 0, h = 0;
29
30 public fftwComplex(int size){
31 s = size;
32 native = alloc_complex(size);
33 }
34
35 // 从复数创建FFTW复数
36 public static fftwComplex from_complex(double[][] complex){
37 fftwComplex dat = new fftwComplex(complex[0].length);
38 dat.fill(complex[0], complex[1]);
39 return dat;
40 }
41
42 // 创建二维复数
43 public fftwComplex(int width, int height){
44 w = width;
45 h = height ;
46 native = alloc_complex(w * h);
47 }
48
49 // 提取复数
50 public double [][]extract(){
51 double[][] fo = nilptr;
52 int len = 0;
53
54 if (s != 0){
55 len = s;
56 }else{
57 len = w * h;
58 }
59
60 fo = new double[2][len];
61 extract_complex_double2(native, 0, len, 0, fo[0], fo[1]);
62 return fo;
63 }
64
65 // 填充复数
66 public void fill(double [] rd, double []id){
67 int len = 0;
68
69 if (s != 0){
70 len = s;
71 }else{
72 len = w * h;
73 }
74 if (id != nilptr){
75 fill_complex_double2(native, 0, len, 0, rd, id);
76 }else{
77 fill_complex_double(native, 0, len, 0, rd);
78 }
79 }
80
81 // 填充二维复数
82 public void fill(double [][] rd, double [][] id){
83 int row = rd[0].length;
84
85 if (id != nilptr){
86 for (int i = 0; i < rd.length; i++){
87 fill_complex_double2(native, i*row, s, 0, rd[i], id[i]);
88 }
89 }else{
90 for (int i = 0; i < rd.length; i++){
91 fill_complex_double(native, i*row, s, 0, rd[i]);
92 }
93 }
94 }
95
96 void finalize(){
97 if (native != 0){
98 free_complex(native);
99 }
100 }
101 };
102
103
104 public static fftwComplex fft2d(fftwComplex in){
105 fftwComplex out = new fftwComplex(in.w, in.h);
106 long plan = create_fftw_plan_dft_2d(in.w, in.h, in.native, out.native, -1, 0x40);
107 if (plan == 0){
108 return nilptr;
109 }
110 execute_fftw(plan);
111 free_plan(plan);
112 return out;
113 }
114
115 public static fftwComplex ifft2d(fftwComplex in){
116 fftwComplex out = new fftwComplex(in.w, in.h);
117 long plan = create_fftw_plan_dft_2d(in.w, in.h, in.native, out.native, 1, 0x40);
118 if (plan == 0){
119 return nilptr;
120 }
121 execute_fftw(plan);
122 free_plan(plan);
123 return out;
124 }
125
126 public static fftwComplex fft2d(double [][] rd, double [][] id){
127 if (id != nilptr && id.length != rd.length){
128 throw new IllegalArgumentException("rd length != id length");
129 return nilptr;
130 }
131
132 fftwComplex in = new fftwComplex(rd.length, rd[0].length);
133 in.fill(rd, id);
134
135 fftwComplex out = new fftwComplex(in.w, in.h);
136
137 long plan = create_fftw_plan_dft_2d(in.w, in.h, in.native, out.native, -1, 0x40);
138 if (plan == 0){
139 return nilptr;
140 }
141 execute_fftw(plan);
142 free_plan(plan);
143 return out;
144 }
145
146 public static fftwComplex ifft2d(double [][] rd, double [][] id){
147 if (id != nilptr && id.length != rd.length){
148 throw new IllegalArgumentException("rd length != id length");
149 return nilptr;
150 }
151
152 fftwComplex in = new fftwComplex(rd.length, rd[0].length);
153 in.fill(rd, id);
154
155 fftwComplex out = new fftwComplex(in.w, in.h);
156
157 long plan = create_fftw_plan_dft_2d(in.w, in.h, in.native, out.native, 1, 0x40);
158 if (plan == 0){
159 return nilptr;
160 }
161 execute_fftw(plan);
162 free_plan(plan);
163 return out;
164 }
165
166 public static double[][] fft2(int n0, int n1, double [] rd, double [] id){
167 if (rd.length != (n0 * n1)){
168 throw new IllegalArgumentException("rd length != n0 *n1");
169 return nilptr;
170 }
171
172 if (id != nilptr && id.length != rd.length){
173 throw new IllegalArgumentException("rd length != id length");
174 return nilptr;
175 }
176
177 fftwComplex in = new fftwComplex(n0, n1);
178 in.fill(rd, id);
179
180 fftwComplex out = new fftwComplex(in.w, in.h);
181
182 long plan = create_fftw_plan_dft_2d(in.w, in.h, in.native, out.native, -1, 0x40);
183 if (plan == 0){
184 return nilptr;
185 }
186 execute_fftw(plan);
187 free_plan(plan);
188
189
190 return out.extract();
191 }
192
193 public static double[][] ifft2(int n0, int n1,double [] rd, double [] id){
194 if (rd.length != (n0 * n1)){
195 throw new IllegalArgumentException("rd length != n0 *n1");
196 return nilptr;
197 }
198
199 if (id != nilptr && id.length != rd.length){
200 throw new IllegalArgumentException("rd length != id length");
201 return nilptr;
202 }
203
204 fftwComplex in = new fftwComplex(n0, n1);
205 in.fill(rd, id);
206
207 fftwComplex out = new fftwComplex(in.w, in.h);
208
209 long plan = create_fftw_plan_dft_2d(in.w, in.h, in.native, out.native, 1, 0x40);
210 if (plan == 0){
211 return nilptr;
212 }
213 execute_fftw(plan);
214 free_plan(plan);
215 return out.extract();
216 }
217
218 public static double[][] fft(double [] rd, double [] id){
219 if (id != nilptr && id.length != rd.length){
220 throw new IllegalArgumentException("rd length != id length");
221 return nilptr;
222 }
223
224 fftwComplex in = new fftwComplex(rd.length);
225 in.fill(rd, id);
226
227 fftwComplex out = new fftwComplex(rd.length);
228
229 long plan = create_fftw_plan_dft_1d(in.s, in.native, out.native, -1, 0x40);
230 if (plan == 0){
231 return nilptr;
232 }
233 execute_fftw(plan);
234 free_plan(plan);
235 return out.extract();
236 }
237
238 public static double[][] ifft(double [] rd, double [] id){
239 if (id != nilptr && id.length != rd.length){
240 throw new IllegalArgumentException("rd length != id length");
241 return nilptr;
242 }
243
244 fftwComplex in = new fftwComplex(rd.length);
245 in.fill(rd, id);
246
247 fftwComplex out = new fftwComplex(rd.length);
248
249 long plan = create_fftw_plan_dft_1d(in.s, in.native, out.native, 1, 0x40);
250 if (plan == 0){
251 return nilptr;
252 }
253 execute_fftw(plan);
254 free_plan(plan);
255 return out.extract();
256 }
257
258 public static double[][] fftr2c(double [] rd, double [] id){
259 if (id != nilptr && id.length != rd.length){
260 throw new IllegalArgumentException("rd length != id length");
261 return nilptr;
262 }
263
264 fftwComplex in = new fftwComplex(rd.length);
265 in.fill(rd, id);
266
267 fftwComplex out = new fftwComplex(rd.length);
268
269 long plan = create_fftw_plan_r2c_1d(in.s, in.native, out.native, -1, 0x40);
270 if (plan == 0){
271 return nilptr;
272 }
273 execute_fftw(plan);
274 free_plan(plan);
275 return out.extract();
276 }
277
278 public static double[][] ifftc2r(double [] rd, double [] id){
279 if (id != nilptr && id.length != rd.length){
280 throw new IllegalArgumentException("rd length != id length");
281 return nilptr;
282 }
283
284 fftwComplex in = new fftwComplex(rd.length);
285 in.fill(rd, id);
286
287 fftwComplex out = new fftwComplex(rd.length);
288
289 long plan = create_fftw_plan_c2r_1d(in.s, in.native, out.native, 1, 0x40);
290 if (plan == 0){
291 return nilptr;
292 }
293 execute_fftw(plan);
294 free_plan(plan);
295 return out.extract();
296 }
297
298 import "xfftw"{
299 Pointer cdecl alloc_complex(int size);
300 void cdecl free_complex(Pointer p);
301 void cdecl fill_complex_double(Pointer p,int offset, int size, int eoffset, ObjectPtr rnp);
302 void cdecl fill_complex_double2(Pointer p,int offset, int size, int eoffset, ObjectPtr rnp, ObjectPtr inp);
303 void cdecl extract_complex_double(Pointer p,int offset, int size, int eoffset, ObjectPtr rnp);
304 void cdecl extract_complex_double2(Pointer p,int offset, int size, int eoffset, ObjectPtr rnp, ObjectPtr inp);
305 double cdecl get_complex_double(Pointer p, int index, bool bi);
306 Pointer cdecl create_fftw_plan_dft_3d(int n0, int n1, int n2, Pointer in, Pointer out, int sign, int flag);
307 Pointer cdecl create_fftw_plan_dft_2d(int n0, int n1, Pointer in, Pointer out, int sign, int flag);
308 Pointer cdecl create_fftw_plan_dft_1d(int n, Pointer in, Pointer out, int sign, int flag);
309 Pointer cdecl create_fftw_plan_c2r_1d(int n, Pointer in, ObjectPtr out, int sign, int flag);
310 Pointer cdecl create_fftw_plan_r2c_1d(int n, ObjectPtr in, Pointer out, int sign, int flag);
311 Pointer cdecl create_fftw_plan_c2r_2d(int n0, int n1, Pointer in, ObjectPtr out, int sign, int flag);
312 Pointer cdecl create_fftw_plan_r2c_2d(int n0, int n1, ObjectPtr in, Pointer out, int sign, int flag);
313 Pointer cdecl create_fftw_plan_c2r_3d(int n0, int n1, int n2, Pointer in, ObjectPtr out, int sign, int flag);
314 Pointer cdecl create_fftw_plan_r2c_3d(int n0, int n1, int n2, ObjectPtr in, Pointer out, int sign, int flag);
315 void cdecl execute_fftw(Pointer p);
316 void cdecl free_plan(Pointer p);
317 };
318};
void finalize()
Definition fftw.xcs:96
double [][] extract()
Definition fftw.xcs:50
static fftwComplex from_complex(double[][] complex)
Definition fftw.xcs:36
void fill(double [][] rd, double [][] id)
Definition fftw.xcs:82
fftwComplex(int size)
Definition fftw.xcs:30
fftwComplex(int width, int height)
Definition fftw.xcs:43
void fill(double [] rd, double []id)
Definition fftw.xcs:66
Definition fftw.xcs:4
static fftwComplex fft2d(double [][] rd, double [][] id)
Definition fftw.xcs:126
static double [][] ifft(double [] rd, double [] id)
Definition fftw.xcs:238
Pointer cdecl create_fftw_plan_dft_3d(int n0, int n1, int n2, Pointer in, Pointer out, int sign, int flag)
static double [][] ifftc2r(double [] rd, double [] id)
Definition fftw.xcs:278
void cdecl extract_complex_double(Pointer p,int offset, int size, int eoffset, ObjectPtr rnp)
static fftwComplex ifft2d(fftwComplex in)
Definition fftw.xcs:115
Pointer cdecl create_fftw_plan_c2r_3d(int n0, int n1, int n2, Pointer in, ObjectPtr out, int sign, int flag)
void cdecl extract_complex_double2(Pointer p,int offset, int size, int eoffset, ObjectPtr rnp, ObjectPtr inp)
static double [][] fftr2c(double [] rd, double [] id)
Definition fftw.xcs:258
void cdecl free_plan(Pointer p)
static double [][] ifft2(int n0, int n1,double [] rd, double [] id)
Definition fftw.xcs:193
double cdecl get_complex_double(Pointer p, int index, bool bi)
void cdecl execute_fftw(Pointer p)
static fftwComplex ifft2d(double [][] rd, double [][] id)
Definition fftw.xcs:146
Pointer cdecl create_fftw_plan_c2r_2d(int n0, int n1, Pointer in, ObjectPtr out, int sign, int flag)
static fftwComplex fft2d(fftwComplex in)
Definition fftw.xcs:104
Pointer cdecl create_fftw_plan_r2c_2d(int n0, int n1, ObjectPtr in, Pointer out, int sign, int flag)
void cdecl free_complex(Pointer p)
void cdecl fill_complex_double(Pointer p,int offset, int size, int eoffset, ObjectPtr rnp)
Pointer cdecl create_fftw_plan_c2r_1d(int n, Pointer in, ObjectPtr out, int sign, int flag)
static double [][] fft2(int n0, int n1, double [] rd, double [] id)
Definition fftw.xcs:166
static double [][] fft(double [] rd, double [] id)
Definition fftw.xcs:218
Pointer cdecl create_fftw_plan_r2c_1d(int n, ObjectPtr in, Pointer out, int sign, int flag)
Pointer cdecl create_fftw_plan_dft_2d(int n0, int n1, Pointer in, Pointer out, int sign, int flag)
void cdecl fill_complex_double2(Pointer p,int offset, int size, int eoffset, ObjectPtr rnp, ObjectPtr inp)
Pointer cdecl create_fftw_plan_r2c_3d(int n0, int n1, int n2, ObjectPtr in, Pointer out, int sign, int flag)
Pointer cdecl create_fftw_plan_dft_1d(int n, Pointer in, Pointer out, int sign, int flag)